Page 1 of 1

Please use C++, the code below doesn't know why there is no output, main.cpp is marked as read only, please help me corr

Posted: Fri Jul 08, 2022 6:16 am
by answerhappygod
Please use C++, the code below doesn't know why there is nooutput, main.cpp is marked as readonly, please help me correctInventoryNode.h.
Given main(), define an InsertAtFront() member function in theInventoryNode class that inserts items at the front of a linkedlist (after the dummy head node).
Ex. If the input is:
the output is:
main.cpp
#include "InventoryNode.h"
int main() {int count;int numItems;string item;
InventoryNode *headNode = new InventoryNode();InventoryNode *currNode;
cin >> count;
for (int i = 0; i < count; i++) {cin >> item;cin >> numItems;currNode = new InventoryNode(item, numItems);currNode->InsertAtFront(headNode, currNode);}
currNode = headNode->GetNext();while (currNode != NULL) {currNode->PrintNodeData();currNode = currNode->GetNext();}
return 0;}
InventoryNode.h
#ifndef INVENTORY_H#define INVENTORY_H
#include<iostream>using namespace std;
class InventoryNode {private:string item;int numberOfItems;InventoryNode* nextNodeRef;
public:InventoryNode() {this->item = "";this->numberOfItems = 0;this->nextNodeRef = NULL;}
InventoryNode(string itemInit, int numberOfItemsInit) {this->item = itemInit;this->numberOfItems = numberOfItemsInit;this->nextNodeRef = NULL;}
InventoryNode(string itemInit, int numberOfItemsInit,InventoryNode nextLoc) {this->item = itemInit;this->numberOfItems = numberOfItemsInit;this->nextNodeRef = &nextLoc;}
InventoryNode* InsertAtFront(InventoryNode* headNode,InventoryNode* currNode){currNode->nextNodeRef = headNode;headNode = currNode;
return headNode;}
InventoryNode* GetNext() {return this->nextNodeRef;}
void PrintNodeData() {cout << this->numberOfItems << " " <<this->item << endl;}};
#endif