Burger Stand Class Implementation Example Code in C C++ Programming Language with Menu
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
void getData();
void recSale();
void disStatus();
class BurgerStand
{
private:
int bunsOnHand;
int shamisOnHand;
public:
void initData(){
cout<<"Enter number of buns";
cin>>bunsOnHand;
cout<<"Enter number of shamis";
cin>>shamisOnHand;
}
void sale(){
--bunsOnHand;
--shamisOnHand;
}
void displayData(){
cout<<"\nNumber of Buns: "<<bunsOnHand;
cout<<"\nNumber of Shamis: "<<shamisOnHand;
}
};
char standNo;
BurgerStand S1,S2,S3,S4;
void main(){
clrscr();
cout<<"BURGER SHOP";
cout<<"\n=========================================";
cout<<"\n1: Enter Data"<<"\n2: Record Sale"<<"\n3: Display Status"
<<"\n4: Exit";
cout<<"\n\nEnter the selection listed";
cin>>standNo;
switch(standNo){
case '1': getData();break;
case '2': recSale();break;
case '3': disStatus();break;
case '4': exit(0);
default:
cout<<"Enter only selection listed";
}//end of switch.
getch();
}
void getData(){
clrscr();
cout<<"\nEnter Stand NO: ";
cin>> standNo;
switch(standNo){
case '1': S1.initData();break;
case '2': S2.initData();break;
case '3': S3.initData();break;
case '4': S4.initData();break;
default:
cout<<"Stand no should not be less than 1 or greater than 4"
<<"\nEnter again";
cout<<"\n\nPress any key to return to main menu";
getch();
main();
}
void recSale(){
clrscr();
cout<<"Enter Stand No";
cin>>standNo;
switch(standNo){
case'1': S1.sale();
case '2': S2.sale();
case '3': S3.sale();
case '4': S4.sale();
default:
cout<<"\nStand no should no be less than 1 or greater than 4"
<<"\nEnter again";
}
cout<<"\n\nOne burger from stand no "<<standNo<<" Sold";
cout<<"\n\nPress any key to return to main menu";
getch();
main();
}
void displayStatus(){
clrscr();
cout<<"\nEnter Stand no ";
cin>>standNo;
switch(standNo){
case '1': S1.displayData();break;
case '2': S2.displayData();break;
case '3': S3.displayData();break;
case '4': S4.displayData();break;
default:
cout<<"\n\nStand no should no be less than 0 or greater than 4";
}//end of switch.
cout<<"\nEnter any key to return to main menu";
getch();
main();
}
#include<iostream.h>
#include<conio.h>
#include<ctype.h>
#include<process.h>
void getData();
void recSale();
void disStatus();
class BurgerStand
{
private:
int bunsOnHand;
int shamisOnHand;
public:
void initData(){
cout<<"Enter number of buns";
cin>>bunsOnHand;
cout<<"Enter number of shamis";
cin>>shamisOnHand;
}
void sale(){
--bunsOnHand;
--shamisOnHand;
}
void displayData(){
cout<<"\nNumber of Buns: "<<bunsOnHand;
cout<<"\nNumber of Shamis: "<<shamisOnHand;
}
};
char standNo;
BurgerStand S1,S2,S3,S4;
void main(){
clrscr();
cout<<"BURGER SHOP";
cout<<"\n=========================================";
cout<<"\n1: Enter Data"<<"\n2: Record Sale"<<"\n3: Display Status"
<<"\n4: Exit";
cout<<"\n\nEnter the selection listed";
cin>>standNo;
switch(standNo){
case '1': getData();break;
case '2': recSale();break;
case '3': disStatus();break;
case '4': exit(0);
default:
cout<<"Enter only selection listed";
}//end of switch.
getch();
}
void getData(){
clrscr();
cout<<"\nEnter Stand NO: ";
cin>> standNo;
switch(standNo){
case '1': S1.initData();break;
case '2': S2.initData();break;
case '3': S3.initData();break;
case '4': S4.initData();break;
default:
cout<<"Stand no should not be less than 1 or greater than 4"
<<"\nEnter again";
cout<<"\n\nPress any key to return to main menu";
getch();
main();
}
void recSale(){
clrscr();
cout<<"Enter Stand No";
cin>>standNo;
switch(standNo){
case'1': S1.sale();
case '2': S2.sale();
case '3': S3.sale();
case '4': S4.sale();
default:
cout<<"\nStand no should no be less than 1 or greater than 4"
<<"\nEnter again";
}
cout<<"\n\nOne burger from stand no "<<standNo<<" Sold";
cout<<"\n\nPress any key to return to main menu";
getch();
main();
}
void displayStatus(){
clrscr();
cout<<"\nEnter Stand no ";
cin>>standNo;
switch(standNo){
case '1': S1.displayData();break;
case '2': S2.displayData();break;
case '3': S3.displayData();break;
case '4': S4.displayData();break;
default:
cout<<"\n\nStand no should no be less than 0 or greater than 4";
}//end of switch.
cout<<"\nEnter any key to return to main menu";
getch();
main();
}
0 comments:
Post a Comment