如何用C语言实现餐厅的点菜系统
本篇内容主要讲解“如何用C语言实现餐厅的点菜系统”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“如何用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=''; 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=''; struct List yuan; /* yuan前不用加“*” */ struct cai a[30]={ {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,"雪花啤酒",50,5},{0,"燕京啤酒",51,6},{0,"二锅头",52,4}, {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://ybzwz.com/article/giigjg.html