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
void popItem(DynStack
// 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
// 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
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
// 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
// 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
//********************************************************* // Member function pop pops the value at the top of the * // stack off, and copies it into the variable passed as an* // argument. * //********************************************************* template
// 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
if (!top) { status = true; } else { status = false; } return status; } #endif
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
