Please use the code at the bottom, and add what is needed, thank you. main.cpp #include "InventoryNode.h" int main() {

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Please use the code at the bottom, and add what is needed, thank you. main.cpp #include "InventoryNode.h" int main() {

Post by answerhappygod »

Please use the code at the bottom, and add what isneeded, thank you.
Please Use The Code At The Bottom And Add What Is Needed Thank You Main Cpp Include Inventorynode H Int Main 1
Please Use The Code At The Bottom And Add What Is Needed Thank You Main Cpp Include Inventorynode H Int Main 1 (24.52 KiB) Viewed 30 times
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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply