C語言實現(xiàn)餐廳管理系統(tǒng)
本文實例為大家分享了C語言實現(xiàn)餐廳管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
在學(xué)習(xí)完C語言之后,寫了一個小程序,涉及到單鏈表,文件,排序,等內(nèi)容。
這個對新手指針,函數(shù)等方面的掌握有一定的要求。
一.程序開始界面
1.輸入不同的數(shù)字,選擇你要的操作,進(jìn)行點菜,修改賬單,結(jié)算等功能
2.熱賣推薦中會默認(rèn)打印當(dāng)前餐廳熱賣的各類食物排行前三位(可以自己選擇查看前幾位,因為懶,就沒加這個功能,要加入這個功能,簡單改一下就行)
3.輸入0結(jié)算,系統(tǒng)會打印出菜單,并將數(shù)據(jù)以xls表格形式存到后臺
二.點餐頁面
1.此時我們選擇涼菜類
2.選完后會打印出已選擇菜單,并提示是否修改
三.后臺文件
1.程序的菜類文件(名字 價格 銷售量)都存于后臺文件中。使用管理員登陸可以對其進(jìn)行修改,刪除,添加等操作
2.每等一個用戶下單,程序都會對后臺菜類文件對應(yīng)的銷售額進(jìn)行調(diào)整,并在下一次使用程序時對其排序,以選出銷量高的菜品
3.用戶下單后生成的賬單也會儲存于后臺(.xls)
以下是程序源代碼:
#include<stdio.h> #include<stdlib.h> #include<io.h> #include<string.h> #include<time.h> #define PATH "C:\\Users\\14765\\Desktop\\點餐系統(tǒng)" //餐廳點餐程序 float SUM=0;?? ?//消費(fèi)總計? FILE *CheckBills;?? ?//賬單? char date[80];?? ?//賬單編號? ? typedef struct Food{//銷量? ?? ?char name[50]; ?? ?float price; ?? ?int sales; }FOOD; ? typedef struct Bill{ ?? ?char name[30];?? ? ?? ?float price; ?? ?int num; ?? ?int sign;? ?? ?int sign_num; ?? ?struct Bill *next; }BILL; ? typedef struct Dishes{ ?? ?char name[30]; ?? ?float price; ?? ?int sales; ?? ?struct Dishes *next; }DISH;? void printMenu(){//選擇界面? ?? ?printf(" ? ? ----------------------- ? ? ?\n"); ?? ?printf(" ? ? | ? ? ? ?菜單 ? ? ? ? | ? ? ?\n"); ?? ?printf(" ? ? ----------------------- ? ? ?\n"); ?? ?printf(" ? ? | ? ? ?1.熱賣推薦 ? ? | ? ? ?\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.吃遍中國系列 | ? ? ?\n"); ?? ?printf(" ? ? ----------------------- ? ? ?\n"); ?? ?printf(" ? ? | ? ? ?0.退出并結(jié)算 ? | ? ? ?\n"); ?? ?printf(" ? ? ----------------------- ? ? ?\n"); ?? ?printf("\n"); }? void printDishes(FILE *fp){//打印菜單文件數(shù)據(jù)? ?? ?char name[20]; ?? ?float price; ?? ?int count=1; ?? ?int a;//銷量? ?? ?while(fscanf(fp,"%s%f%d",name,&price,&a)!=EOF){ ?? ??? ?getc(fp); ?? ??? ?printf("%2d.%-15s ?%.1f\n",count++,name,price); ?? ?} ?? ?rewind(fp);? } void reviseDish(FILE *fp){//修改菜名,價格...? ?? ?int snum; ?? ?char cName[15]; ?? ?float price; ?? ?printf("1.修改名稱\n2.修改價格\n"); ?? ?do{ ?? ??? ?scanf("%d",&snum); ?? ?}while(snum!=1&&snum!=2); ?? ?if(snum==1){ ?? ??? ?printf("請輸入要修改的名稱:\n"); ?? ??? ?scanf("%s",cName); ?? ??? ?fprintf(fp,"%-15s",cName); ?? ?}else{ ?? ??? ?printf("請輸入要修改的價格:\n"); ?? ??? ?scanf("%f",&price); ?? ??? ?fseek(fp,16,1); ?? ??? ?fprintf(fp,"%4.1f",price);//這兒應(yīng)該有一個判斷格式的函數(shù),確保其輸入到文件的格式(已解決)? ?? ?} ?? ?rewind(fp); ?? ? } void printDishL(DISH *dish){//打印菜單(鏈表)? ?? ?DISH *temp=dish; ?? ?int count=1;? ?? ?while(temp!=NULL){ ?? ??? ?printf("%2d.%-15s%.1f\n",count++,temp->name,temp->price); ?? ??? ?temp=temp->next; ?? ?}? } //先把管理部分做了 void reviseMenuDetail(char *setName){//修改菜單函數(shù)(具體實現(xiàn)) ?? ?FILE *fp; ?? ?int a; ?? ?if((fp=fopen(setName,"r+"))==NULL){ ?? ??? ?printf("Error!\n"); ?? ??? ?exit(1); ?? ?} B:?? ?printf("請選擇:\n1.添加菜品\n2.刪除菜品\n3.修改菜品\n0.退出\n");? ?? ?scanf("%d",&a); ?? ?switch(a){ ?? ??? ?case 1:{ ?? ??? ??? ?fp=fopen(setName,"a+"); ?? ??? ??? ?while(1){ ?? ??? ??? ??? ?char name[30],c; ?? ??? ??? ??? ?float price; ?? ??? ??? ??? ?printf("請依次輸入菜名,價格:\n"); ?? ??? ??? ??? ?scanf("%s %f",name,&price); ?? ??? ??? ? ? ?fprintf(fp,"%-15s %4.1f%5d\n",name,price,0); ?? ??? ??? ??? ?printf("是否繼續(xù)錄入?(Y or N)\n"); ?? ??? ??? ??? ?do{ ?? ??? ??? ??? ??? ?scanf("%c",&c); ?? ??? ??? ??? ?}while(c!='Y'&&c!='N'); ?? ??? ??? ??? ?if(c=='N'){ ?? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ?} ?? ??? ??? ?} ?? ??? ??? ?fclose(fp); ?? ??? ??? ?goto B; ?? ??? ?} ?? ??? ?case 2:{ ?? ??? ??? ?int snum; ?? ??? ??? ?fp=fopen(setName,"r+"); ?? ??? ??? ?char name[30]; ?? ??? ??? ?float price; ?? ??? ??? ?int sales; ?? ??? ??? ?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("請選擇刪除的內(nèi)容:(輸入-1退出)\n"); ?? ??? ??? ?printDishes(fp); ?? ??? ??? ?while(1){ ?? ??? ??? ??? ?scanf("%d",&snum); ?? ??? ??? ??? ?if(snum==-1){ ?? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ?} ?? ??? ??? ??? ?DISH *tp=dishes,*t=NULL,*t1=NULL;? ?? ??? ??? ??? ?for(int i=1;i<snum;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); ?? ??? ??? ?goto B; ?? ??? ?} ?? ??? ?case 3:{ ?? ??? ??? ?int snum; B1:?? ??? ??? ?fp=fopen(setName,"r+"); ?? ??? ??? ?printf("請選擇修改的內(nèi)容:\n"); ?? ??? ??? ?printDishes(fp); ?? ??? ??? ?fseek(fp,0,2); ?? ??? ??? ?int f=ftell(fp); ?? ??? ??? ?int flimit=f/27; ?? ??? ??? ?rewind(fp); ?? ??? ??? ?scanf("%d",&snum); ?? ??? ??? ?if(snum>flimit){ ?? ??? ??? ??? ?printf("請輸入正確的數(shù)字!\n"); ?? ??? ??? ??? ?goto B1; ?? ??? ??? ?} ?? ??? ??? ?fseek(fp,27*(snum-1),0);? ?? ??? ??? ?reviseDish(fp);? ?? ??? ??? ?char c; ?? ??? ??? ?printf("是否繼續(xù)修改?(Y or N)\n"); ?? ??? ??? ?do{ ?? ??? ??? ??? ?scanf("%c",&c); ?? ??? ??? ?}while(c!='Y'&&c!='N'); ?? ??? ??? ?if(c=='Y'){ ?? ??? ??? ??? ?goto B1; ?? ??? ??? ?} ?? ??? ??? ?fclose(fp);?? ??? ??? ??? ? ?? ??? ??? ?goto B; ?? ??? ?} ?? ??? ?case 0:{ ?? ??? ??? ?break; ?? ??? ?} ?? ??? ?default:{ ?? ??? ??? ?goto B; ?? ??? ?} ?? ?} }? void reviseMenu(){//修改菜單函數(shù)(方法)? ?? ?char password[30]; ?? ?printf("請輸入管理員密碼:\n"); ?? ?scanf("%s",&password); ?? ?if(!strcmp(password,"520521")){ ?? ??? ?printf("登錄成功!\n");? ?? ?}else{ ?? ??? ?printf("密碼錯誤!"); ?? ??? ?return;? ?? ?} ?? ?int num; A:?? ?printf("請選擇修改的菜類:(0退出后臺管理系統(tǒng))\n");? ?? ?scanf("%d",&num); ?? ?switch(num){ ?? ??? ?case 1:{ ?? ??? ??? ?printf("此選項不可更改,請重新選擇\n"); ?? ??? ??? ?goto A;? ?? ??? ?} ?? ??? ?case 2:{ ?? ??? ??? ?char a[]="涼菜.txt"; ?? ??? ??? ?reviseMenuDetail(a); ?? ??? ??? ?goto A; ?? ??? ?} ?? ??? ?case 3:{ ?? ??? ??? ?char a[]="熱菜.txt"; ?? ??? ??? ?reviseMenuDetail(a); ?? ??? ??? ?goto A; ?? ??? ?} ?? ??? ?case 4:{ ?? ??? ??? ?char a[]="飲品.txt"; ?? ??? ??? ?reviseMenuDetail(a); ?? ??? ??? ?goto A; ?? ??? ?} ?? ??? ?case 5:{ ?? ??? ??? ?char a[]="特產(chǎn)小吃.txt"; ?? ??? ??? ?reviseMenuDetail(a); ?? ??? ??? ?goto A; ?? ??? ?} ?? ??? ?case 6:{? ?? ??? ??? ?printf("尚未開放!\n");? ?? ??? ??? ?goto A; ?? ??? ?} ?? ??? ?case 0:{ ?? ??? ??? ? ?? ??? ??? ?break; ?? ??? ?}? ?? ??? ?default:{ ?? ??? ??? ?printf("請重新輸入!\n"); ?? ??? ??? ?goto A; ?? ??? ?} ?? ?}? } ? void printBill(BILL *bill,char *dname){ ?? ?BILL *temp=bill; ?? ?printf("—————————————%s—————————————\n",dname); ?? ?float sum=0; ?? ?int count=1; ?? ?while(temp!=NULL){ ?? ??? ?printf("|No.%d.%-15s%d(份) * %.1f(元) ? 小計: ?%.1f(元)|\n",count++,temp->name,temp->num,temp->price,temp->num*temp->price); ?? ??? ?printf("————————————————————————————\n"); ?? ??? ?sum+=temp->price*temp->num; ?? ??? ?temp=temp->next;?? ??? ? ?? ?} ?? ?printf(" ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?共計: ?%.1f(元)\n",sum);? } void reviseBill_D(BILL **bill,int n){//(***) ?? ?BILL *temp,*r=NULL,*r0=NULL;? ?? ?if(n==1){ ?? ??? ?temp=*bill; ?? ??? ?*bill=(*bill)->next; ?? ??? ?free(temp); ?? ?}else{ ?? ??? ?int i=1; ?? ??? ?r=*bill; ?? ??? ?while(i<n){ ?? ??? ??? ?r0=r; ?? ??? ??? ?r=r->next; ?? ??? ??? ?temp=r->next; ?? ??? ??? ?i++; ?? ??? ?} ?? ??? ?free(r); ?? ??? ?r0->next=temp; ?? ?} } void revise_sales(FILE *fp,int num,int salenum,int aa){ ?? ?fseek(fp,27*(num-1),0); ?? ?fseek(fp,20,1); ?? ?fprintf(fp,"%5d",aa+salenum); } void reviseBill(BILL **bill_,FILE *fp){ //修改賬單 ?——————————要點(***)? ?? ?int snum,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("請選擇修改的菜品(序號) 輸入0退出:\n"); ?? ??? ?scanf("%d",&snum); ?? ??? ?if(snum>0&&snum<=num){ ? ?? ??? ??? ?r=bill; ?? ??? ??? ?int i=1; ?? ??? ??? ?while(i<snum){ ?? ??? ??? ??? ?r=r->next; //目標(biāo)菜品 ?? ??? ??? ??? ?i++;? ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ??? ?printf("1.修改數(shù)量 2.刪除該菜品 0.返回\n"); ?? ??? ??? ? ?? ??? ??? ?do{ ?? ??? ??? ??? ?scanf("%d",&snum1); ?? ??? ??? ??? ?if(snum1==0){ ?? ??? ??? ??? ??? ?break; ?? ??? ??? ??? ?}? ?? ??? ??? ?}while(snum1!=1&&snum1!=2); ?? ??? ??? ? ?? ??? ??? ? ?? ??? ??? ?if(snum1==1){ ?? ??? ??? ??? ? ?? ??? ??? ??? ?printf("請輸入要修改的數(shù)量:\n"); ?? ??? ??? ??? ? ?? ??? ??? ??? ?scanf("%d",&snum2); ?? ??? ??? ??? ??? ??? ??? ??? ? ?? ??? ??? ??? ? ?? ??? ??? ??? ?if(snum2==0){ ?? ??? ??? ??? ??? ?reviseBill_D(bill_,snum); ?? ??? ??? ??? ??? ? ?? ??? ??? ??? ?}else{ ?? ??? ??? ??? ??? ?r->num=snum2; ?? ??? ??? ??? ?} ?? ??? ??? ? ?? ??? ??? ? ?? ??? ??? ?}else if(snum1==2){ ?? ??? ??? ??? ?reviseBill_D(bill_,snum); ?? ??? ??? ??? ? ?? ??? ??? ?} ?? ??? ??? ? ?? ??? ?}else if(snum==0){ ?? ??? ??? ?break; ?? ??? ?}else{ ?? ??? ??? ?printf("請重新輸入!\n"); ?? ??? ?} ?? ??? ?num=0;? ?? ??? ?revise_sales(fp,r->sign,r->num,r->sign_num); ?? ??? ?rewind(fp); ?? ?} ?? ? }? ? ? void checkDishes(FILE *fp,char *dName,char *dname){ ?? ?int s,num,num1,aa;? ?? ?BILL *bill=NULL,*temp,*r; ?? ? ?? ?if((fp=fopen(dName,"r+"))==NULL){ ?? ??? ?printf("系統(tǒng)錯誤,請聯(lián)系工作人員"); ?? ??? ?exit(1); ?? ?} ?? ?printf("請選擇菜品和數(shù)量(用空格分開):(輸入0返回)\n");? ?? ?printDishes(fp); ?? ?fseek(fp,0,2); ?? ?num=ftell(fp)/27; ?? ?char name[30]; ?? ?float price; ?? ?while(1){ ? //賬單用鏈表來做? ?? ??? ?rewind(fp); ?? ??? ?scanf("%d",&s); ?? ??? ?if(s==0){ ?? ??? ??? ?break; ?? ??? ?} ?? ??? ?scanf("%d",&num1); ?? ??? ?if(s<=num&&s>0){ ?? ??? ??? ?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 價格:%.1f 數(shù)量:%d\n",name,price,num1); ?? ??? ?}else{ ?? ??? ??? ?printf("請重新選擇.\n"); ?? ??? ??? ?continue; ?? ??? ?} ?? ??? ?rewind(fp); ?? ??? ?revise_sales(fp,s,num1,aa);?? ? ?? ?}? ?? ?rewind(fp); ?? ?printBill(bill,dname); ?? ? ?? ?char c; ?? ?while(1){ ?? ??? ?printf("是否對已選菜品進(jìn)行修改?(Y or N)\n"); ?? ??? ?do{ ?? ??? ??? ?scanf("%c",&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ù)量 ?? ?int num_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類\n",dname); ?? ? ?? ?fprintf(CheckBills,"序號\t ? 品名 ? \t單價(元/份)\t數(shù)量\t小計\n");// \n為換行符\r為回車符? ?? ?for(int i=0;i<num_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共計:\t%.1f(元)\n",_sum); ? } void check_out(){//結(jié)賬? ?? ?fprintf(CheckBills,"\t\t\t消費(fèi)合計: %.1f(元)",SUM); } ? ? void sellB(FILE *fp,DISH **dp,int *n){//錄入數(shù)據(jù)到鏈表? ?? ?char s[30];float p;int sales; ? ?? ?DISH *r,*temp; ?? ?int n1=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"); } void sort(DISH *dp,int n,int *a){//將菜類的銷量前五名在鏈表中的位置錄入到數(shù)組? ?? ?DISH *t=dp; ?? ?int b[n];//銷量數(shù)列? ?? ? ?? ?for(int i=0;i<n;i++){ ?? ??? ?b[i]=t->sales; ?? ??? ?t=t->next;? ?? ?} ?? ? ?? ?for(int i=0;i<n;i++){ ?? ??? ?int max=i; ?? ??? ?for(int j=i;j<n;j++){ ?? ??? ??? ?if(b[j]>b[max]){ ?? ??? ??? ??? ?max=j; ?? ??? ??? ?} ?? ??? ?} ?? ??? ?a[i]=max+1; ?? ??? ?b[max]=0; ?? ?} } void printSells(DISH *dp,char *name,int *a){ ?? ?DISH *temp=dp;? ?? ?printf("%s類\n",name); ?? ? ?? ?for(int i=0;i<3;i++){ ?? ??? ?for(int j=0;j<a[i]-1;j++){ ?? ??? ??? ?temp=temp->next;? ?? ??? ?} ?? ??? ?printf("No.%d ? ?%s",i+1,temp->name); ?? ??? ?if(i==2){ ?? ??? ??? ?break; ?? ??? ?} ?? ??? ?printf("\n");? ?? ??? ?temp=dp; ?? ?} ?? ? ?? ?printf("\n"); } void sellBriskly(){//熱賣? ?? ?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ù)鏈表? ?? ?int n,n1,n2,n3; ?? ? ?? ?sellB(fp,&d,&n);//文件,待錄入鏈表,鏈表長度? ?? ?sellB(fp1,&d1,&n1); ?? ?sellB(fp2,&d2,&n2); ?? ?sellB(fp3,&d3,&n3); ?? ? ?? ?DISH *temp=d1;?? ? ?? ? ?? ?int a[n]={0},a1[n1]={0},a2[n2]={0},a3[n3]={0};? ?? ? ?? ?sort(d,n,a);//目標(biāo)鏈表,長度,待錄入數(shù)組。? ?? ?sort(d1,n1,a1); ?? ?sort(d2,n2,a2); ?? ?sort(d3,n3,a3); ?? ??? ? ?? ?printf("————銷量排行————\n"); ?? ?char c[]="涼菜",c1[]="熱菜",c2[]="飲品",c3[]="特產(chǎn)小吃"; ?? ?printSells(d,c,a); ?? ?printSells(d1,c1,a1); ?? ?printSells(d2,c2,a2); ?? ?printSells(d3,c3,a3); ?? ??? ? } int main(void){//可以設(shè)置一個管理員密碼? ?? ?printf("—————?dú)g迎光臨 西郵中餐廳—————\n\n"); ?? ?printMenu();? ?? ?int sNum; ?? ?time_t t; ?? ?time(&t); ?? ?char str[64],str1[64]; ?? ?strftime(str,sizeof(str),"%Y-%m-%d %H:%M:%S",localtime(&t)); ?? ?//在文件命名時要注意部分英文字符不能用?? ? ?? ?strcpy(str1,str); ?? ?strcat(str,".xls"); ?? ?strcpy(date,str);? ?? ? ?? ?if((CheckBills=fopen(date,"a+"))==NULL){ ?? ??? ?printf("Error!\n"); ?? ??? ?exit(1); ?? ?} ?? ?fprintf(CheckBills,"\t ? ?%s 消費(fèi)記錄\n",str1); ?? ? A:?? ?printf("請選擇菜類:(輸入0結(jié)算)\n");? ?? ?scanf("%d",&sNum); ?? ?FILE *fp;? ?? ?BILL *bill=NULL; ?? ?switch(sNum){ ?? ??? ?case 1:{//熱賣推薦,要隨著顧客點菜進(jìn)行數(shù)據(jù)更新? ?? ??? ??? ?sellBriskly(); ?? ??? ??? ?goto A; ?? ??? ?} ?? ??? ?case 2:{//計算菜的數(shù)目:1.flength(fno)/一行字節(jié)數(shù) ? 2.遍歷 ?? ??? ??? ?char dname[]="涼菜"; ?? ??? ??? ?char dName[]="涼菜.txt";? ?? ??? ??? ?checkDishes(fp,dName,dname);?? ??? ??? ? ?? ??? ??? ?goto A; ?? ??? ?} ?? ??? ?case 3:{ ?? ??? ??? ?char dname[]="熱菜"; ?? ??? ??? ?char dName[]="熱菜.txt";? ?? ??? ??? ?checkDishes(fp,dName,dname);? ?? ??? ??? ?goto A; ?? ??? ?} ?? ??? ?case 4:{ ?? ??? ??? ?char dname[]="飲品"; ?? ??? ??? ?char dName[]="飲品.txt";? ?? ??? ??? ?checkDishes(fp,dName,dname); ?? ??? ??? ?goto A; ?? ??? ?} ?? ??? ?case 5:{ ?? ??? ??? ?char dname[]="特產(chǎn)小吃"; ?? ??? ??? ?char dName[]="特產(chǎn)小吃.txt";? ?? ??? ??? ?checkDishes(fp,dName,dname); ?? ??? ??? ?goto A; ?? ??? ?} ?? ??? ?case 6:{ ?? ??? ??? ?printf("尚未開放!\n");? ?? ??? ??? ?goto A; ?? ??? ?} ?? ??? ?case 0:{ ?? ??? ??? ?check_out(); ?? ??? ??? ?break; ?? ??? ?} ?? ??? ?case -1:{ ?? ??? ??? ?reviseMenu(); ?? ??? ??? ?return 0; ? ?? ??? ?} ?? ??? ?default:{ ?? ??? ??? ?printf("請重新輸入."); ?? ??? ??? ?goto A; ?? ??? ?} ?? ?} //fclose為什么會錯?? OK! ?? ?fclose(CheckBills); ?? ?FILE *fp1; ?? ?if((fp1=fopen(date,"r+"))==NULL){ ?? ??? ?printf("Error!"); ?? ??? ?exit(1); ?? ?} ?? ?char stre[100]; ?? ?while(fgets(stre,100,fp1)!=NULL){ ?? ??? ?printf("%s",stre); ?? ?} ?? ?printf("\n————感謝惠顧,期待您下次光臨!————"); }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C++中字符串全排列算法及next_permutation原理詳解
這篇文章主要為大家詳細(xì)介紹了C++中字符串全排列(遞歸法)和(迭代法)以及next_permutation底層原理,文中的示例代碼講解詳細(xì),感興趣的可以了解一下2023-02-02solaris操作系統(tǒng)做c應(yīng)用程序開發(fā)步驟
solaris操作系統(tǒng)做c應(yīng)用程序開發(fā)步驟,大家參考使用吧2013-12-12