Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design an inventory class that stores the following members: serialNum:An intege

ID: 3920733 • Letter: D

Question

Design an inventory class that stores the following members: serialNum:An integer that holds a part's serial number anufactDate: lotNum A member that holds the date the part was manufactured An integer that holds the pasrt'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 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 finishes. 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 störed in an 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 objects that remain on stack

Explanation / Answer

#include<iostream>
#include<string>
#include<stack>

/* class for inventory */
class Inventory {
   private:
       /* data members */
       long serialNum;
       std::string manufacturedDate;
       long lotNum;
   public:
       /* default constructor */
       Inventory(long serial, long lot, std::string date) {
           setSerialNum(serial);
           setLotNum(lot);
           setManufacturedDate(date);
       }
       /* default destructor */
       ~Inventory() {}
       /* setter getter methods */
       long getSerialNum() {
           return serialNum;
       }
       void setSerialNum(long serial) {
           serialNum = serial;
       }
       std::string getManufacturedDate() {
           return manufacturedDate;
       }
       void setManufacturedDate(std::string date) {
           manufacturedDate = date;
       }
       long getLotNum() {
           return lotNum;
       }
       void setLotNum(long lotnum) {
           lotNum = lotnum;
       }
       /* print the details of inventory object */
       void printInventoryDetails() {
           std::cout<<"Serial Number: "<<getSerialNum()<<" ";
           std::cout<<"Manufactured Date: "<<getManufacturedDate()<<" ";
           std::cout<<"Lot Number: "<<getLotNum()<<" ";
       }
};

/* class Stack */
class Stack {
   private:
       /* standard template library usage of stack */
       std::stack<Inventory> priv_stack;
   public:
       /* default constructor */
       Stack(){}
       /* default destructor */
       ~Stack(){}
       /* push to stack */
       void push(Inventory inventory) {
           priv_stack.push(inventory);
       }
       /* pop from stack */
       Inventory pop() {
           Inventory inventory = priv_stack.top();
           priv_stack.pop();
           return inventory;
       }
       /* size method for size of stack */
       size_t size() {
           return priv_stack.size();
       }
       /* empty method for stack */
       bool empty() {
           return priv_stack.empty();
       }
       /* print stack contents */
       void printStackContents() {
           while(! priv_stack.empty()) {
               Inventory inventory = priv_stack.top();
               inventory.printInventoryDetails();
               priv_stack.pop();
           }
       }
};

/* helper method to get the user choice */
int getUserChoice() {
   int user_choice;
   std::cout<<"1. Add to inventory stack ";
   std::cout<<"2. Remove from inventory stack ";
   std::cout<<"3. Quit ";
   std::cout<<"Enter your choice: ";
   std::cin>>user_choice;
   return user_choice;
}

/* main function */
int main () {
   Stack inventory_stack;
   int user_choice;
   while((user_choice = getUserChoice()) != 3) {
       /* pushing to stack */
       if (user_choice == 1) {
           long serial_num, lot_num;
           std::string date;
           std::cout<<"Enter serial Number: ";
           std::cin>>serial_num;
           std::cout<<"Enter lot number: ";
           std::cin>>lot_num;
           std::cout<<"Enter manufacture date: ";
           std::cin>>date;
           Inventory inventory(serial_num, lot_num, date);
           inventory_stack.push(inventory);
       } else {
           /* popping from stack */
           if (inventory_stack.empty()) {
               std::cout<<"Stack Empty ";
               continue;
           }
           /* print the inventory details */
           Inventory inventory = inventory_stack.pop();
           inventory.printInventoryDetails();
       }
   }
   /* print the stack details */
   inventory_stack.printStackContents();
   return 0;
}

/* hope this helps, if any queries please do comment */

/* thanks */

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote