Question: Could use some expert help on writing source code for the program that follows in the C++ language. Please show headings for .cpp and .h

Could use some expert help on writing source code for the program that follows in the C++ language. Please show headings for .cpp and .h files, comment code, and show sample output of it working correctly (screenshot image). Below you will see a heading marked "FILE TO INCLUDE". This file must be integrated to work with the program. See instructions below and thank you!

// Program Requirements

Using the previously created stack class (see "FILE TO INCLUDE"), you will create a class called InventoryItem. This class will have its class declaration in InventoryItem.h and its implementation in InventoryItem.cpp. It will have three private data members, an integer serialNum which holds the parts serial number, manufactDate which should be a string that holds the date the item was manufactured, then lotNum which will be an integer that holds the parts lot number. The program should then create a stack with a data type of InventoryItem (stack). The program should loop asking the user to enter in new items to the inventory stack or to remove an item from the inventory stack. The loop should continue until the user indicates they are done. This should be menu driven. When adding an item, the program should ask the user for the information it needs for the 3 data members of the InventoryItem class and add a new item to the stack. When removing an item from the stack, the program should display all of the information in the InventoryItem object that was popped off the stack. When the program ends, it should pop all of the remaining items off the stack and display the data that is in the Inventory items as it pops them off. There should be 3 utility functions that main uses.

void popItem(DynStack* stack) // pops the item off the stack and displays it. void pushItem(DynStack* stack) // pushes the item onto the stack int menu(); // displays the menu and returns the users choice.

// FILE TO INCLUDE

//Print function is added to the stack.h header file

//and test program to test the generic stack //Stack.h #ifndef STACK_H #define STACK_H #include using namespace std;

// This class template creates a dynamic stack of // of any data type. It has a pop function that // returns a bool. The parameter to the pop function // is passed by reference and should be the item on // the list if it was able to pop something.

template class Stack { private: // Structure for the stack nodes struct StackNode { T value; // Value in the node StackNode *next; // Pointer to the next node };

StackNode *top; // Pointer to the stack top

public: // Constructor Stack() { top = NULL; }

// Destructor ~Stack();

// Stack operations void push(T); void pop(T&); bool isEmpty(); void print();

};

//********************************************************* // Destructor * //********************************************************* template Stack::~Stack() { StackNode *nodePtr, *nextNode;

// Position nodePtr at the top of the stack nodePtr = top;

// Traverse the list deleting each node while (nodePtr != NULL) { nextNode = nodePtr->next; delete nodePtr; nodePtr = nextNode; } }

//********************************************************* // Member function push pushes the argument onto the * // stack. * //********************************************************* template void Stack::push(T item) { StackNode *newNode; // Pointer to a new node

// Allocate a new node and store num there newNode = new StackNode; newNode->value = item;

// If there are no nodes in the list make newNode // the first node if (isEmpty()) { top = newNode; newNode->next = NULL; } else // Otherwise, insert newNode before top { newNode->next = top; top = newNode; } }

//********************************************************* // Member function to print elements from the stack* //********************************************************* template void Stack::print() { StackNode *temp=top; T item; // Traverse the stack until the temp node is not null while (temp != NULL) { item = temp->value; cout<next; } }

//********************************************************* // Member function pop pops the value at the top of the * // stack off, and copies it into the variable passed as an* // argument. * //********************************************************* template void Stack::pop(T &item) { StackNode *temp; // Temporary pointer

// First make sure the stack isn't empty if (isEmpty()) { cout << "ERROR! The stack is empty. "; } else { item = top->value; temp = top->next; delete top; top = temp; } }

//********************************************************* // Member function isEmpty returns true if the stack is * // empty, or false otherwise. * //********************************************************* template bool Stack::isEmpty() { bool status;

if (!top) { status = true; } else { status = false; } return status; } #endif

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!