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

Design an inventory class in c++ that stores the following members: serialNum: A

ID: 3732908 • Letter: D

Question

Design an inventory class in c++ 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. 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 the 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.

Explanation / Answer

#include<conio.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
class inventory
{
public:
int serialNum,lotNum;
char date[12];

void setdata(inventory);
};

struct node{
inventory info;
struct node *link;
}*top=NULL;
struct node *temp;


class stack:public inventory
{
public:
void setdata(inventory i)
{
int snum,lnum;
char dt[12];
printf(" Enter serial number:");
scanf("%d",&snum);
printf(" Enter lot number:");
scanf("%d",&lnum);
printf(" Enter date:");
scanf("%s",&dt);
i.serialNum=snum;
i.lotNum=lnum;
strcpy(dt,i.date);
//Pushing inside the stack
temp=(struct node*)malloc(sizeof(struct node));
if(temp!=NULL)
{
   temp->info.serialNum=i.serialNum;
   temp->info.lotNum=i.lotNum;
   strcpy(temp->info.date,i.date);
}
if(top==NULL)
{
   top=temp;
   temp->link=NULL;
}
else
{
   temp->link=top;
   top=temp;
}

}
//popping from the stack
void pop(inventory i)
{
temp=top;
printf("The following part is being removed:");
printf(" Serial Number:%d",temp->info.serialNum);
printf(" Lot Number:%d",temp->info.lotNum);
top=temp->link;
getch();
}
};

void main()
{
inventory i;
stack s;
int choice;
do
{
clrscr();
printf(" Hello!Enter your choice");
printf(" 1.Enter a part to the inventory 2.Take a part from the inventory 3.Exit ");
scanf("%d",&choice);
switch(choice)
{
    case 1:s.setdata(i);
       break;
    case 2:s.pop(i);
       break;
    case 3:exit(0);
    default:printf(" Invalid choice!");
}
}
while(choice!=3);
}

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