Question: C++ Data stucture Instruction:Implement the codes must use the LinkedStack implementation Below the question i provided the code to use for the question 1. (Gaddis)

C++ Data stucture Instruction:Implement the codes must use the LinkedStack implementation Below the question i provided the code to use for the question

1. (Gaddis) Programming Challenges 12. Inventory Bin Stack Pag 1119. Cap 18

Problem 12. Inventory Bin Stack Design an inventory class that stores the following members: serialNum: An integer that holds a part's serial number. manufactDate: A member that holds the date the part was manufactured. lotNum: An integer that holds the part's lot number. The class should have appropriate member functions for storing data into, and retrieving data from, these members. Next, design a stack class that can hold objects of the class described above. If you wish, you may use the template you designed in Programming Challenge 1 or 2. Last, design a program that uses the stack class described above. The program should have a loop that asks the user if he or she wishes to add a part to inventory, or take a part from inventory. The loop should repeat until the user is finished. If the user wishes to add a part to inventory, the program should ask for the serial number, date of manufacture, and lot number. The data should be stored in an inventory object, and pushed onto the stack. If the user wishes to take a part from inventory, the program should pop the top-most part from the stack and display the contents of its member variables. When the user finishes the program, it should display the contents of the member values of all the objects that remain on the stack.

When we use links and dynamic memory to implement an ADT we need to design copy constructor and destructor so we avoid any memory leak or shadow copies. Therefore we need to be more careful in this implementation about memory management.

By using links, we can implement the stacks the same way we have defined it. We will have a pointer that keeps the head of stack and all the linked data from there forward. The following listing shows the header for link-based implementation of a stack.

C++ Data stucture Instruction:Implement the codes must use the LinkedStack implementation Belowthe question i provided the code to use for the question1. (Gaddis)

/** @file LinkedStack. cpp #/ #include // For assert #include "LinkedStack.h" // Header file template LinkedStack: : LinkedStack() : topPtr(nullptr) // end default constructor template LinkedStack: : LinkedStack (const LinkedStack& aStack) { // Point to nodes in original chain Node* origChainPtr = aStack->topPtr; if (origChainPtr == nullptr) topPtr = nullptr; // Original bag is empty else { // Copy first node topPtr = new Node() ; topPtr->setItem(origChainPtr->getItem()) ; // Point to first node in new chain Node* newChainPtr = topPtr; // Copy remaining nodes while (origChainPtr != nullptr) { // Advance original-chain pointer origChainPtr = origChainPtr->getNext(); // Get next item from original chain ItemType nextItem = origChainPtr->getItem() ; // Create a new node containing the next item Node* newNodePtr = new Node(nextItem); // Link new node to end of new chain newChainPtr->setNext (newNodePtr) ;/** ADT stack: Link-based implementation. @file LinkedStack.h */ #ifndef _LINKED_STACK #define _LINKED_STACK #include "StackInterface.h" #include "Node.h" template class LinkedStack : public StackInterface private: Node* topPtr; // Pointer to first node in the chain; // this node contains the stack's top public: // Constructors and destructor: LinkedStack () ; // Default constructor LinkedStack (const LinkedStack& aStack); // Copy constructor virtual ~LinkedStack(); // Destructor // Stack operations: bool isEmpty() const; bool push(const ItemType& newItem) ; bool pop (); ItemType peek () const; }; // end LinkedStack

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 Programming Questions!