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

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 C++, the code below doesn't know why there is no output, main.cpp is marked as read only, please help me corr

Post 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
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply