11、 模拟餐馆点菜系统
你到一个餐馆去仔细研究一下餐馆的业务流程:餐馆事先准备好自己的招牌菜及一些常规的菜式,有营业场所,服务人员等;顾客来了以后,服务生先给客人找一张桌子坐下来,然后递上菜谱等待顾客点菜,顾客可以点一个菜,也可以退菜,完了之后结账走人,这张桌子又可以用来招待下一批顾客。自己设计程序模拟点菜系统。
算法流程图
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//
#if !defined(AFX_STDAFX_H__4607A810_33E2_483D_80D8_BE41F0D473D5__INCLUDED_)
#define AFX_STDAFX_H__4607A810_33E2_483D_80D8_BE41F0D473D5__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// Insert your headers here
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#define DLLEXPORT __declspec(dllexport)
#define DLLIMPORT __declspec(dllimport)
#include "stdio.h"
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma comment(lib,"ws2_32.lib")
// TODO: reference additional headers your program requires here
void Msg(char *szFormat, ...);
void dbMsg(char *szFormat, ...);
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_STDAFX_H__4607A810_33E2_483D_80D8_BE41F0D473D5__INCLUDED_)
#include "stdafx.h"
#include<iostream>
using namespace std;
//class Waiter
//{};
class MENU
{
private:
int num;
char name[30];
float price;
public:
MENU();
void Setmenu(int nums,char *names,float prices);
int Getnum();
char *Getname();
float Getprice();
};
class TABLE
{
private:
int i;
int order[32];
int number[32];
MENU me[32];
public:
TABLE();
void Seti(int n){i=n;}
int Geti(){return i;}
void Setorder(int orders[32]);
int *Getorder();
void Setnumber(int numbers[32]);
int *Getnumber();
void Printmenu();
void Getlassorder();
void Printlassorder();
void Getmore_order();
void Getless_order();
void GetPay();
};
class RESTAURANT
{
private:
TABLE tab[31];
public:
RESTAURANT(){}
void Service();
void Searchtable(); //查桌子
void Choose(); //选桌子
void Order(); //点菜
void More(); //加菜
void Less(); //退菜
void Pay(); //买单
};
//MENU******************************************************
MENU::MENU()
{
num=0;
name[0]='\0';
price=0.0;
}
void MENU::Setmenu(int nums,char *names,float prices)
{
num=nums;
strcpy(name,names);
price=prices;
}
int MENU::Getnum(){return num;}
char *MENU::Getname(){return name;}
float MENU::Getprice(){return price;}
//TABLE*****************************************************
TABLE::TABLE():i(0)
{
for(int i=0;i<32;i++)
{
order[i]=0;
number[i]=0;
}
me[1].Setmenu(1,"(快)蛋炒饭",10);
me[2].Setmenu(2,"(快)鸡丁饭",15);
me[3].Setmenu(3,"(快)田鸡饭",15);
me[4].Setmenu(4,"(快)牛肉饭",18);
me[5].Setmenu(5,"(快)鸡腿饭",18);
me[6].Setmenu(6,"(快)烤鸭饭",18);
me[7].Setmenu(7,"(快)牛杂饭",20);
me[8].Setmenu(8,"(快)牛肉饭",20);
me[9].Setmenu(9," 酱爆鸭舌 ",30);
me[10].Setmenu(10,"闷鲍鱼 ",40);
me[11].Setmenu(11,"清汤雪耳 ",90);
me[12].Setmenu(12,"可乐鸡翅 ",50);
me[13].Setmenu(13,"炖鱼翅 ",60);
me[14].Setmenu(14,"露笋拼鸡肉 ",70);
me[15].Setmenu(15,"洪七公窖鸡 ",80);
me[16].Setmenu(16,"鱼跃龙门 ",82);
me[17].Setmenu(17,"燕窝鸡 ",90);
me[18].Setmenu(18,"水煮龙虾 ",90);
}
void TABLE::Setorder(int orders[32])
{
for(int i=1;i<32;i++)
order[i]=orders[i];
}
int *TABLE::Getorder()
{
int *p;
p=order;
return p;
}
void TABLE::Setnumber(int numbers[32])
{
for(int i=1;i<32;i++)
number[i]=numbers[i];
}
int *TABLE::Getnumber()
{
int *p;
p=number;
return p;
}
void TABLE::Printmenu()
{
/*cout<<"【菜的编号】 【菜名】 【单价】 "<<endl;
for(int i=1;i<11;i++)
{
if(me[i].Getname()==0&&me[i].Getprice()==0)
break;
cout<<" "<<me[i].Getnum()<<" "<<me[i].Getname()<<" "<<me[i].Getprice()<<"元/份"<<endl;
}*/
cout<<" ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ "<<endl;
cout<<" ┃【菜单号】 【菜名】 【单价】 ┃ "<<endl;
for(int i=1;i<19;i++)
{
if(me[i].Getname()==0&&me[i].Getprice()==0)
break;
cout<<" ┃ "<<me[i].Getnum()<<" "<<me[i].Getname()<<" "
<<me[i].Getprice()<<"元/份"<<" ┃"<<endl;
}
cout<<" ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ "<<endl;
}
void TABLE::Getlassorder()//点菜
{
int num,number;
int ord[32],nums[32];
int j;
while(j!=1)
{
cout<<"请输入菜单号:";
cin>>num;
cout<<"要点几份:";
cin>>number;
if(num>18||num<1||number<0)
{
cout<<"您输入有误,请重新输入:"<<endl;
continue;
}
else
j=1;
if(ord[num]==1)
nums[num]+=number;
else
{
ord[num]=1;
nums[num]=number;
}
}
TABLE::Setorder(ord);
TABLE::Setnumber(nums);
}
void TABLE::Printlassorder()
{
/*for(int i=1;i<32;i++)
{
if(order[i]==1)
{
cout<<"********** "<<me[i].Getnum()<<" "
<<me[i].Getname()<<" "
<<me[i].Getprice()<<" 份数 :"
<<number[i]<<" *********"<<endl;
}
else
continue;
}*/
cout<<" ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ "<<endl;
for(int i=1;i<32;i++)
{
if(order[i]==1)
{
cout<<" ┃"<<me[i].Getnum()<<" "
<<me[i].Getname()<<" "
<<me[i].Getprice()<<"元/份 份数 :"
<<number[i]<<" ┃"<<endl;
}
else
continue;
}
cout<<" ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛ "<<endl;
}
void TABLE::Getmore_order()//加菜
{
int num=0,numbers=0;
int j=0;
while(j!=1)
{
cout<<"请输入菜单号:";
cin>>num;
cout<<"要点几份:";
cin>>numbers;
if(num>18||num<1||numbers<0)
{
cout<<"您输入有误,请重新输入:"<<endl;
continue;
}
else
j=1;
if(order[num]==1)
number[num]+=numbers;
else
{
order[num]=1;
number[num]=numbers;
}
}
}
void TABLE::Getless_order()//退菜
{
int num,numbers;
int j=0;
while(j!=1)
{
cout<<"请输入菜单号:";
cin>>num;
cout<<"要退几份:";
cin>>numbers;
if(num>18||num<1||numbers<0)
{
cout<<"您输入有误,请重新输入:"<<endl;
continue;
}
else
j=1;
if(order[num]==1)
{
number[num]-=numbers;
if(number[num]<0)
number[num]=0;
}
else
{
num=0;
numbers=0;
continue;
}
num=0;
numbers=0;
}
}
void TABLE::GetPay()//买单
{
double m[32];
int i;
for(i=1;i<32;i++)
{
m[i]=0;
}
for(i=1;i<32;i++)
{
if(order[i]==1)
m[i]=me[i].Getprice()*number[i];
else
continue;
}
for(i=2;i<32;i++)
{
if(m[i]>=0)
{
m[1]+=m[i];
}
else
continue;
}
cout<<"您应付"<<m[1]<<"元."<<endl;
for(i=1;i<32;i++)
{
order[i]=0;
number[i]=0;
}
}
//RESTAURANT************************************************
void RESTAURANT::Service()
{
cout<<"━*━*━*━*━*━*━*━*━*━欢迎光临海大餐馆*━*━*━*━*━*━*━*━*━"<<endl;
int j=0;
int k=1;
while(k!=0)
{
cout<<" ┏━━━━━━━━━━━━━━━━━━━━━━━┓ "<<endl;
cout<<" ┃ 1--查桌子 2--选桌子 3--点菜 ┃ "<<endl;
cout<<" ┃ ┃ "<<endl;
cout<<" ┃ 4--加菜 5--退菜 6--买单 ┃ "<<endl;
cout<<" ┃ ┃ "<<endl;
cout<<" ┃ 7--退出 ┃ "<<endl;
cout<<" ┗━━━━━━━━━━━━━━━━━━━━━━━┛ "<<endl;
cout<<endl;
cout<<"请输入您要服务的号码:";
cin>>j;
cout<<endl;
while(j<0||j>7)
{
cout<<"您输入有误,请重新输入:";
cin>>j;
cout<<endl;
}
switch(j)
{
case 1:Searchtable();
break;
case 2:Choose();
break;
case 3:Order();
break;
case 4:More();
break;
case 5:Less();
break;
case 6:Pay();
break;
case 7:k=0;
cout<<"谢谢您的光临!"<<endl;
default:
break;
}
}
}
void RESTAURANT::Searchtable()
{
cout<<"现在为您服务查找空桌子..."<<endl;
cout<<endl;
int i;
for(i=1;i<=30;i++)
{
if(tab[i].Geti()==0)
cout<<i<<"号桌子没有客人!"<<endl;
else
cout<<i<<"号桌子已经有客人!**********"<<endl;
cout<<endl;
}
}
void RESTAURANT::Choose()
{
int i=0,n=0;
for(i=1;i<31;i++)
{
if(tab[i].Geti()==0)
{
cout<<i<<"号桌子没有客人!"<<endl;
}
else
{
cout<<i<<"号桌子已经有客人!"<<endl;
}
cout<<endl;
}
cout<<"现在为您服务选桌..."<<endl;
cout<<endl;
cout<<"请在1~30号中选择桌子号码:";
cin>>n;
cout<<endl;
while(tab[n].Geti()==1)
{
cout<<"您输入的号码有误,请重新输入:";
cin>>n;
cout<<endl;
}
tab[n].Seti(1);
cout <<"您刚才选的是 "<< n <<"号桌子."<<endl;
cout <<endl;
}
void RESTAURANT::Order()
{
for(int i=1;i<31;i++)
{
if(tab[i].Geti()==0)
{
if(i==30)
{
cout<<"对不起,您还没选桌,请先选桌."<<endl;
cout<<endl;
}
else
continue;
}
else
if(tab[i].Geti()==1)
{
int n=0;
cout<<"请您再次输入您的桌子的号码:";
cin>>n;
cout<<endl;
while(tab[n].Geti()!=1)
{
cout<<"您输入的桌子号码有误,请重新输入:";
cin>>n;
cout<<endl;
}
cout<<"现在为您服务点菜..."<<endl;
cout<<endl;
cout<<"━*━*━*━*━*━*━*━*━*━*━海大餐馆菜单━*━*━*━*━*━*━*━*━*━*━"<<endl;
tab[n].Printmenu();
cout<<"请问您想点什么菜?"<<endl;
tab[n].Getlassorder();
cout<<"您刚才点的菜有:"<<endl;
tab[n].Printlassorder();
break;
}
}
}
void RESTAURANT::More()
{
for(int i=1;i<31;i++)
{
if(tab[i].Geti()==0)
{
if(i==30)
{
cout<<"对不起,您还没选桌,请先选桌."<<endl;
cout<<endl;
}
else
continue;
}
else
{
int n;
cout<<"现在为您服务加菜..."<<endl;
cout<<"请您再次输入您的桌子的号码:";
cin>>n;
cout<<endl;
while(tab[n].Geti()!=1)
{
cout<<"您输入的桌子号码有误,请重新输入:";
cin>>n;
cout<<endl;
}
cout<<"这些是您刚才点的菜:"<<endl;
tab[n].Printlassorder();
cout<<endl;
cout<<"━*━*━*━*━*━*━*━*━*━*━健康餐馆菜单━*━*━*━*━*━*━*━*━*━*━"<<endl;
tab[n].Printmenu();
cout<<"请问您想加些什么菜呢?"<<endl;
tab[n].Getmore_order();
tab[n].Printlassorder();
break;
}
}
}
void RESTAURANT::Less()
{
for(int i=1;i<31;i++)
{
if(tab[i].Geti()==0)
{
if(i==30)
{
cout<<"对不起,您还没选桌,请先选桌."<<endl;
cout<<endl;
}
else
continue;
}
else
{
int n;
cout<<"现在为您服务退菜..."<<endl;
cout<<"请您再次输入您的桌子的号码:";
cin>>n;
cout<<endl;
while(tab[n].Geti()!=1)
{
cout<<"您输入的桌子号码有误,请重新输入:";
cin>>n;
cout<<endl;
}
cout<<"这些是您刚才点的菜:"<<endl;
tab[n].Printlassorder();
/*int r=tab[n].Printlassorder();
if(r==0)
{
cout<<"对不起,您还没点菜!"<<endl;
return 0;
}*/
cout<<"请问您想退那些菜呢?"<<endl;
tab[n].Getless_order();
cout<<"您现在点的菜有:"<<endl;
tab[n].Printlassorder();
break;
}
}
}
void RESTAURANT::Pay()
{
for(int i=1;i<31;i++)
{
if(tab[i].Geti()==0)
{
if(i==30)
{
cout<<"对不起,您还没选桌,请先选桌."<<endl;
cout<<endl;
}
else
continue;
}
else
{
int n;
cout<<"现在为您服务结帐..."<<endl;
cout<<"请您再次输入您的桌子的号码:";
cin>>n;
cout<<endl;
while(tab[n].Geti()!=1)
{
cout<<"您输入的桌子号码有误,请重新输入:";
cin>>n;
cout<<endl;
}
cout<<"您结的是"<<n<<"号桌子的帐。"<<endl;
cout<<"您刚才点的菜有:"<<endl;
tab[n].Printlassorder();
tab[n].GetPay();
tab[n].Seti(0);
//cout<<"谢谢光临!"<<endl;
cout<<endl;
break;
}
}
}
int main(int argc, char* argv[])
{
RESTAURANT a;
a.Service();
return 0;
}
1.系统登陆界面
2.寻找空台
3.选择台号
4.查看菜单选择菜式
5.选择菜式数量
6.加菜
7.退菜
6.买单结账