Write this program in C++ using Stacks and Queues, don\'t worry about templates
ID: 3909818 • Letter: W
Question
Write this program in C++ using Stacks and Queues, don't worry about templates
Inventory Bin Stack Design an inventory class that stores the following members An integer that holds a part's serial number A member that holds the date the part was manufactured An integer that holds the parts lot number nauatae 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 finishecd 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. Inventory Bin Queue Modify the program you wrote for Programming Challenge 12 (Inventory Bin Stack) so it uses a queue instead of a stack. Compare the order in which the parts are removed from the bin for each programExplanation / Answer
Inventory.h
#ifndef _INVENTORY
#define _INVENTORY
#include "stdafx.h"
#include <string>
using namespace std;
class Inventory
{
private:
int serial;
int lot;
string manufacture;
public:
Inventory();
Inventory(int, int, string);
int GetSerial();
int GetLot();
string GetManufacture();
void SetSerial(int);
void SetLot(int);
void SetManufacture(string);
};
#endif _INVENTORY
Inventory.cpp
#include "stdafx.h"
#include <string>
#include <deque>
#include <iostream>
#include "Inventory.h"
using namespace std;
void PrintQueue(deque<Inventory> InventoryQueue)
{
for (unsigned int i = 0; i < InventoryQueue.size(); i++)
{
cout << "Inventory Item #" << i+1 << " Serial Number: " << InventoryQueue[i].GetSerial() << " Lot Number: " << InventoryQueue[i].GetLot() << " Manufacture Date: " << InventoryQueue[i].GetManufacture() << " ";
}
}
int _tmain(int argc, _TCHAR* argv[])
{
deque<Inventory> myInventoryQueue;
char decision;
bool finished = false;
char done;
int serial;
int lot;
string manufacture;
deque<Inventory>::iterator Iter;
while (!finished)
{
cout << " Do you want to Add or Remove an item to the queue? Or Print??? ";
cout << " Enter ADD or REMOVE or PRINT... as A or R or P";
cin >> decision;
if (decision == 'A' || decision == 'a')
{
cout << " Adding Inventory object to queue. ";
cout << "Enter serial number: ";
cin >> serial;
cout << "Enter lot number: ";
cin >> lot;
cout << "Enter manufacture date: ";
getline(cin>>ws, manufacture);
Inventory obj(serial, lot, manufacture);
myInventoryQueue.push_back(obj);
cout << " Are you Done entering items into the queue or do you want to Continue?";
cout << " Enter DONE or CONTINUE... as D or C";
cin >> done;
if(done == 'D' || done == 'd')
finished = true;
}
else if (decision == 'R' || decision == 'r')
{
if (myInventoryQueue.size() > 0)
{
cout << " Removing front item from Queue ";
myInventoryQueue.pop_front();
}
else
cout << " Queue is empty, can't remove any items. ";
}
else if (decision == 'P' || decision == 'p')
{
PrintQueue(myInventoryQueue);
}
else
cout << " Input either A, R, or P";
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.