溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

如何用C語言實(shí)現(xiàn)餐廳的點(diǎn)菜系統(tǒng)

發(fā)布時(shí)間:2021-08-27 18:19:42 來源:億速云 閱讀:259 作者:chen 欄目:編程語言

本篇內(nèi)容主要講解“如何用C語言實(shí)現(xiàn)餐廳的點(diǎn)菜系統(tǒng)”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“如何用C語言實(shí)現(xiàn)餐廳的點(diǎn)菜系統(tǒng)”吧!

代碼如下:

用C語言編寫的簡(jiǎn)單的餐廳點(diǎn)菜系統(tǒng),操作簡(jiǎn)單,代碼不多,菜單可以自己更改,價(jià)格也是

#include<stdio.h>#include<stdlib.h>#include<conio.h>#include"windows.h"struct cai /*cai結(jié)構(gòu)體 實(shí)現(xiàn)對(duì)菜品 已點(diǎn)份數(shù)、名稱、原材料 的記錄*/{ int fenshu; char name[50]; int use; int price;};typedef int ElemType;struct List /*該線性表實(shí)現(xiàn)對(duì)菜品原材料的剩余量的記錄,線性表【i】對(duì)應(yīng)菜品的點(diǎn)餐菜單編碼*/{  ElemType* list; int size; int MaxSize;};/*以下為線性表的函數(shù)*/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("動(dòng)態(tài)存儲(chǔ)分配失敗!");  exit(1); } L->size=0;}void againMalloc(struct List *L){ ElemType *p=realloc(L->list,2*L->MaxSize*sizeof(ElemType)); if(!p){ printf("分配存儲(chǔ)空間失??!"); 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++;}/*表格函數(shù)*/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("已點(diǎn)菜/酒品編號(hào)  已點(diǎn)菜品名稱  已點(diǎn)份數(shù)/瓶數(shù)  價(jià)格\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("           您好,您點(diǎn)餐價(jià)格合計(jì)=%d¥\n",s); } if(j==0)  printf("顧客尚未點(diǎn)餐,無法進(jìn)行菜單打印!\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確認(rèn)并結(jié)束點(diǎn)餐)----------|-------酒品--------|\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("   |------------------份數(shù)--------------------|\n");  printf("   |------------------------------------------|\n");  printf("   | 1.一份   2.兩份     |\n");  printf("   | 3.三份   4.其他請(qǐng)直接輸入  |\n");   printf("   |------------------------------------------|\n");  printf("   |------------------------------------------|\n"); scanf("%d",&wep); if(wep>50) {system("CLS");printf("您輸入的值異?;蜻^大,請(qǐng)您檢查輸入的值!\n");continue;}/*防止誤輸入*/ else if(wep<=50) {a[p].fenshu+=wep;  system("CLS"); } } else if(p>=21&&p<=23) {   printf("   |--------------------------------------------------------|\n");  printf("   |-------------------------酒品數(shù)量-----------------------|\n");  printf("   |--------------------------------------------------------|\n");  printf("   | 1.一瓶 2.兩瓶 3.三瓶 4.其他瓶數(shù)請(qǐng)直接輸入  |\n");   printf("   |--------------------------------------------------------|\n");  printf("   |--------------------------------------------------------|\n"); scanf("%d",&wep); if(wep>50) {system("CLS");printf("您輸入的值異?;蜻^大,請(qǐng)您檢查輸入的值!\n");continue;}/*防止誤輸入*/ else if(wep<=50) { a[p].fenshu+=wep;  system("CLS"); } } else if(p!=-1) printf("對(duì)不起,你輸入的編碼沒有對(duì)應(yīng)菜品,請(qǐng)重新輸入!\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("   |---------------- 歡迎來到春曉點(diǎn)餐系統(tǒng)! -----------------|\n");   printf("   |--------------------------------------------------------|\n"); Sleep(2500);  system("CLS");  diancai(a);    /*點(diǎn)餐函數(shù),開始點(diǎn)餐吧!*/ ycldayin(yuan,a); printf("\n\n\n\n");  printf("   |--------------------------------------------------------|\n");  printf("   |-------------- 歡迎再次使用春曉點(diǎn)餐系統(tǒng)! ---------------|\n");   printf("   |--------------------------------------------------------|\n"); printf("\n\n\n\n\n\n");}

到此,相信大家對(duì)“如何用C語言實(shí)現(xiàn)餐廳的點(diǎn)菜系統(tǒng)”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI