您好,登錄后才能下訂單哦!
這篇文章給大家介紹使用C語言怎么編寫一個點菜系統,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。
具體內容如下
#include<stdio.h> #include<stdlib.h> #include<conio.h> #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語言怎么編寫一個點菜系統就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。