项目实现:通过主菜单选择需要的服务,实现网上点餐,支付功能
#include <iostream>
#include <fstream>//设置文件
#include <string>
#include <conio.h>//等待输入
using namespace std;
/*
食物
名字
价格
种类
*/
class food
{
public:
string name;
int price;
food(){}
food(string na,int pr):name(na),price(pr){}
};
food zhushi[3]={food("米饭",2),food("花卷",1),food("白饼",3)};
food liangcai[3]={food("蒜蓉油麦",10),food("拍黄瓜 ",11),food("凉拌海蜇",12)};
food recai[3]={food("鱼香肉丝",23),food("肉沫茄子",13),food("松鼠鳜鱼",35)};
food soup[3]={food("西湖牛肉羹",20),food("紫菜蛋花汤",15),food("醪糟汤 ",17)};
food drink[3]={food("可乐",3),food("雪碧",3),food("啤酒",5)};
主食
food myfood[15];
int money=0;
int num=0;
//主食
void xuanzhushi()
{
void Menu();
void Diancan();
system("cls");
cout<<"\r\n";
cout<<"\r\n";
cout<<"\t\t\t主食有:\r\n";
cout<<"\t\t\t\t\t**************************************\r\n";
cout<<"\t\t\t\t\t* 1、"<<zhushi[0].name<<" 价格:"<<zhushi[0].price<<" *"<<endl;
cout<<"\t\t\t\t\t* 2、"<<zhushi[1].name<<" 价格:"<<zhushi[1].price<<" *"<<endl;
cout<<"\t\t\t\t\t* 3、"<<zhushi[2].name<<" 价格:"<<zhushi[2].price<<" *"<<endl;
cout<<"\t\t\t\t\t* *\r\n";
cout<<"\t\t\t\t\t* 4、返回 *"<<endl;
cout<<"\t\t\t\t\t**************************************\r\n";
char c;
c=getch();
switch(c)
{
case'1': myfood[num]=zhushi[0];money+=zhushi[0].price;num++;
printf("米饭");
break;
case'2': myfood[num]=zhushi[1];money+=zhushi[1].price;num++;
printf("花卷");
break;
case'3': myfood[num]=zhushi[2];money+=zhushi[2].price;num++;
printf("白饼");
break;
case'4': Diancan(); break;
default:
printf("\n输入有误!请重新选择!\n");
getch();
xuanzhushi();
}
printf("\n点餐成功!请按任意键继续点餐或者返回!\n");
getch();
if(num>30)
{
cout<<"您本次点餐已达上限!如果需要!请结算后继续点餐"<<endl;
printf("\n请按任意键返回主菜单\n");
getch();
Menu();
}
else xuanzhushi();
}
菜品
//热菜
void xuanrecai()
{
void Menu();
void Diancan();
system("cls");
cout<<"\r\n";
cout<<"\r\n";
cout<<"\t\t\t热菜有:\r\n";
cout<<"\t\t\t\t\t**************************************\r\n";
cout<<"\t\t\t\t\t* 1、"<<recai[0].name<<" 价格:"<<recai[0].price<<" *"<<endl;
cout<<"\t\t\t\t\t* 2、"<<recai[1].name<<" 价格:"<<recai[1].price<<" *"<<endl;
cout<<"\t\t\t\t\t* 3、"<<recai[2].name<<" 价格:"<<recai[2].price<<" *"<<endl;
cout<<"\t\t\t\t\t* *\r\n";
cout<<"\t\t\t\t\t* 4、返回 *"<<endl;
cout<<"\t\t\t\t\t**************************************\r\n";
char c;
c=getch();
switch(c)
{
case'1': myfood[num]=recai[0];money+=recai[0].price;num++;
printf("鱼香肉丝");
break;
case'2': myfood[num]=recai[1];money+=recai[1].price;num++;
printf("肉沫茄子");
break;
case'3': myfood[num]=recai[2];money+=recai[2].price;num++;
printf("松鼠鳜鱼");
break;
case'4': Diancan(); break;
default:
printf("\n输入有误!请重新选择!\n");
getch();
xuanrecai();
}
printf("\n点餐成功!请按任意键继续点餐或者返回!\n");
getch();
if(num>30)
{
cout<<"您本次点餐已达上限!如果需要!请结算后继续点餐"<<endl;
printf("\n请按任意键返回主菜单\n");
getch();
Menu();
}
else xuanrecai();
}
//凉菜
void xuanliangcai()
{
void Menu();
void Diancan();
system("cls");
cout<<"\r\n";
cout<<"\r\n";
cout<<"\t\t\t凉菜有:\r\n";
cout<<"\t\t\t\t\t**************************************\r\n";
cout<<"\t\t\t\t\t* 1、"<<liangcai[0].name<<" 价格:"<<liangcai[0].price<<" *"<<endl;
cout<<"\t\t\t\t\t* 2、"<<liangcai[1].name<<" 价格:"<<liangcai[1].price<<" *"<<endl;
cout<<"\t\t\t\t\t* 3、"<<liangcai[2].name<<" 价格:"<<liangcai[2].price<<" *"<<endl;
cout<<"\t\t\t\t\t* *\r\n";
cout<<"\t\t\t\t\t* 4、返回 *"<<endl;
cout<<"\t\t\t\t\t**************************************\r\n";
char c;
c=getch();
switch(c)
{
case'1': myfood[num]=liangcai[0];money+=liangcai[0].price;num++;
printf("蒜蓉油麦");
break;
case'2': myfood[num]=liangcai[1];money+=liangcai[1].price;num++;
printf("拍黄瓜");
break;
case'3': myfood[num]=liangcai[2];money+=liangcai[2].price;num++;
printf("凉拌海蜇");
break;
case'4': Diancan(); break;
default:
printf("\n输入有误!请重新选择!\n");
getch();
xuanliangcai();
}
printf("\n点餐成功!请按任意键继续点餐或者返回!\n");
getch();
if(num>30)
{
cout<<"您本次点餐已达上限!如果需要!请结算后继续点餐"<<endl;
printf("\n请按任意键返回主菜单\n");
getch();
Menu();
}
else xuanliangcai();
}
汤品及饮料
//汤
void xuansoup()
{
void Menu();
void Diancan();
system("cls");
cout<<"\r\n";
cout<<"\r\n";
cout<<"\t\t\t汤品有:\r\n";
cout<<"\t\t\t\t\t**************************************\r\n";
cout<<"\t\t\t\t\t* 1、"<<soup[0].name<<" 价格:"<<soup[0].price<<" *"<<endl;
cout<<"\t\t\t\t\t* 2、"<<soup[1].name<<" 价格:"<<soup[1].price<<" *"<<endl;
cout<<"\t\t\t\t\t* 3、"<<soup[2].name<<" 价格:"<<soup[2].price<<" *"<<endl;
cout<<"\t\t\t\t\t* *\r\n";
cout<<"\t\t\t\t\t* 4、返回 *"<<endl;
cout<<"\t\t\t\t\t**************************************\r\n";
char c;
c=getch();
switch(c)
{
case'1': myfood[num]=soup[0];money+=soup[0].price;num++;
printf("西湖牛肉羹");
break;
case'2': myfood[num]=soup[1];money+=soup[1].price;num++;
printf("紫菜蛋花汤");
break;
case'3': myfood[num]=soup[2];money+=soup[2].price;num++;
printf("醪糟汤");
break;
case'4': Diancan(); break;
default:
printf("\n输入有误!请重新选择!\n");
getch();
xuansoup();
}
printf("\n点餐成功!请按任意键继续点餐或者返回!\n");
getch();
if(num>30)
{
cout<<"您本次点餐已达上限!如果需要!请结算后继续点餐"<<endl;
printf("\n请按任意键返回主菜单\n");
getch();
Menu();
}
else xuansoup();
}
//饮料
void xuandrink()
{
void Menu();
void Diancan();
system("cls");
cout<<"\r\n";
cout<<"\r\n";
cout<<"\t\t\t饮料有:\r\n";
cout<<"\t\t\t\t\t**************************************\r\n";
cout<<"\t\t\t\t\t* 1、"<<drink[0].name<<" 价格:"<<drink[0].price<<" *"<<endl;
cout<<"\t\t\t\t\t* 2、"<<drink[1].name<<" 价格:"<<drink[1].price<<" *"<<endl;
cout<<"\t\t\t\t\t* 3、"<<drink[2].name<<" 价格:"<<drink[2].price<<" *"<<endl;
cout<<"\t\t\t\t\t* *\r\n";
cout<<"\t\t\t\t\t* 4、返回 *"<<endl;
cout<<"\t\t\t\t\t**************************************\r\n";
char c;
c=getch();
switch(c)
{
case'1': myfood[num]=drink[0];money+=drink[0].price;num++;
printf("可乐");
break;
case'2': myfood[num]=drink[1];money+=drink[1].price;num++;
printf("雪碧");
break;
case'3': myfood[num]=drink[2];money+=drink[2].price;num++;
printf("啤酒");
break;
case'4': Diancan(); break;
default:
printf("\n输入有误!请重新选择!\n");
getch();
xuandrink();
}
printf("\n点餐成功!请按任意键继续点餐或者返回!\n");
getch();
if(num>30)
{
cout<<"您本次点餐已达上限!如果需要!请结算后继续点餐"<<endl;
printf("\n请按任意键返回主菜单\n");
getch();
Menu();
}
else xuandrink();
}
需要实现的功能
//点餐
void Diancan()
{
void Menu();
system("cls");
cout<<endl<<endl<<"\t\t\t请选择主食!"<<endl<<endl;
cout<<"\t\t\t\t\t************* 您现在想 **************\r\n";
cout<<"\t\t\t\t\t******** ********"<<endl;
cout<<"\t\t\t\t\t* 1、主食 *"<<endl;
cout<<"\t\t\t\t\t* 2、热菜 *"<<endl;
cout<<"\t\t\t\t\t* 3、凉菜 *"<<endl;
cout<<"\t\t\t\t\t* 4、汤品 *"<<endl;
cout<<"\t\t\t\t\t* 5、饮料 *"<<endl;
cout<<"\t\t\t\t\t* 6、返回 *"<<endl;
cout<<"\t\t\t\t\t**************************************\r\n";
char c;
c=getch();
switch(c)
{
case'1': xuanzhushi(); break;
case'2': xuanrecai(); break;
case'3': xuanliangcai(); break;
case'4': xuansoup(); break;
case'5': xuandrink(); break;
case'6': Menu(); break;
default:
printf("\n输入有误!请重新选择!\n");
getch();
Diancan();
}
}
//查看已点
void Show()
{
void Menu();
system("cls");
int i;
for(i=0;i<num;i++)
{
cout<<i+1<<""<<myfood[i].name<<" "<<myfood[i].price<<endl;
}
cout<<"总价"<<money<<endl;
printf("\n按任意键返回主菜单!\n");
getch();
Menu();
}
//清空已点
void Clear()
{
void Menu();
system("cls");
num=0;
money=0;
printf("\n清空成功!\n按任意键返回菜单!\n");
getch();
Menu();
}
//支付
void Pay()
{
void Menu();
system("cls");
cout<<"您本次消费"<<money<<"元!请支付!"<<endl;
int m,s;
cin>>m;
s=m-money;
while(s<0)
{
cout<<"您给的资金不足,还需要"<<0-s<<"元!请继续支付现金!"<<endl;
cin>>m;
s=m+s;
}
while(s>0)
{
cout<<"找零"<<s-0<<"元!"<<endl;
printf("%d",(s-0));
break;
}
cout<<"结算后清空账单!请按 1"<<endl;
char b;
b=getch();
switch(b)
{
case'1': Clear(); break;
getch();
Menu();
}
Menu();
}
//主菜单
void Menu()
{
system("cls");
cout<<endl<<endl<<"\t\t\t欢迎光临!"<<endl<<endl;
cout<<"\t\t\t\t\t************* 您现在想 **************\r\n";
cout<<"\t\t\t\t\t******** ********"<<endl;
cout<<"\t\t\t\t\t* 1、点餐 *"<<endl;
cout<<"\t\t\t\t\t* 2、查看 *"<<endl;
cout<<"\t\t\t\t\t* 3、清空 *"<<endl;
cout<<"\t\t\t\t\t* 4、支付 *"<<endl;
cout<<"\t\t\t\t\t* 5、退出 *"<<endl;
cout<<"\t\t\t\t\t**************************************\r\n";
char c;
c=getch();
switch(c)
{
case'1': Diancan(); break;
case'2': Show(); break;
case'3': Clear(); break;
case'4': Pay(); break;
case'5': exit(0);
default:
printf("\n输入有误!请重新选择!\n");
getch();
Menu();
}
}
int main()
{
Menu();
return 0;
}
|