使用C语言怎么编写一个点菜系统
这篇文章给大家介绍使用C语言怎么编写一个点菜系统,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
公司主营业务:成都网站建设、做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。成都创新互联公司是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。成都创新互联公司推出昆都仑免费做网站回馈大家。
具体内容如下
#include#include #include #include"windows.h" struct cai /*cai结构体 实现对菜品 已点份数、名称、原材料 的记录*/ { int fenshu; char name[50]; int use; int price; }; typedef int ElemType; struct List /*该线性表实现对菜品原材料的剩余量的记录,线性表【i】对应菜品的点餐菜单编码*/ { ElemType* list; int size; int MaxSize; }; /*以下为线性表的函数*/ void InitList(struct List* L,int ms) { if(ms<=0){printf("ms 值非法!\n");exit(1);} L->MaxSize=ms; L->list=malloc(ms*sizeof(ElemType)); if(!L->list) { printf("动态存储分配失败!"); exit(1); } L->size=0; } void againMalloc(struct List *L) { ElemType *p=realloc(L->list,2*L->MaxSize*sizeof(ElemType)); if(!p){ printf("分配存储空间失败!"); exit(1); } L->list=p; L->MaxSize=2*L->MaxSize; } void InsertLastList(struct List *L,ElemType x) { if(L->size==L->MaxSize) againMalloc(L); L->list[L->size]=x; L->size++; } /*表格函数*/ void cddayin(struct cai a[]) { int i=0,j=0,s=0; for(i=0;i<30;i++) {if(a[i].fenshu>0) j++;} if(j!=0) { printf("已点菜/酒品编号 已点菜品名称 已点份数/瓶数 价格\n"); for(i=0;i<30;i++) if(a[i].fenshu>0) {printf(" %5d %10s%14d %d¥ \n",i,a[i].name,a[i].fenshu,a[i].fenshu*a[i].price); s=s+a[i].fenshu*a[i].price; } printf(" 您好,您点餐价格合计=%d¥\n",s); } if(j==0) printf("顾客尚未点餐,无法进行菜单打印!\n"); } void ycliao(struct List *yuan,struct cai a[]) { int i=1,p=0,k=0; for(i=0;i<30;i++) { do{ p=a[i].use%100; yuan->list[p]=yuan->list[p]-a[i].fenshu; a[i].use=a[i].use/100; }while(a[i].use!=0); } printf("|-------------------------------------------------------|--------------------|\n"); printf("|------------------原材料余量---------------------------|-----酒品余量-------|\n"); printf("|-------------------------------------------------------|--------------------|\n"); printf("| 10.鸡肉=%3d 11.猪肉=%3d 12.鱼肉=%3d | 50.雪花啤酒=%3d |\n",yuan->list[10],yuan->list[11],yuan->list[12],yuan->list[50]); printf("| 13.黄瓜=%3d 14.土豆=%3d 15.豆腐=%3d | 51.燕京啤酒=%3d |\n",yuan->list[13],yuan->list[14],yuan->list[15],yuan->list[51]); printf("| 16.茄子=%3d 17.青椒=%3d 18.牛肉=%3d | 52.二锅头=%3d |\n",yuan->list[16],yuan->list[17],yuan->list[18],yuan->list[52]); printf("| 19.大葱=%3d 20.鲜鸭血=%3d 21.花生=%3d | |\n",yuan->list[19],yuan->list[20],yuan->list[21]); printf("| 22.花椒=%3d 23.酱=%3d 24.胡萝卜=%3d | |\n",yuan->list[22],yuan->list[23],yuan->list[24]); printf("| 25.辣椒=%3d 26.芹菜=%3d 27.豆皮=%3d | |\n",yuan->list[25],yuan->list[26],yuan->list[27]); printf("|-------------------------------------------------------|--------------------|\n"); printf("|-------------------------------------------------------|--------------------|\n"); } void diancai(struct cai a[]) { int p=0,wep=0; do{ printf(" |----------------------------------------------|-------------------|\n"); printf(" |----------菜品(输入-1确认并结束点餐)----------|-------酒品--------|\n"); printf(" |----------------------------------------------|-------------------|\n"); printf(" | 1.宫爆鸡丁 2.鱼香肉丝 3.京酱肉丝 | 21.雪花啤酒 |\n"); printf(" | 4.地三鲜 5.水煮鱼 6.麻婆豆腐 | 22.燕京啤酒 |\n"); printf(" | 7.夫妻肺片 8.拍黄瓜 9.鲜鸭血 | 23.二锅头 |\n"); printf(" |----------------------------------------------|-------------------|\n"); printf(" |----------------------------------------------|-------------------|\n"); scanf("%d",&p); system("CLS"); if(p>=1&&p<=9) { printf(" |------------------------------------------|\n"); printf(" |------------------份数--------------------|\n"); printf(" |------------------------------------------|\n"); printf(" | 1.一份 2.两份 |\n"); printf(" | 3.三份 4.其他请直接输入 |\n"); printf(" |------------------------------------------|\n"); printf(" |------------------------------------------|\n"); scanf("%d",&wep); if(wep>50) {system("CLS");printf("您输入的值异常或过大,请您检查输入的值!\n");continue;}/*防止误输入*/ else if(wep<=50) {a[p].fenshu+=wep; system("CLS"); } } else if(p>=21&&p<=23) { printf(" |--------------------------------------------------------|\n"); printf(" |-------------------------酒品数量-----------------------|\n"); printf(" |--------------------------------------------------------|\n"); printf(" | 1.一瓶 2.两瓶 3.三瓶 4.其他瓶数请直接输入 |\n"); printf(" |--------------------------------------------------------|\n"); printf(" |--------------------------------------------------------|\n"); scanf("%d",&wep); if(wep>50) {system("CLS");printf("您输入的值异常或过大,请您检查输入的值!\n");continue;}/*防止误输入*/ else if(wep<=50) { a[p].fenshu+=wep; system("CLS"); } } else if(p!=-1) printf("对不起,你输入的编码没有对应菜品,请重新输入!\n"); }while(p!=-1); system("CLS"); cddayin(a); } void ycldayin(struct List yuan,struct cai a[]) { char l='\0'; printf("显示原材料余量?(Y/N)\n"); l=getch(); if(l=='Y'||l=='y') {system("CLS"); ycliao(&yuan,a);} else { system("CLS"); printf("\n\n\n\n");} } main() { int i=0; char l='\0'; struct List yuan; /* yuan前不用加“*” */ struct cai a[30]={ {0,"\0",0}, {0,"宫爆鸡丁",10131421,15},{0,"鱼香肉丝",1124,14},{0,"京酱肉丝",112327,16}, {0,"地三鲜",141617,10},{0,"水煮鱼",122225,50},{0,"麻婆豆腐",152225,11}, {0,"夫妻肺片",18212625,17},{0,"拍黄瓜",13252223,8},{0,"鲜鸭血",20,20}, {0,"\0",0},{0,"\0",0},{0,"\0",0}, {0,"\0",0},{0,"\0",0},{0,"\0",0}, {0,"\0",0},{0,"\0",0},{0,"\0",0}, {0,"\0",0},{0,"\0",0}, {0,"雪花啤酒",50,5},{0,"燕京啤酒",51,6},{0,"二锅头",52,4}, {0,"\0",0},{0,"\0",0},{0,"\0",0}, {0,"\0",0},{0,"\0",0},{0,"\0",0}}; InitList(&yuan,60); for(i=0;i<60;i++) InsertLastList(&yuan,100);//+rand()%50 printf("\n\n\n\n\n\n\n\n"); printf(" |--------------------------------------------------------|\n"); printf(" |---------------- 欢迎来到春晓点餐系统! -----------------|\n"); printf(" |--------------------------------------------------------|\n"); Sleep(2500); system("CLS"); diancai(a); /*点餐函数,开始点餐吧!*/ ycldayin(yuan,a); printf("\n\n\n\n"); printf(" |--------------------------------------------------------|\n"); printf(" |-------------- 欢迎再次使用春晓点餐系统! ---------------|\n"); printf(" |--------------------------------------------------------|\n"); printf("\n\n\n\n\n\n"); }
关于使用C语言怎么编写一个点菜系统就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
当前文章:使用C语言怎么编写一个点菜系统
文章位置:http://scyanting.com/article/ijcpch.html