struct { char d[50]; float p,amount; int qty; }rd; class Order:public Restaurant { public: void bill(); void showbill(); void dish_menu(); }; void Order::bill() { int a,c=0; char ch; float total=0; fstream obj,obj1; dish_menu(); obj1.open("bill.txt",ios::out|ios::binary); do{ obj.open("restaurant.txt",ios::in|ios::binary); cout<<"enter the dish key:"; cin>>a; while(obj.read((char*)&r,sizeof(r))) { if(r.key==a) { c++; cout<<"enter the quantity:"; cin>>rd.qty; rd.amount=rd.qty*r.price; cout<<"\t"<>ch; obj.close(); } while(ch!='n'); obj1.close(); cout<<"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"<>a; switch(a) { case '0': break; case '1': system("CLS"); obj.admin(); break; case '2': system("CLS"); obj.bill(); break; } } while(a!='0'); }
Another half of my code:
cout<<"\n\t\t\t\t\t\t|||||||||||||||||||||||||"<<endl;
cout<<"\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t| 1) ADD DISH |"<<endl;
cout<<"\t\t\t\t\t\t| 2) Display |"<<endl;
cout<<"\t\t\t\t\t\t| 3) QUERY |"<<endl;
cout<<"\t\t\t\t\t\t| 4) UPDATE |"<<endl;
cout<<"\t\t\t\t\t\t| 5) DELETE |"<<endl;
cout<<"\t\t\t\t\t\t| 0) EXIT TO MAIN MENU |"<<endl;
cout<<"\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t|||||||||||||||||||||||||"<<endl;
cout<<"\t\t\t\t\t\tselect the key";
cin>>a;
switch(a)
{
case '0':
break;
case '1':
system("CLS");
create();
break;
case '2':
system("CLS");
display();
break;
case '3':
system("CLS");
query();
break;
case '4':
system("CLS");
update();
break;
case '5':
system("CLS");
delet();
break;
}
}
while(a!='0');
}
struct {
char d[50];
float p,amount;
int qty;
}rd;
class Order:public Restaurant
{
public:
void bill();
void showbill();
void dish_menu();
};
void Order::bill()
{
int a,c=0;
char ch;
float total=0;
fstream obj,obj1;
dish_menu();
obj1.open("bill.txt",ios::out|ios::binary);
do{
obj.open("restaurant.txt",ios::in|ios::binary);
cout<<"enter the dish key:";
cin>>a;
while(obj.read((char*)&r,sizeof(r)))
{
if(r.key==a)
{
c++;
cout<<"enter the quantity:";
cin>>rd.qty;
rd.amount=rd.qty*r.price;
cout<<"\t"<<r.dish<<"\t\t"<<r.price<<"*"<<rd.qty<<"\t\t"<<rd.amount<<endl;
strcpy(rd.d,r.dish);
rd.p=r.price;
obj1.write((char*)&rd,sizeof(rd));
total=total+rd.amount;
}
}
if(c==0)
{
cout<<"not found"<<endl;
}
cout<<"do you want to order more [y/n]";
cin>>ch;
obj.close();
}
while(ch!='n');
obj1.close();
cout<<"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"<<endl;
cout<<"|||||||||||||||||||||||||||||||||||||||||||||||| BILL |||||||||||||||||||||||||||||||||||||||||||||||||||||||"<<endl;
cout<<"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"<<endl;
showbill();
cout<<"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"<<endl;
cout<<"|||\t\t\t\t\t\t\t TOTAL="<<total<<"\t\t\t\t\t |||"<<endl;
cout<<"||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||"<<endl;
}
void Order::showbill(){
fstream obj;
obj.open("bill.txt",ios::in|ios::binary);
cout<<"\tDISH NAME\t\tPRICE\t\tQTY\t\tAMOUNT"<<endl;
while(obj.read((char*)&rd,sizeof(rd)))
{
cout<<"\t"<<rd.d<<"\t\t\t"<<rd.p<<"\t\t"<<rd.qty<<"\t\t"<<rd.amount<<endl;
}
obj.close();
}
void Order::dish_menu()
{
fstream obj;
obj.open("restaurant.txt",ios::in|ios::binary);
while(obj.read((char*)&r,sizeof(r)))
{
cout<<"\t\t"<<r.key<<") "<<r.dish<<"-------RM "<<r.price<<endl;
}
obj.close();
}
int main()
{
char a;
Order obj;
do
{
cout<<"\n\t\t\t\t\t\t||||||||||||||||||||"<<endl;
cout<<"\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t| 1)Admin |"<<endl;
cout<<"\t\t\t\t\t\t| 2)Order |"<<endl;
cout<<"\t\t\t\t\t\t| 0)Exit |"<<endl;
cout<<"\t\t\t\t\t\t| |"<<endl;
cout<<"\t\t\t\t\t\t||||||||||||||||||||"<<endl;
cout<<"\t\t\t\t\t\tselect the menu";
cin>>a;
switch(a)
{
case '0':
break;
case '1':
system("CLS");
obj.admin();
break;
case '2':
system("CLS");
obj.bill();
break;
}
}
while(a!='0');
}
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)