Please use the code at the bottom, and add what is needed, thank you. main.cpp #include "InventoryNode.h" int main() {
Posted: Fri Jul 01, 2022 5:45 am
Please use the code at the bottom, and add what isneeded, thank you.
main.cpp
#include "InventoryNode.h"
int main() { int count; int numItems; string item;
InventoryNode *headNode = newInventoryNode(); InventoryNode *currNode;
// Obtain number of items cin >> count;
// Get each item and number of each for (int i = 0; i < count; i++) { cin >> item; cin >> numItems; currNode = newInventoryNode(item, numItems); currNode->InsertAtFront(headNode, currNode); }
// Print linked list currNode = headNode->GetNext(); while (currNode != NULL) { currNode->PrintNodeData(); currNode =currNode->GetNext(); }
return 0;}
inventoryNode.h
#include <iostream>#include <string>using namespace std;
class InventoryNode {private: string item; int numberOfItems; InventoryNode *nextNodeRef;
public: //Constructor InventoryNode() { this->item = ""; this->numberOfItems =0; this->nextNodeRef =NULL; }
//Constructor InventoryNode(string itemInit, intnumberOfItemsInit) { this->item =itemInit; this->numberOfItems =numberOfItemsInit; this->nextNodeRef =NULL; }
//Constructor InventoryNode(string itemInit, intnumberOfItemsInit, InventoryNode nextLoc) { this->item =itemInit; this->numberOfItems =numberOfItemsInit; this->nextNodeRef =&nextLoc; }
// TODO: Define an insertAtFront() method thatinserts a node at the // front of the linked list(after the dummy head node)
//Get the next node InventoryNode *GetNext() { returnthis->nextNodeRef; }
//Print node data void PrintNodeData() { cout <<this->numberOfItems << " " << this->item <<endl; }};
Given main(), define an InsertAtFront() member function in the InventoryNode class that inserts items at the front of a linked list (after the dummy head node). Ex. If the input is: 4 plates 100 spoons 200 cups 150 forks 200 the output is: 200 forks 150 cups 200 spoons 100 plates angos 2194510vRm7
main.cpp
#include "InventoryNode.h"
int main() { int count; int numItems; string item;
InventoryNode *headNode = newInventoryNode(); InventoryNode *currNode;
// Obtain number of items cin >> count;
// Get each item and number of each for (int i = 0; i < count; i++) { cin >> item; cin >> numItems; currNode = newInventoryNode(item, numItems); currNode->InsertAtFront(headNode, currNode); }
// Print linked list currNode = headNode->GetNext(); while (currNode != NULL) { currNode->PrintNodeData(); currNode =currNode->GetNext(); }
return 0;}
inventoryNode.h
#include <iostream>#include <string>using namespace std;
class InventoryNode {private: string item; int numberOfItems; InventoryNode *nextNodeRef;
public: //Constructor InventoryNode() { this->item = ""; this->numberOfItems =0; this->nextNodeRef =NULL; }
//Constructor InventoryNode(string itemInit, intnumberOfItemsInit) { this->item =itemInit; this->numberOfItems =numberOfItemsInit; this->nextNodeRef =NULL; }
//Constructor InventoryNode(string itemInit, intnumberOfItemsInit, InventoryNode nextLoc) { this->item =itemInit; this->numberOfItems =numberOfItemsInit; this->nextNodeRef =&nextLoc; }
// TODO: Define an insertAtFront() method thatinserts a node at the // front of the linked list(after the dummy head node)
//Get the next node InventoryNode *GetNext() { returnthis->nextNodeRef; }
//Print node data void PrintNodeData() { cout <<this->numberOfItems << " " << this->item <<endl; }};
Given main(), define an InsertAtFront() member function in the InventoryNode class that inserts items at the front of a linked list (after the dummy head node). Ex. If the input is: 4 plates 100 spoons 200 cups 150 forks 200 the output is: 200 forks 150 cups 200 spoons 100 plates angos 2194510vRm7