Inventory Bin Stack ( C++) Instructions Design an inventory class that stores th
ID: 3690017 • Letter: I
Question
Inventory Bin Stack ( C++) Instructions 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. Then make a copy of your entire program. Modify the copy so that it uses a queue instead of a stack. Compare the order in which the parts are removed from the bin for each program. Submit both programs along with your analysis.
Explanation / Answer
Header file:
# Ifndef PROG6_H_INCLUDED
# Define PROG6_H_INCLUDED
# Include <iostream>
const int size = 2;
class Inventory
{
private:
int serialNum;
int manufactDate;
int lotNum;
public:
void setnum (int x) {serialNum = x;}
int getnum () {return serialNum;}
void setdate (int y) {manufactDate = y;}
int getdate () {return manufactDate;}
void setnum1 (int z) {lotNum = z;}
int getnum1 () {return lotNum;}
};
class stack
{
private:
int a [size];
int b [size];
int c [size];
public:
int i;
stack () {i = 0;};
void push (int, int, int);
void pop ();
};
class queue
{
private:
int * a;
int * b;
int * c;
int front;
int rear;
int num_item;
public:
queue ();
void enqueue (int, int, int);
void dequeue (int &, int &, int &);
void clear ();
};
# Endif / / PROG6_H_INCLUDED
Source File:
# Include "prog6.h"
using namespace std;
void stack:: push (int x, int y, int z)
{
i + +;
a [i] = x;
b [i] = y;
c [i] = z;
}
void stack:: pop ()
{
- I;
cout <<a [i] <<endl;
cout <<b [i] <<endl;
cout <<c [i] <<endl;
}
//------------------------------------------------ --------------
queue:: queue ()
{
a = new int [size];
b = new int [size];
c = new int [size];
front = -1;
rear = -1;
num_item = 0;
}
void queue:: enqueue (int num, int num1, int num2)
{
rear = (rear + 1)% size;
a [rear] = num;
b [rear] = num1;
c [rear] = num2;
num_item + +;
}
void queue:: dequeue (int & num, int & num1, int & num2)
{
front = (front +1)% size;
num = a [front];
num1 = b [front];
num2 = c [front];
num_item -;
}
//------------------------------------------------ ---
int main ()
{
Inventory a [size];
stack b; / / stack
int c [size];
int d [size];
int e [size];
for (int i = 0; i <= size; i + +)
{
cout <<"please enter the serialNum:";
cin>> c [i];
a [i]. setnum (c [i]);
cout <<"please enter the date:";
cin>> d [i];
a [i]. setdate (d [i]);
cout <<"please enter the lotnum:";
cin>> e [i];
a [i]. setnum1 (e [i]);
}
b.push (a [0]. getnum (), a [0]. getdate (), a [0]. getnum1 ());
b.push (a [1]. getnum (), a [1]. getdate (), a [1]. getnum1 ());
b.push (a [2]. getnum (), a [2]. getdate (), a [2]. getnum1 ());
cout <<endl;
b.pop ();
cout <<endl;
b.pop ();
cout <<endl;
b.pop ();
//------------------------------------------------ ------------
queue f; / / queue
for (int i = 0; i <= size; i + +)
{
cout <<"please enter the serialNum:";
cin>> c [i];
a [i]. setnum (c [i]);
cout <<"please enter the date:";
cin>> d [i];
a [i]. setdate (d [i]);
cout <<"please enter the lotnum:";
cin>> e [i];
a [i]. setnum1 (e [i]);
}
f.enqueue (a [0]. getnum (), a [0]. getdate (), a [0]. getnum1 ());
f.enqueue (a [1]. getnum (), a [1]. getdate (), a [1]. getnum1 ());
f.enqueue (a [2]. getnum (), a [2]. getdate (), a [2]. getnum1 ());
for (int i = 0; i <= size; i + +)
{
int value, value1, value2;
f.dequeue (value, value1, value2);
cout <<value <<"" <<value1 <<"" <<value2 <<endl;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.