




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
第C語(yǔ)言實(shí)現(xiàn)餐廳管理系統(tǒng)本文實(shí)例為大家分享了C語(yǔ)言實(shí)現(xiàn)餐廳管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
在學(xué)習(xí)完C語(yǔ)言之后,寫(xiě)了一個(gè)小程序,涉及到單鏈表,文件,排序,等內(nèi)容。
這個(gè)對(duì)新手指針,函數(shù)等方面的掌握有一定的要求。
一.程序開(kāi)始界面
1.輸入不同的數(shù)字,選擇你要的操作,進(jìn)行點(diǎn)菜,修改賬單,結(jié)算等功能
2.熱賣(mài)推薦中會(huì)默認(rèn)打印當(dāng)前餐廳熱賣(mài)的各類(lèi)食物排行前三位(可以自己選擇查看前幾位,因?yàn)閼?,就沒(méi)加這個(gè)功能,要加入這個(gè)功能,簡(jiǎn)單改一下就行)
3.輸入0結(jié)算,系統(tǒng)會(huì)打印出菜單,并將數(shù)據(jù)以xls表格形式存到后臺(tái)
二.點(diǎn)餐頁(yè)面
1.此時(shí)我們選擇涼菜類(lèi)
2.選完后會(huì)打印出已選擇菜單,并提示是否修改
三.后臺(tái)文件
1.程序的菜類(lèi)文件(名字價(jià)格銷(xiāo)售量)都存于后臺(tái)文件中。使用管理員登陸可以對(duì)其進(jìn)行修改,刪除,添加等操作
2.每等一個(gè)用戶下單,程序都會(huì)對(duì)后臺(tái)菜類(lèi)文件對(duì)應(yīng)的銷(xiāo)售額進(jìn)行調(diào)整,并在下一次使用程序時(shí)對(duì)其排序,以選出銷(xiāo)量高的菜品
3.用戶下單后生成的賬單也會(huì)儲(chǔ)存于后臺(tái)(.xls)
以下是程序源代碼:
#includestdio.h
#includestdlib.h
#includeio.h
#includestring.h
#includetime.h
#definePATH"C:\\Users\\14765\\Desktop\\點(diǎn)餐系統(tǒng)"
//餐廳點(diǎn)餐程序
floatSUM=0;
//消費(fèi)總計(jì)
FILE*CheckBills;
//賬單
chardate[80];
//賬單編號(hào)
typedefstructFood{//銷(xiāo)量
charname[50];
floatprice;
intsales;
}FOOD;
typedefstructBill{
charname[30];
floatprice;
intnum;
intsign;
intsign_num;
structBill*next;
}BILL;
typedefstructDishes{
charname[30];
floatprice;
intsales;
structDishes*next;
}DISH;
voidprintMenu(){//選擇界面
printf("
-----------------------
\n");
printf("
|
菜單
|
\n");
printf("
-----------------------
\n");
printf("
|
1.熱賣(mài)推薦
|
\n");
printf("
-----------------------
\n");
printf("
|
2.涼菜
|
\n");
printf("
-----------------------
\n");
printf("
|
3.熱菜
|
\n");
printf("
-----------------------
\n");
printf("
|
4.飲品
|
\n");
printf("
-----------------------
\n");
printf("
|
5.特產(chǎn)小吃
|
\n");
printf("
-----------------------
\n");
printf("
|
6.吃遍中國(guó)系列|
\n");
printf("
-----------------------
\n");
printf("
|
0.退出并結(jié)算
|
\n");
printf("
-----------------------
\n");
printf("\n");
voidprintDishes(FILE*fp){//打印菜單文件數(shù)據(jù)
charname[20];
floatprice;
intcount=1;
inta;//銷(xiāo)量
while(fscanf(fp,"%s%f%d",name,price,a)!=EOF){
getc(fp);
printf("%2d.%-15s
%.1f\n",count++,name,price);
}
rewind(fp);
voidreviseDish(FILE*fp){//修改菜名,價(jià)格...
intsnum;
charcName[15];
floatprice;
printf("1.修改名稱\n2.修改價(jià)格\n");
do{
scanf("%d",snum);
}while(snum!=1snum!=2);
if(snum==1){
printf("請(qǐng)輸入要修改的名稱:\n");
scanf("%s",cName);
fprintf(fp,"%-15s",cName);
}else{
printf("請(qǐng)輸入要修改的價(jià)格:\n");
scanf("%f",price);
fseek(fp,16,1);
fprintf(fp,"%4.1f",price);//這兒應(yīng)該有一個(gè)判斷格式的函數(shù),確保其輸入到文件的格式(已解決)
}
rewind(fp);
voidprintDishL(DISH*dish){//打印菜單(鏈表)
DISH*temp=dish;
intcount=1;
while(temp!=NULL){
printf("%2d.%-15s%.1f\n",count++,temp-name,temp-price);
temp=temp-next;
}
//先把管理部分做了
voidreviseMenuDetail(char*setName){//修改菜單函數(shù)(具體實(shí)現(xiàn))
FILE*fp;
inta;
if((fp=fopen(setName,"r+"))==NULL){
printf("Error!\n");
exit(1);
}
B:
printf("請(qǐng)選擇:\n1.添加菜品\n2.刪除菜品\n3.修改菜品\n0.退出\n");
scanf("%d",
switch(a){
case1:{
fp=fopen(setName,"a+");
while(1){
charname[30],c;
floatprice;
printf("請(qǐng)依次輸入菜名,價(jià)格:\n");
scanf("%s%f",name,price);
fprintf(fp,"%-15s%4.1f%5d\n",name,price,0);
printf("是否繼續(xù)錄入(YorN)\n");
do{
scanf("%c",
}while(c!='Y'c!='N');
if(c=='N'){
break;
}
}
fclose(fp);
gotoB;
}
case2:{
intsnum;
fp=fopen(setName,"r+");
charname[30];
floatprice;
intsales;
DISH*dishes=NULL,*temp=NULL,*r;
while(fscanf(fp,"%s%f%d\n",name,price,sales)!=EOF){
r=(DISH*)malloc(sizeof(DISH));
strcpy(r-name,name);
r-price=price;
r-sales=sales;
//
printf("%-15s%.1f\n",name,price);
if(dishes==NULL){
temp=r;
dishes=temp;
r-next=NULL;
}else{
temp-next=r;
temp=temp-next;
r-next=NULL;
}
}
rewind(fp);
printf("請(qǐng)選擇刪除的內(nèi)容:(輸入-1退出)\n");
printDishes(fp);
while(1){
scanf("%d",snum);
if(snum==-1){
break;
}
DISH*tp=dishes,*t=NULL,*t1=NULL;
for(inti=1;isnum;i++){
t=tp;
tp=tp-next;
}
if(t==NULL){
t=dishes;
dishes=dishes-next;
free(t);
}else{
t1=tp;
t-next=tp-next;
free(t1);
}
printDishL(dishes);
}
fp=fopen(setName,"w+");
temp=dishes;
while(temp!=NULL){
strcpy(name,temp-name);
price=temp-price;
fprintf(fp,"%-15s%.1f%5d\n",name,price,temp-sales);
temp=temp-next;
}
printf("刪除完成!\n");
fclose(fp);
//
fseek(fp,22*(snum-1),0);
gotoB;
}
case3:{
intsnum;
B1:
fp=fopen(setName,"r+");
printf("請(qǐng)選擇修改的內(nèi)容:\n");
printDishes(fp);
fseek(fp,0,2);
intf=ftell(fp);
intflimit=f/27;
rewind(fp);
scanf("%d",snum);
if(snumflimit){
printf("請(qǐng)輸入正確的數(shù)字!\n");
gotoB1;
}
fseek(fp,27*(snum-1),0);
reviseDish(fp);
charc;
printf("是否繼續(xù)修改?(YorN)\n");
do{
scanf("%c",
}while(c!='Y'c!='N');
if(c=='Y'){
gotoB1;
}
fclose(fp);
gotoB;
}
case0:{
break;
}
default:{
gotoB;
}
}
voidreviseMenu(){//修改菜單函數(shù)(方法)
charpassword[30];
printf("請(qǐng)輸入管理員密碼:\n");
scanf("%s",password);
if(!strcmp(password,"520521")){
printf("登錄成功!\n");
}else{
printf("密碼錯(cuò)誤!");
return;
}
intnum;
A:
printf("請(qǐng)選擇修改的菜類(lèi):(0退出后臺(tái)管理系統(tǒng))\n");
scanf("%d",num);
switch(num){
case1:{
printf("此選項(xiàng)不可更改,請(qǐng)重新選擇\n");
gotoA;
}
case2:{
chara[]="涼菜.txt";
reviseMenuDetail(a);
gotoA;
}
case3:{
chara[]="熱菜.txt";
reviseMenuDetail(a);
gotoA;
}
case4:{
chara[]="飲品.txt";
reviseMenuDetail(a);
gotoA;
}
case5:{
chara[]="特產(chǎn)小吃.txt";
reviseMenuDetail(a);
gotoA;
}
case6:{
printf("尚未開(kāi)放!\n");
gotoA;
}
case0:{
break;
}
default:{
printf("請(qǐng)重新輸入!\n");
gotoA;
}
}
voidprintBill(BILL*bill,char*dname){
BILL*temp=bill;
printf("—————————————%s—————————————\n",dname);
floatsum=0;
intcount=1;
while(temp!=NULL){
printf("|No.%d.%-15s%d(份)*%.1f(元)
小計(jì):
%.1f(元)|\n",count++,temp-name,temp-num,temp-price,temp-num*temp-price);
printf("————————————————————————————\n");
sum+=temp-price*temp-
temp=temp-next;
}
printf("
共計(jì):
%.1f(元)\n",sum);
voidreviseBill_D(BILL**bill,intn){//(***)
BILL*temp,*r=NULL,*r0=NULL;
if(n==1){
temp=*bill;
*bill=(*bill)-next;
free(temp);
}else{
inti=1;
r=*bill;
while(in){
r0=r;
r=r-next;
temp=r-next;
i++;
}
free(r);
r0-next=temp;
}
voidrevise_sales(FILE*fp,intnum,intsalenum,intaa){
fseek(fp,27*(num-1),0);
fseek(fp,20,1);
fprintf(fp,"%5d",aa+salenum);
voidreviseBill(BILL**bill_,FILE*fp){//修改賬單
——————————要點(diǎn)(***)
intsnum,num=0,snum1,snum2;
BILL*bill=*bill_;
while(1){
BILL*temp=bill,*r;
while(temp!=NULL){
num++;
//num為鏈表內(nèi)容數(shù)目
temp=temp-next;
}
printf("請(qǐng)選擇修改的菜品(序號(hào))輸入0退出:\n");
scanf("%d",snum);
if(snum0snum=num){
r=bill;
inti=1;
while(isnum){
r=r-next;//目標(biāo)菜品
i++;
}
printf("1.修改數(shù)量2.刪除該菜品0.返回\n");
do{
scanf("%d",snum1);
if(snum1==0){
break;
}
}while(snum1!=1snum1!=2);
if(snum1==1){
printf("請(qǐng)輸入要修改的數(shù)量:\n");
scanf("%d",snum2);
if(snum2==0){
reviseBill_D(bill_,snum);
}else{
r-num=snum2;
}
}elseif(snum1==2){
reviseBill_D(bill_,snum);
}
}elseif(snum==0){
break;
}else{
printf("請(qǐng)重新輸入!\n");
}
num=0;
revise_sales(fp,r-sign,r-num,r-sign_num);
rewind(fp);
}
voidcheckDishes(FILE*fp,char*dName,char*dname){
ints,num,num1,aa;
BILL*bill=NULL,*temp,*r;
if((fp=fopen(dName,"r+"))==NULL){
printf("系統(tǒng)錯(cuò)誤,請(qǐng)聯(lián)系工作人員");
exit(1);
}
printf("請(qǐng)選擇菜品和數(shù)量(用空格分開(kāi)):(輸入0返回)\n");
printDishes(fp);
fseek(fp,0,2);
num=ftell(fp)/27;
charname[30];
floatprice;
while(1){
//賬單用鏈表來(lái)做
rewind(fp);
scanf("%d",
if(s==0){
break;
}
scanf("%d",num1);
if(s=nums0){
fseek(fp,27*(s-1),0);
fscanf(fp,"%s%f%d",name,price,aa);
r=(BILL*)malloc(sizeof(BILL));
strcpy(r-name,name);
r-price=price;
r-num=num1;
r-sign=s;//鏈表帶著菜在文件中的順序
r-sign_num=aa;
if(bill==NULL){
bill=r;
temp=bill;
}else{
temp-next=r;
temp=temp-next;
}
r-next=NULL;
printf("名稱:%s價(jià)格:%.1f數(shù)量:%d\n",name,price,num1);
}else{
printf("請(qǐng)重新選擇.\n");
continue;
}
rewind(fp);
revise_sales(fp,s,num1,aa);
}
rewind(fp);
printBill(bill,dname);
charc;
while(1){
printf("是否對(duì)已選菜品進(jìn)行修改(YorN)\n");
do{
scanf("%c",
}while(c!='Y'c!='N');
if(c=='Y'){
reviseBill(bill,fp);
printBill(bill,dname);
}else{
break;
}
}
//
if((CheckBills=fopen(date,"a+"))==NULL){
//
printf("Error!");
//
exit(1);
//
}
//bill為目前賬單鏈表,dname為菜系
//先獲取最后選擇菜的數(shù)量
intnum_1=0,_count=1;
BILL*temp1=bill,*temp2=bill;
while(temp1!=NULL){
num_1++;
temp1=temp1-next;
}
float_sum=0;
fprintf(CheckBills,"\t\t%s類(lèi)\n",dname);
fprintf(CheckBills,"序號(hào)\t
品名
\t單價(jià)(元/份)\t數(shù)量\t小計(jì)\n");//\n為換行符\r為回車(chē)符
for(inti=0;inum_1;i++){
fprintf(CheckBills,"%d\t%s\t
%.1f
\t
%d
\t%.1f(元)\n",_count++,temp2-name,temp2-price,temp2-num,temp2-num*temp2-price);
_sum+=temp2-num*temp2-price;
temp2=temp2-next;
}
SUM+=_sum;
fprintf(CheckBills,"\t\t\t共計(jì):\t%.1f(元)\n",_sum);
voidcheck_out(){//結(jié)賬
fprintf(CheckBills,"\t\t\t消費(fèi)合計(jì):%.1f(元)",SUM);
voidsellB(FILE*fp,DISH**dp,int*n){//錄入數(shù)據(jù)到鏈表
chars[30];floatp;intsales;
DISH*r,*temp;
intn1=0;
while(fscanf(fp,"%s%f%d",s,p,sales)!=EOF){
r=(DISH*)malloc(sizeof(DISH));
strcpy(r-name,s);
r-sales=sales;
r-price=p;
r-next=NULL;
if(*dp==NULL){
temp=r;
*dp=r;
}else{
temp-next=r;
temp=temp-next;
}
n1++;
}
rewind(fp);
*n=n1;
//
printf("ceshi");
voidsort(DISH*dp,intn,int*a){//將菜類(lèi)的銷(xiāo)量前五名在鏈表中的位置錄入到數(shù)組
DISH*t=dp;
intb[n];//銷(xiāo)量數(shù)列
for(inti=0;ii++){
b[i]=t-sales;
t=t-next;
}
for(inti=0;ii++){
intmax=i;
for(intj=i;jj++){
if(b[j]b[max]){
max=j;
}
}
a[i]=max+1;
b[max]=0;
}
voidprintSells(DISH*dp,char*name,int*a){
DISH*temp=dp;
printf("%s類(lèi)\n",name);
for(inti=0;ii++){
for(intj=0;ja[i]-1;j++){
temp=temp-next;
}
printf("No.%d
%s",i+1,temp-name);
if(i==2){
break;
}
printf("\n");
temp=dp;
}
printf("\n");
voidsellBriskly(){//熱賣(mài)
FILE*fp,*fp1,*fp2,*fp3;
if((fp=fopen("涼菜.txt","r"))==NULL){
printf("Error!\n");
exit(1);
}
if((fp1=fopen("熱菜.txt","r"))==NULL){
printf("Error!\n");
exit(1);
}
if((fp2=fopen("飲品.txt","r"))==NULL){
printf("Error!\n");
exit(1);
}
if((fp3=fopen("特產(chǎn)小吃.txt","r"))==NULL){
printf("Error!\n");
exit(1);
}
DISH*d=NULL,*d1=NULL,*d2=NULL,*d3=NULL;//數(shù)據(jù)鏈表
intn,n1,n2,n3;
sellB(fp,d,//文件,待錄入鏈表,鏈表長(zhǎng)度
sellB(fp1,d1,n1);
sellB(fp2,d2,n2);
sellB(fp3,d3,n3);
DISH*temp=d1;
inta[n]={0},a1[n1]={0},a2[n2]={0},a3[n3]={0};
sort(d,n,a);//目標(biāo)鏈表,長(zhǎng)度,待錄入數(shù)組。
sort(d1,n1,a1);
sort(d2,n2,a2);
sort(d3,n3,a3);
printf("————銷(xiāo)量排行————\n");
charc[]="涼菜",c1[]="熱菜",c2[]="飲品",c3[]="特產(chǎn)小吃";
printSells(d,c,a);
printSells(d1,c1,a1);
printSells(d2,c2,a2);
printSells(d3,c3,a3);
intmain(void){//可以設(shè)置一個(gè)管理員密碼
printf("—————?dú)g迎光臨西郵中餐廳—————\n\n");
printMenu();
intsNum;
time_tt;
time(
charstr[64],str1[64];
strftime(str,sizeof(str),"%Y-%m-%d%H:%M:%S",localtime(t));
//在文件命名時(shí)要注意部分英文字符不能用
strcpy(str1,str);
strcat(str,".xls");
strcpy
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 《倍數(shù)的理解與應(yīng)用課件》
- 橋隧工初級(jí)練習(xí)題及答案(附解析)
- 小螞蟻課件教學(xué)課件
- 2023年6月材料員(基礎(chǔ))模擬考試題與答案(附解析)
- 電腦系統(tǒng)啟動(dòng)順序調(diào)整與優(yōu)化技巧考核試卷
- 技術(shù)服務(wù)國(guó)際市場(chǎng)拓展與國(guó)際貿(mào)易考核試卷
- 《td水泥廠節(jié)能評(píng)估》課件
- 安全監(jiān)控系統(tǒng)的安全運(yùn)維管理流程考核試卷
- 《T推行手冊(cè)》課件
- 豆類(lèi)批發(fā)商市場(chǎng)經(jīng)營(yíng)風(fēng)險(xiǎn)防范與控制考核試卷
- 模具維護(hù)保養(yǎng)記錄表
- 汽車(chē)貨物運(yùn)單模板
- 260噸汽車(chē)吊地基承載力驗(yàn)算
- 高中語(yǔ)文第4單元家鄉(xiāng)文化生活4.3參與家鄉(xiāng)文化建設(shè)課時(shí)作業(yè)部編版必修上冊(cè)
- 火力發(fā)電廠與變電所設(shè)計(jì)防火規(guī)范
- Unit4+Extended+reading-+The+Value+of+Science高中英語(yǔ)牛津譯林版2020必修第三冊(cè)
- 小學(xué)思政課《愛(ài)國(guó)主義教育》
- 09《馬克思主義政治經(jīng)濟(jì)學(xué)概論(第二版)》第九章
- 啟動(dòng)調(diào)試期間設(shè)備代保管管理制度
- 鋼質(zhì)防火門(mén)安裝施工工藝
- 婦產(chǎn)科學(xué)教學(xué)課件:女性生殖系統(tǒng)炎癥
評(píng)論
0/150
提交評(píng)論