超市管理系統(C語言)課程設計(新手)
阿新 • • 發佈:2018-12-30
一個不是很完善的設計,目的是實現基礎功能。
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <conio.h> #include <time.h> #include <windows.h> struct AD { int t; //商品類別 char name[20]; //商品名稱 int price; //商品價格 int stock; //商品庫存 char factory[20];//商品廠家 char id[20]; //商品品牌 }; struct clas //1.食品 2.化妝品 3.日用品 4.飲料 { struct AD a; struct clas *next; }; char a1[30]="靳凌霄"; //管理員賬號資訊 char b1[30]="12345678"; char c1[30]="你是誰?"; char d1[30]="我不知道"; char e1[30]="17638837824"; void passrand() //隨機數驗證碼 { char a[53]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; int i,j; char T[5]; loop:srand((int)time(0)); for(i=0;i<4;i++) { j=rand()%52; T[i]=a[j]; printf("%c",a[j]); } printf("\n請輸入驗證碼:\n"); char t[5]; scanf("%s",t); int len=strcmp(t,T); if(len==0) { printf("輸入正確。"); } else if(len!=0) { printf("請重新輸入\n"); goto loop; } } void inputpassword(char passwd[]) //密碼用*代替 { char s[30]; char temp[2]; int n; strcpy(s," "); while(1) { n=getch(); //標頭檔案conio.h if(n == 13) //13就是回車 { break; } printf("*"); memset(temp,0,sizeof(temp)); sprintf(temp,"%c",n); // 把n列印成字元儲存在temp strcat(s,temp); } printf("\n"); strcpy(passwd, s+1); } char a[30],b[30],c[30],d[30],k[30],j[30]; void password(); void window() //賬號登陸 { system("color 78"); printf("請輸入系統賬號:\n"); char x[30]; scanf("%s",&x); int len1=strcmp(a,x); if(len1==0) { password(); } else { int num; printf("賬號錯誤,輸入“1”重新輸入,輸入“其它”退出程式\n"); scanf("%d",&num); if(num==1) { window(); } else { exit(0) ; } window(); } } void bestpassword(); //管理員密碼 void bestwindow() //管理員賬號 { system("color 78"); printf("請輸入系統賬號:\n"); char x[30]; scanf("%s",&x); int len1=strcmp(a1,x); if(len1==0) { bestpassword(); } else { int num; printf("賬號錯誤,輸入“1”重新輸入,輸入“其它”退出程式\n"); scanf("%d",&num); if(num==1) { bestwindow(); } else { exit(0) ; } } } void bestchangepass(); //管理員修改密碼 void bestfindpass(); //管理員查詢密碼 void bestpassword() //管理員密碼密碼 { char y[30]; printf("請輸入賬號密碼:\n"); inputpassword(y); int len2=strcmp(b1,y); if(len2==0) { return ; } else { printf("密碼錯誤!\n"); int num; printf("請輸入您要選擇的功能:1.重新輸入\t2.修改密碼\t3.查詢密碼\n"); scanf("%d",&num); if(num==1) { bestpassword(); } else if(num==2) { bestchangepass(); } else if(num==3) { bestfindpass(); } else { printf("您選擇的功能不存在!\n"); } } } void bestchangepass() //管理員修改密碼 { char z[30]; printf("請輸入問題答案:\n%s\n",&c1); scanf("%s",&z); int len3=strcmp(d1,z); if(len3==0) { printf("請輸入您要修改的密碼:\n"); inputpassword(z); strcpy(b1,z); printf("修改成功,請重新登陸。\n"); bestwindow(); } else { printf("回答錯誤,請重試。\n"); bestchangepass(); } } void bestfindpass() //管理員查詢密碼 { char v[20]; printf("請輸入您的手機號碼:\n"); scanf("%s",&v); int len=strcmp(e1,v); if(len==0) { puts(b1); printf("請重新登入:\n"); window(); } else { printf("手機號碼錯誤,1.返回 2.重新輸入:\n"); int num; scanf("%d",&num); if(num==1) { bestpassword(); } else if(num==2) { bestfindpass(); } else { printf("輸入錯誤!"); return ; } } } void changepass(); //註冊賬號修改密碼 void findpass(); //註冊賬號查詢密碼 void password() //註冊賬號密碼 { char y[30]; printf("請輸入賬號密碼:\n"); inputpassword(y); int len2=strcmp(b,y); if(len2==0) { return ; } else { printf("密碼錯誤!\n"); int num; printf("請輸入您要選擇的功能:1.重新輸入\t2.修改密碼\t3.查詢密碼\n"); scanf("%d",&num); if(num==1) { password(); } else if(num==2) { changepass(); } else if(num==3) { findpass(); } else { printf("您選擇的功能不存在!\n"); } } } void changepass() { char z[30]; printf("請輸入問題答案:\n%s\n",&k); scanf("%s",&z); int len3=strcmp(c,z); if(len3==0) { printf("請輸入您要修改的密碼:\n"); inputpassword(z); strcpy(b,z); printf("修改成功,請重新登陸。\n"); window(); } else { printf("回答錯誤,請重試。\n"); changepass(); } } void findpass() { char v[20]; printf("請輸入您的手機號碼:\n"); scanf("%s",&v); int len=strcmp(d,v); if(len==0) { puts(b); printf("請重新登入:\n"); window(); } else { printf("手機號碼錯誤,1.返回 2.重新輸入:\n"); int num; scanf("%d",&num); if(num==1) { password(); } else if(num==2) { findpass(); } else { printf("輸入錯誤!"); return ; } } } void createwindow() //註冊賬號 { system("color 78"); printf("請註冊一個賬號:\n"); printf("請輸入系統賬號:(不超過30個字元)\n"); scanf("%s",a); start : printf("請輸入系統密碼:(不超過30個字元)\n"); inputpassword(b); printf("請確認系統密碼:\n"); inputpassword(j); int len9=strcmp(b,j); if(len9!=0) { goto start; } printf("請設定一個密保問題:\n"); scanf("%s",&k); printf("請輸入問題答案:\n"); scanf("%s",&c); printf("請輸入您的手機號碼:(以便用來找回密碼)\n"); scanf("%s",&d); printf("註冊完成。\n"); system("CLS"); } int look(struct clas *head,int T); int look1(struct clas *head,char F[]); void create(struct clas *head) //新增一個不能輸入相同資訊的功能。 { struct clas *p1=head; printf("請輸入您想要新增的資訊:\n\n"); printf("(類別)1.食品 2.化妝品 3.日用品 4.飲料\n\n"); int n=1; while(n==1) { printf("是否開始錄入商品資訊?如果是請輸入“1”,否則輸入“2”\n"); scanf("%d",&n); if(n==1) { struct clas *p2=(struct clas *)malloc(sizeof(clas)); printf("請輸入商品資訊:\n"); printf("請輸入商品類別: \t"); scanf("%d",&p2->a.t); printf("請輸入商品名稱: \t"); scanf("%s",&p2->a.name); if((look(head,p2->a.t))==1) { if((look1(head,p2->a.name))==0) { printf("請勿新增相同商品!\n"); return ; } } printf("請輸入商品價格: \t"); scanf("%d",&p2->a.price); printf("請輸入新增庫存:\t"); scanf("%d",&p2->a.stock); printf("請輸入商品廠家: \t"); scanf("%s",&p2->a.factory); printf("請輸入商品品牌: \t"); scanf("%s",&p2->a.id); p1->next=p2; p2->next=NULL; p1=p2; } else if(n==2) { printf("結束錄入。\n"); break; } else { printf("系統錯誤。\n"); break; } } } void print(struct clas *head) //輸出連結串列 { struct clas *p1=head; printf("以下為所有的商品資訊:((類別)1.食品 2.化妝品 3.日用品 4.飲料 \n"); printf("商品類別\t商品名稱\t商品價格\t商品庫存\t商品廠家\t商品品牌\n"); if(p1->next==NULL) { printf("未找到商品資訊!\n"); } while(p1->next!=NULL) { printf("%d\t\t%s\t\t%d\t\t%d\t\t%s\t\t%s\n",p1->next->a.t,p1->next->a.name,p1->next->a.price,p1->next->a.stock,p1->next->a.factory,p1->next->a.id); p1=p1->next; } } void find(struct clas *head) //查詢商品 { int T; printf("請輸入您要查詢的商品類別: \t"); scanf("%d",&T); char F[20]; printf("請輸入您要查詢的商品名稱: \t"); scanf("%s",&F); struct clas *p1=head; int m=1; while(p1->next!=NULL) { int len=strcmp(F,p1->next->a.name); if(p1->next->a.t==T&&len==0)//這裡多個分號會必定執行下面語句!!!!!!!!! { m=0; printf("您要查詢的商品資訊為: \n"); printf("商品名稱\t商品價格\t商品庫存\t商品廠家\t商品品牌\n"); printf("%s\t\t%d\t\t%d\t\t%s\t\t%s\n",p1->next->a.name,p1->next->a.price,p1->next->a.stock,p1->next->a.factory,p1->next->a.id); } p1=p1->next; } if(m==1) { printf("查詢失敗!"); } } int look(struct clas *head,int T) //查詢類別是否存在 { struct clas *p1=head; while(p1->next!=NULL) { if(p1->next->a.t==T) { return 1; } p1=p1->next; } return 0; } void sell(struct clas *head) //購買功能 { struct clas *p1=head; int priceall=0; int T; printf("請輸入您要購買的商品類別:\t"); scanf("%d",&T); char F[20]; printf("請輸入您想要購買的商品名稱:\t"); scanf("%s",F); int A=look(head,T); if(A==1) { while(p1->next!=NULL) { int len=strcmp(F,p1->next->a.name); if(len==0) { if(p1->next->a.t==T) { if(p1->next->a.stock>0) { int total; printf("請輸入您要購買商品的數量:\t"); scanf("%d",&total); if(p1->next->a.stock>=total) { printf("商品總價格為:\t\n"); priceall=p1->next->a.price*total+priceall; printf("人民幣:\t%d\n",priceall); p1->next->a.stock=p1->next->a.stock-total; break; } else { printf("庫存不足!\n"); break; } } else { printf("庫存為0!\n"); break; } } } else { printf("未找到您要購買的商品!\n"); break; } p1=p1->next; } } else if(A==0) { printf("未找到您要購買的商品!\n"); } int num; printf("是否繼續購買?(是請輸入“1”,否則請輸入“2”)\n"); scanf("%d",&num); if(num==1) { int T; printf("請輸入您要購買的商品類別:\t"); scanf("%d",&T); char F[20]; printf("請輸入您想要購買的商品名稱:\t"); scanf("%s",F); int A=look(head,T); if(A==1) { while(p1->next!=NULL) { int len=strcmp(F,p1->next->a.name); if(len==0) { if(p1->next->a.t==T) { if(p1->next->a.stock>0) { int total; printf("請輸入您要購買商品的數量:\t"); scanf("%d",&total); if(p1->next->a.stock>=total) { printf("商品總價格為:\t\n"); priceall=p1->next->a.price*total+priceall; printf("人民幣:\t%d\n",priceall); p1->next->a.stock=p1->next->a.stock-total; break; } else { printf("庫存不足!\n"); break; } } else { printf("庫存為0!\n"); break; } } } else { printf("未找到您要購買的商品!\n"); break; } p1=p1->next; } } else if(A==0) { printf("未找到您要購買的商品!\n"); } } else if(num==2) { printf("結束購買!\n"); } else { printf("無效輸入!\n"); } } void change(struct clas *head) //修改商品資訊 { struct clas *p1=head; int T; printf("請輸入您要修改的商品類別\t"); scanf("%d",&T); char F[20]; printf("請輸入您要修改的商品名稱:\t"); scanf("%s",&F); while(p1->next!=NULL) { int len=strcmp(F,p1->next->a.name); if(p1->next->a.t==T&&len==0) { int z,c,v; char x[20],b[20],l[20]; printf("請輸入您要修改的商品類別: \t"); scanf("%d",&z); printf("請輸入您要修改的商品名稱: \t"); scanf("%s",&x); printf("請輸入您要修改的商品價格: \t"); scanf("%d",&c); printf("請輸入您要修改的庫存:\t"); scanf("%d",&v); printf("請輸入您要修改的商品廠家: \t"); scanf("%s",&b); printf("請輸入您要修改的商品品牌: \t"); scanf("%s",&l); p1->next->a.t=z; strcpy(p1->next->a.name,x); p1->next->a.price=c; p1->next->a.stock=v; strcpy(p1->next->a.factory,b); strcpy(p1->next->a.id,l); } p1=p1->next; } } void frees(struct clas *head) //釋放結構體 { struct clas *p1=head; int T; printf("請輸入您要刪除的商品類別"); scanf("%d",&T); char F[20]; printf("請輸入您要刪除的商品名稱"); scanf("%s",F); if(look(head,T)==1) { while(p1->next!=NULL) { int len=strcmp(p1->next->a.name,F); if(p1->next->a.t==T&&len==0) { struct clas *t; t=p1->next; t->next=p1->next->next; p1->next=t->next; //這裡是p1->next 不是 p1 !!!!! free(t); t=NULL; printf("刪除成功。\n"); break; } p1=p1->next; } } else { printf("該商品不存在。\n"); } } int look1(struct clas *head,char F[]) //查詢名稱是否存在 { struct clas *p1=head; int m=1; while(p1->next!=NULL) { int len=strcmp(F,p1->next->a.name); if(len==0) { m=0; return 0; } p1=p1->next; } if(m==1) { return 1; } } void add(struct clas *head) //新增商品 { int T; printf("請輸入您要新增的類別:\t"); scanf("%d",&T); char F[20]; printf("請輸入您要新增到哪個商品之後(請從此類別商品中選擇):\t");//如果不存在出現BUG scanf("%s",F); struct clas *p1=head; struct clas *p2=(struct clas *)malloc(sizeof(clas)); int m=1; if(look(head,T)==1) { if(look1(head,F)==0) { while(p1->next!=NULL) { int len=strcmp(p1->next->a.name,F); if(len==0) { m=0; if(p1->next->a.t==T) { printf("請輸入您要新增的商品資訊:\n"); printf("請輸入您要新增的商品類別: \t"); scanf("%d",&p2->a.t); printf("請輸入您要新增的商品名稱: \t"); scanf("%s",&p2->a.name); if(look1(head,p2->a.name)==1) { ; } else if(look1(head,p2->a.name)==0) { printf("請勿新增相同商品,請使用修改功能更改庫存。"); break; } printf("請輸入您要新增的商品價格: \t"); scanf("%d",&p2->a.price); printf("請輸入您要新增的新增庫存:\t"); scanf("%d",&p2->a.stock); printf("請輸入您要新增的商品廠家: \t"); scanf("%s",&p2->a.factory); printf("請輸入您要新增的商品品牌: \t"); scanf("%s",&p2->a.id); p2->next=p1->next->next; //先連線在後面 p1->next->next=p2; //不能反 break; } } } p1=p1->next; } else { printf("該類別不存在。\n"); } if(m==1) { printf("未找到該商品!\n"); return ; } } } void sorts(struct clas *head) //商品排序 { int tt,price1,stock1; char name1[20],factory1[20],id1[20]; char F[20]; struct clas *p=head; struct clas *p1; struct clas *p2; int num; printf("請輸入按照哪一專案排序:\t(1.類別 2.名稱 3.價格 4.庫存 5.廠家 6.品牌 \n)"); scanf("%d",&num); if(num==1) { while(p->next!=NULL) { p1=p->next; p2=p1->next; while(p2!=NULL) { if(p1->a.t>p2->a.t) { tt=p1->a.t; p1->a.t=p2->a.t; p2->a.t=tt; strcpy(name1,p1->a.name); strcpy(p1->a.name,p2->a.name); strcpy(p2->a.name,name1); price1=p1->a.price; p1->a.price=p2->a.price; p2->a.price=price1; stock1=p1->a.stock; p1->a.stock=p2->a.stock; p2->a.stock=stock1; strcpy(factory1,p1->a.factory); strcpy(p1->a.factory,p2->a.factory); strcpy(p2->a.factory,factory1); strcpy(id1,p1->a.id); strcpy(p1->a.id,p2->a.id); strcpy(p2->a.id,id1); } p2=p2->next; //選擇排序 } p=p->next; } } else if(num==2) { while(p->next!=NULL) { p1=p->next; p2=p1->next; while(p2!=NULL) { int len=strcmp(p1->a.name,p2->a.name); if(len<0) { tt=p1->a.t; p1->a.t=p2->a.t; p2->a.t=tt; strcpy(name1,p1->a.name); strcpy(p1->a.name,p2->a.name); strcpy(p2->a.name,name1); price1=p1->a.price; p1->a.price=p2->a.price; p2->a.price=price1; stock1=p1->a.stock; p1->a.stock=p2->a.stock; p2->a.stock=stock1; strcpy(factory1,p1->a.factory); strcpy(p1->a.factory,p2->a.factory); strcpy(p2->a.factory,factory1); strcpy(id1,p1->a.id); strcpy(p1->a.id,p2->a.id); strcpy(p2->a.id,id1); } p2=p2->next; //選擇排序 } p=p->next; } } else if(num==3) { while(p->next!=NULL) { p1=p->next; p2=p1->next; while(p2!=NULL) { if(p1->a.price>p2->a.price) { tt=p1->a.t; p1->a.t=p2->a.t; p2->a.t=tt; strcpy(name1,p1->a.name); strcpy(p1->a.name,p2->a.name); strcpy(p2->a.name,name1); price1=p1->a.price; p1->a.price=p2->a.price; p2->a.price=price1; stock1=p1->a.stock; p1->a.stock=p2->a.stock; p2->a.stock=stock1; strcpy(factory1,p1->a.factory); strcpy(p1->a.factory,p2->a.factory); strcpy(p2->a.factory,factory1); strcpy(id1,p1->a.id); strcpy(p1->a.id,p2->a.id); strcpy(p2->a.id,id1); } p2=p2->next; //選擇排序 } p=p->next; } } else if(num==4) { while(p->next!=NULL) { p1=p->next; p2=p1->next; while(p2!=NULL) { if(p1->a.stock>p2->a.stock) { tt=p1->a.t; p1->a.t=p2->a.t; p2->a.t=tt; strcpy(name1,p1->a.name); strcpy(p1->a.name,p2->a.name); strcpy(p2->a.name,name1); price1=p1->a.price; p1->a.price=p2->a.price; p2->a.price=price1; stock1=p1->a.stock; p1->a.stock=p2->a.stock; p2->a.stock=stock1; strcpy(factory1,p1->a.factory); strcpy(p1->a.factory,p2->a.factory); strcpy(p2->a.factory,factory1); strcpy(id1,p1->a.id); strcpy(p1->a.id,p2->a.id); strcpy(p2->a.id,id1); } p2=p2->next; //選擇排序 } p=p->next; } } else if(num==5) { while(p->next!=NULL) { p1=p->next; p2=p1->next; while(p2!=NULL) { int len=strcmp(p1->a.factory,p2->a.factory); if(len<0) { tt=p1->a.t; p1->a.t=p2->a.t; p2->a.t=tt; strcpy(name1,p1->a.name); strcpy(p1->a.name,p2->a.name); strcpy(p2->a.name,name1); price1=p1->a.price; p1->a.price=p2->a.price; p2->a.price=price1; stock1=p1->a.stock; p1->a.stock=p2->a.stock; p2->a.stock=stock1; strcpy(factory1,p1->a.factory); strcpy(p1->a.factory,p2->a.factory); strcpy(p2->a.factory,factory1); strcpy(id1,p1->a.id); strcpy(p1->a.id,p2->a.id); strcpy(p2->a.id,id1); } p2=p2->next; //選擇排序 } p=p->next; } } else if(num==6) { while(p->next!=NULL) { p1=p->next; p2=p1->next; while(p2!=NULL) { int len=strcmp(p1->a.id,p2->a.id); if(len<0) { tt=p1->a.t; p1->a.t=p2->a.t; p2->a.t=tt; strcpy(name1,p1->a.name); strcpy(p1->a.name,p2->a.name); strcpy(p2->a.name,name1); price1=p1->a.price; p1->a.price=p2->a.price; p2->a.price=price1; stock1=p1->a.stock; p1->a.stock=p2->a.stock; p2->a.stock=stock1; strcpy(factory1,p1->a.factory); strcpy(p1->a.factory,p2->a.factory); strcpy(p2->a.factory,factory1); strcpy(id1,p1->a.id); strcpy(p1->a.id,p2->a.id); strcpy(p2->a.id,id1); } p2=p2->next; //選擇排序 } p=p->next; } } } void freeall(struct clas *head) //全部釋放 { struct clas *p1,*p2; p1=head; while(p1->next!=NULL) { p2=p1->next; p1->next=p2->next; free(p2); p2=NULL; //防止野指標 } printf("清除成功!\n"); } void filewrite(struct clas *head) //文字寫入 { struct clas *p1=head; FILE *fp; fp=fopen("shop.txt","w"); int num; printf("請選擇是否要存入已存入的商品資訊:如果是請輸入“1”,否則輸入“2”.\t"); scanf("%d",&num); fflush(stdin); //這個函式的功能具體是什麼? // fprintf(fp,"以下為所有的商品資訊:((類別)1.食品 2.化妝品 3.日用品 4.飲料 \n商品類別\t商品名稱\t商品價格\t商品庫存\t商品廠家\t商品品牌\n"); if(num==1) { if(fp==NULL) { printf("檔案開啟錯誤,程式無法繼續執行!\n"); exit(0); //表示程式正常退出。 } while(p1->next!=NULL) { fprintf(fp,"%d %s %d %d %s %s ",p1->next->a.t,p1->next->a.name,p1->next->a.price,p1->next->a.stock,p1->next->a.factory,p1->next->a.id); p1=p1->next; } fclose(fp); printf("資料儲存完畢\n"); return ; } else if(num==2) { return ; } else { printf("輸入錯誤!\n"); } p1=head; } void fileread(struct clas *head) //文字讀取 { struct clas *p1=head; FILE *fp; fp=fopen("shop.txt","r"); if(fp==NULL) { printf("開啟檔案失敗!\n"); } else { //printf("以下為所有的商品資訊:((類別)1.食品 2.化妝品 3.日用品 4.飲料 \n商品類別\t商品名稱\t商品價格\t商品庫存\t商品廠家\t商品品牌\n"); while(p1->next!=NULL) { fscanf(fp,"%d%s%d%d%s%s",&p1->next->a.t,p1->next->a.name,&p1->next->a.price,&p1->next->a.stock,p1->next->a.factory,p1->next->a.id); printf("%d%s%d%d%s%s",p1->next->a.t,p1->next->a.name,p1->next->a.price,p1->next->a.stock,p1->next->a.factory,p1->next->a.id); p1=p1->next; } } fclose(fp); p1=head; } void filewrite1(struct clas *head) //二進位制寫入 { struct clas *p1=head; FILE *fp; fp=fopen("shop.dat","wb"); int num; printf("請選擇是否要存入已存入的商品資訊:如果是請輸入“1”,否則輸入“2”.\t"); scanf("%d",&num); fflush(stdin); //這個函式的功能具體是什麼? // fprintf(fp,"以下為所有的商品資訊:((類別)1.食品 2.化妝品 3.日用品 4.飲料 \n商品類別\t商品名稱\t商品價格\t商品庫存\t商品廠家\t商品品牌\n"); if(num==1) { if(fp==NULL) { printf("檔案開啟錯誤,程式無法繼續執行!\n"); exit(0); //表示程式正常退出。 } while(p1->next!=NULL) { //fprintf(fp,"%d\t\t%s\t\t%d\t\t%d\t\t%s\t\t%s\n",p1->next->a.t,p1->next->a.name,p1->next->a.price,p1->next->a.stock,p1->next->a.factory,p1->next->a.id); fwrite(&p1->next->a,sizeof(struct clas *),1,fp); p1=p1->next; } fclose(fp); printf("資料儲存完畢\n"); return ; } else if(num==2) { return ; } else { printf("輸入錯誤!\n"); } p1=head; } void fileread1(struct clas *head) 二進位制讀取 { struct clas *p1=head; FILE *fp; fp=fopen("shop.dat","rb"); if(fp==NULL) { printf("開啟檔案失敗!\n"); } else { // printf("以下為所有的商品資訊:((類別)1.食品 2.化妝品 3.日用品 4.飲料 \n商品類別\t商品名稱\t商品價格\t商品庫存\t商品廠家\t商品品牌\n"); while(p1->next!=NULL) { // fscanf(fp,"%d%s%d%d%s%s",p1->next->a.t,p1->next->a.name,p1->next->a.price,p1->next->a.stock,p1->next->a.factory,p1->next->a.id); fread(&p1->next->a,sizeof(struct clas *),1,fp); printf("%d%s%d%d%s%s\n",p1->next->a.t,p1->next->a.name,p1->next->a.price,p1->next->a.stock,p1->next->a.factory,p1->next->a.id); p1=p1->next; } } fclose(fp); p1=head; //返回頭不要忘不然只能一次讀取 } void y() //返回登陸介面 { int num; loop:printf("請輸入您要進去的登陸頁面:1.管理員登陸 2.已註冊賬號登陸\n"); scanf("%d",&num); if(num==1) { bestwindow(); passrand(); } else if(num==2) { int NUM; printf("若未註冊賬號,請輸入3退出該介面,否則隨意輸入一個數字繼續操作:\n"); scanf("%d",&NUM); if(NUM==3) { goto loop; } window(); passrand(); } else { printf("無效輸入:\n"); y(); } } int main() { system("color 78"); int num; loop1:printf("請輸入您要使用的功能:1.管理員登入 2.註冊賬號登入(只能輸入數字)\n"); scanf("%d",&num); if(num==1) { loop2:bestwindow(); passrand(); } else if(num==2) { createwindow(); loop3:window(); passrand(); } else { printf("輸入錯誤,請重新輸入:\n"); goto loop1; } struct clas *head=(struct clas *)malloc(sizeof(clas)); struct clas *p1=head; p1->next=NULL; printf("1.食品 2.化妝品 3.日用品 4.飲料\n"); system("color 3F"); system("mode con cols=400 lines=30000 ");//調整系統Console控制檯顯示的寬度和高度,高度為?個字元,寬度為?個字元 while(1) { system("date/t"); system("time/t"); printf(" ==============================================================================\n"); printf("|| 超市商品管理系統 ||\n"); printf("||============================================================================||\n"); printf("|| ①--建立初始商品資訊 (類別)1.食品 2.化妝品 3.日用品 4.飲料||\n"); printf("|| ②--刪除某商品資訊 ||\n"); printf("|| ③--查詢某商品資訊 ||\n"); printf("|| ④--修改某商品資訊 ||\n"); printf("|| ⑤--新增某商品資訊 ||\n"); printf("|| ⑥--清空商品資訊 ||\n"); printf("|| ⑦--商品排序 ||\n"); printf("|| ⑧--檢視所有商品資訊 ||\n"); printf("|| ⑨--購買某商品 ||\n"); printf("|| ⑩--儲存資訊於檔案(txt) ||\n"); printf("|| ①①--讀取檔案資訊(txt) ||\n"); printf("|| ①②--儲存資訊於檔案(dat) ||\n"); printf("|| ①③--讀取檔案資訊(dat) ||\n"); printf("|| ①④----返回登入介面(退出前請儲存商品資訊!) ||\n"); printf("|| 〇--退出系統 ||\n"); printf(" ==============================================================================\n"); printf("請選擇對應服務種類:"); int n; scanf("%d",&n); switch(n) { case 1 :system("CLS");create(head);system("pause");break; case 2 :system("CLS");print(head);frees(head);system("pause");break; case 3 :system("CLS");find(head);system("pause");break; case 4 :system("CLS");print(head);change(head);system("pause");break; case 5 :system("CLS");print(head);add(head);system("pause");break; case 6 :system("CLS");freeall(head);system("pause");break; case 7 :system("CLS");print(head);sorts(head);print(head);system("pause");break; case 8 :system("CLS");print(head);system("pause");break; case 9 :system("CLS");print(head);sell(head);system("pause");break; case 10 :system("CLS");print(head);filewrite(head);system("pause");break; case 11 :system("CLS");fileread(head);system("pause");break; case 12 :system("CLS");print(head);filewrite1(head);system("pause");break; case 13 :system("CLS");fileread1(head);system("pause");break; case 14 :system("CLS");y();break; case 0 :system("CLS");printf("謝謝使用!!");exit(0);system("pause"); default:system("CLS");printf("選擇錯誤! 請重新選擇!\n\n");system("pause"); } } }