超市管理系統(tǒng) C語言_第1頁
超市管理系統(tǒng) C語言_第2頁
超市管理系統(tǒng) C語言_第3頁
超市管理系統(tǒng) C語言_第4頁
超市管理系統(tǒng) C語言_第5頁
已閱讀5頁,還剩30頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)

文檔簡介

1、西安郵電大學(xué)高級語言課程設(shè)計報告題 目: 超市管理系統(tǒng)院系名稱: 理學(xué)院 專業(yè)名稱: 應(yīng)用物理學(xué)班 級: 1301 學(xué)生姓名: 王松學(xué)號(8位): 07132022指導(dǎo)教師: 王西龍設(shè)計起止時間:2014年06月19日2014年06月27日1:程序模型2:原函數(shù)概況1:創(chuàng)建函數(shù)void start(); /*啟動界面*/void input(); /*商品數(shù)據(jù)信息輸入函數(shù)*/void change(); /*商品數(shù)據(jù)信息修改函數(shù)*/void dele(); /*給定指定商品名稱,刪除商品信息*/void output(); /*商品信息輸出*/void search(); /*商品信息查找*/

2、void mima();/*密碼程序*/void colour();/顏色選擇void huanying();2:商品信息錄入input()3:商品信息的修改Change()4:商品信息的刪除Dele()5:商品信息的查詢Seaerch()6:系統(tǒng)顏色選擇Colour()7:退出系統(tǒng)3:詳細(xì)設(shè)計過程1:結(jié)構(gòu)體變量的定義struct MarketGoods /*存數(shù)商品信息的結(jié)構(gòu)體*/ char goods_id30; /*商品編號*/ char goods_name30; /*商品名稱*/double goods_price; /*商品價格*/double goods_discount;/*商

3、品折扣*/int goods_amount;/*商品總數(shù)目*/int goods_remain;/*商品剩余數(shù)目*/goodsCOUNT;int count=0; /*全局變量,用于保存實際上有多少個商品*/2:歡迎界面void huanying()printf("t333333333333333333333333333333n"); printf("t3 歡迎使用 3n"); printf("t3 3n"); printf("t3 3n"); printf("t3 超市管理系統(tǒng) 3n"); p

4、rintf("t3 3n"); printf("t3 3n"); printf("t3 444444 3n"); printf("t3 3n"); printf("t3 555555555 3n"); printf("t3 3n");printf("t3333333333333333333333333333333n");3:密碼登陸void mima()/char pass6='1','2','3','

5、;4','5','6'/*假設(shè)密碼長度是6*/ char pass="123456"/*假設(shè)密碼長度是6*/ char str6,ch;int i=0;int flag=0;printf(" 請輸入密碼:"); fflush(stdin);for(i=0;i<6;i+) ch=getch(); /*讀取字符,不顯示*/stri=ch;putchar('*'); for(i=0;i<6;i+)if(stri!=passi) flag=1;break;if(flag)printf("

6、;n密碼錯誤,登錄失敗!請重新登錄n");mima();else printf("n登錄成功n");getch();system("cls");start();4:系統(tǒng)選擇界面void start() /*啟動菜單*/int chi; printf(" 超市商品管理系統(tǒng)n");printf(" *n"); printf(" *n"); printf(" 1.商品信息的錄入:n");printf(" 2.商品信息的修改:n"); printf(&q

7、uot; 3.刪除某個商品信息:n"); printf(" 4.查找商品信息:n"); printf(" 5.顏色選擇:n"); printf(" 0.退出程序n");printf(" *n"); printf(" *n"); printf(" 輸入你的選擇: "); scanf("%d",&chi); /*根據(jù)你的選擇執(zhí)行相應(yīng)的函數(shù)*/if(chi=1) input(); else if(chi=2) change();else if(

8、chi=3) dele();else if(chi=4) search(); else if(chi=5) colour();else if(chi=0) printf("你已經(jīng)退出超市商品管理系統(tǒng)!謝謝您的使用,再見n"); exit(0);elseprintf(" You Enter The Choice Is Not valid ! n");getch();system("cls");start();void huanying()printf("t333333333333333333333333333333n"

9、;); printf("t3 歡迎使用 3n"); printf("t3 3n"); printf("t3 3n"); printf("t3 超市管理系統(tǒng) 3n"); printf("t3 3n"); printf("t3 3n"); printf("t3 444444 3n"); printf("t3 3n"); printf("t3 555555555 3n"); printf("t3 3n"

10、);printf("t3333333333333333333333333333333n");5:商品信息的錄入void input() /*數(shù)據(jù)錄入*/FILE *fp;char flag20;fp=fopen("e:/student.txt","wt");doprintf("請輸入你的商品信息:n"); /*錄入商品的信息*/ printf("商品編號:"); scanf("%s",goodscount.goods_id); printf("商品名字:"

11、); scanf("%s",goodscount.goods_name); printf("商品價格:"); scanf("%lf",&goodscount.goods_price); printf("商品折扣:"); scanf("%lf",&goodscount.goods_discount); printf("商品總數(shù)目:"); scanf("%d",&goodscount.goods_amount); printf(&quo

12、t;商品剩余數(shù)目:"); scanf("%d",&goodscount.goods_remain); count+; /*存數(shù)的商品數(shù)加一*/ printf("是否繼續(xù)輸入數(shù)據(jù) y是 n否 : "); /*是否還想繼續(xù)輸入數(shù)據(jù)*/ scanf("%s",flag); while(strcmp(flag,"y")=0|strcmp(flag,"Y")=0);fwrite(&goods,sizeof(struct MarketGoods),count,fp);fclose(

13、fp);output(); /*調(diào)用顯示商品數(shù)據(jù)*/getch();system("cls");start();6:商品信息的修改void change() /*數(shù)據(jù)修改*/ FILE *fp;int i,m=0;char ch20,a20;fp=fopen("e:/student.txt","rt");while(fread(&goodsm,sizeof(struct MarketGoods),1,fp)!=NULL)m+;fclose(fp);printf("nyou sure want change goods

14、Infor y/n): ");/*根據(jù)商品的id來修改數(shù)據(jù)*/ scanf("%s",ch); if(strcmp(ch,"y")=0|strcmp(ch,"Y")=0) printf("nenter you want change goods_id:"); scanf("%s",a); for(i=0;i<count;i+) if(strcmp(goodsi.goods_id,a)=0) printf("nyou sure want change goods name

15、(y/n): "); scanf("%s",ch); if(strcmp(ch,"y")=0|strcmp(ch,"Y")=0) printf("nname:");scanf("%s",goodsi.goods_name); printf("nyou sure want change goods price(y/n): "); scanf("%s",ch); if(strcmp(ch,"y")=0|strcmp(ch,&quo

16、t;Y")=0) printf("nprice");scanf("%lf",&goodsi.goods_price); printf("nyou sure want goods discount(y/n): "); scanf("%s",ch); if(strcmp(ch,"y")=0|strcmp(ch,"Y")=0) printf("ndiscount"); scanf("%lf",&goodsi.good

17、s_discount); printf("nyou sure want goods amount(y/n): "); scanf("%s",ch); if(strcmp(ch,"y")=0|strcmp(ch,"Y")=0) printf("namount");scanf("%d",&goodsi.goods_amount);printf("nyou sure want goods remain(y/n): "); scanf("%s&q

18、uot;,ch); if(strcmp(ch,"y")=0|strcmp(ch,"Y")=0) printf("nremain"); scanf("%d",&goodsi.goods_remain); fwrite(&goods,sizeof(struct MarketGoods),count,fp);fclose(fp);output();getch();system("cls");start();7:商品信息的刪除void dele() /*數(shù)據(jù)刪除*/FILE *fp;in

19、t i,m=0,j;char ch20,c20;fp=fopen("e:/student.txt","rt");while(fread(&goodsm,sizeof(struct MarketGoods),1,fp)!=NULL)printf("%s",goodsm.goods_id);m+;fclose(fp);printf("nenter you want delete name :n"); /*根據(jù)商品的名稱來刪除數(shù)據(jù)*/ printf("name:"); scanf("

20、%s",c); for(i=0;i<count;i+) if(strcmp(c,goodsi.goods_name)=0) break; /*找到,即跳出循環(huán)*/ for(j=i;j<count-1;j+) goodsj=goodsj+1; printf("tttyou had delete %sn",c); count-;fp=fopen("e:/student.txt","wt");fwrite(&goods,sizeof(struct MarketGoods),count,fp);fclose(fp

21、);output();getch();system("cls");start();8:商品信息查詢void search() /*數(shù)據(jù)查找*/FILE *fp;int i,m=0;char a20;fp=fopen("e:/student.txt","rt");while(fread(&goodsm,sizeof(struct MarketGoods),1,fp)!=NULL)printf("%s",goodsm.goods_name);m+;printf("nenter you want loo

22、k name:"); /*根據(jù)商品的名稱來查找數(shù)據(jù)*/ scanf("%s",a); for(i=0;i<m;i+)if(strcmp(goodsi.goods_name,a)=0) printf("%s %s %lf %lf %d %d n",goodsi.goods_id,goodsi.goods_name,goodsi.goods_price,goodsi.goods_discount,goodsi.goods_amount,goodsi.goods_remain);getch();system("cls");s

23、tart();9:系統(tǒng)顏色選擇void colour() int a; printf("nntt選擇以下方案n");printf("nntt1*紅底黑字n");printf("nntt2*白底黑子");printf("nntt3*黑底紅字");printf("nntt4*綠底藍(lán)字");printf("nntt5*黃底藍(lán)字");printf("nntt6*系統(tǒng)默認(rèn)");printf("nntttt請?zhí)暨x您喜歡的顏色<1-6>."

24、;);scanf("%d",&a);switch(a)case 1:system("color 40"); break;case 2:system("color 70"); break;case 3:system("color 04"); break;case 4:system("color 21"); break;case 5:system("color 65"); break;case 6:system("color la"); break;d

25、efault:printf("nntttt輸入無效");getch();colour(); start();10:商品信息輸出void output() /*數(shù)據(jù)輸出*/ FILE *fp; int i,m=0;fp=fopen("e:/student.txt","rt");while(fread(&goodsm,sizeof(struct MarketGoods),1,fp)!=NULL)m+; fclose(fp);printf(" 編號 名稱 價格 折扣 總數(shù)目 剩余數(shù)目 n");for(i=0;i&

26、lt;m;i+)printf("%s %s %lf %lf %10d %10d n",goodsi.goods_id,goodsi.goods_name,goodsi.goods_price,goodsi.goods_discount,goodsi.goods_amount,goodsi.goods_remain);getch();system("cls");start();11:退出系統(tǒng) void start() /*啟動菜單*/int chi; printf(" 超市商品管理系統(tǒng)n");printf(" *n"

27、); printf(" *n"); printf(" 1.商品信息的錄入:n");printf(" 2.商品信息的修改:n"); printf(" 3.刪除某個商品信息:n"); printf(" 4.查找商品信息:n"); printf(" 5.顏色選擇:n"); printf(" 0.退出程序n");printf(" *n"); printf(" *n"); printf(" 輸入你的選擇: "

28、;); scanf("%d",&chi); /*根據(jù)你的選擇執(zhí)行相應(yīng)的函數(shù)*/if(chi=1) input(); else if(chi=2) change();else if(chi=3) dele();else if(chi=4) search(); else if(chi=5) colour();else if(chi=0) printf("你已經(jīng)退出超市商品管理系統(tǒng)!謝謝您的使用,再見n"); exit(0);4:調(diào)試分析調(diào)試過程中,會有很多的錯誤。語句和函數(shù)的運(yùn)用不到位,還存在許多的小錯誤。5:測試結(jié)果 通過我想同學(xué)求助,向老師咨詢,

29、查找書籍,在網(wǎng)絡(luò)上查找,最終使得程序順利運(yùn)行。1:歡迎界面2:密碼輸入3:系統(tǒng)菜單選擇界面4:商品信息錄入及保存5:商品信息的修改6:商品信息的刪除及剩余物品記錄7:物品信息的查詢8:商品信息輸出9:系統(tǒng)環(huán)境顏色的選擇10:退出系統(tǒng) 課程設(shè)計總結(jié)上學(xué)期學(xué)習(xí)了C語言,所以對于C語言有了初步和基礎(chǔ)的認(rèn)識。這次做程序設(shè)計,許多的程序過程都是通過咨詢老師,同學(xué),查詢網(wǎng)絡(luò),查找書籍做的。感到自己的C語言知識還是很欠缺。程序中許多都是自己設(shè)計的簡單的語句,很少有精彩的部分,但是很知足,畢竟是自己第一次做,感覺挺好。但是總結(jié)下來,自己可是漏洞百出。通過一周多的實習(xí)設(shè)計,使我對于C語言有了更深刻,更多的了解,

30、也是我認(rèn)識到C語言的難度,但是,我又感覺到了這門課程的樂趣,看著自己的成果一天天出現(xiàn),那種喜悅是不可言語的。過程中,我發(fā)現(xiàn)自己的基礎(chǔ)知識薄弱,英語很多不認(rèn)識,知識做的過程中還要上查詢英語方面的知識,很是費(fèi)事。還有就是有些概念很模糊,但是通過這次實習(xí),我對于C語言有了新的認(rèn)識。在這一周時間里,經(jīng)過不斷的與同學(xué)和老師的討論,是我的C語言水平有了很大的提高。此次我還感覺到,C語言是一門實用性很強(qiáng)的課程。其實真正的程序過程就是頭文件,主函數(shù),模塊函數(shù)。這些東西的組合才構(gòu)成了一個完整的函數(shù)體系。雖然說只有這幾項,但是就是這簡單的幾項,在一起通過邏輯,順序,等關(guān)系羅列開來,構(gòu)成了復(fù)雜的函數(shù)體。我就是在程序

31、作業(yè)工程中老是在各種邏輯順序中迷糊,所以浪費(fèi)了很長時間。這次的實驗設(shè)計,讓我對C語言有了很大的興趣。我相信我還會去自學(xué)的,因為我知道只是一門可以武裝子的課程。相信,通過這次的學(xué)習(xí),還有以后的學(xué)習(xí),會是我的C語言有很大的提高。 源程序#include <stdio.h> #include <stdlib.h>#include <conio.h>#include <string.h>#define COUNT 30 /*聲明商品的種類為30中*/#define N 30void start(); /*啟動界面*/void input(); /*商品數(shù)

32、據(jù)信息輸入函數(shù)*/void change(); /*商品數(shù)據(jù)信息修改函數(shù)*/void dele(); /*給定指定商品名稱,刪除商品信息*/void output(); /*商品信息輸出*/void search(); /*商品信息查找*/void mima();/*密碼程序*/void colour();/顏色選擇void huanying();void paixu();struct MarketGoods /*存數(shù)商品信息的結(jié)構(gòu)體*/ char goods_id30; /*商品編號*/ char goods_name30; /*商品名稱*/double goods_price; /*商品價

33、格*/double goods_discount;/*商品折扣*/int goods_amount;/*商品總數(shù)目*/int goods_remain;/*商品剩余數(shù)目*/goodsCOUNT;int count=0; /*全局變量,用于保存實際上有多少個商品*/void main() /*主函數(shù)*/ huanying();mima();start(); void start() /*啟動菜單*/int chi; printf(" 超市商品管理系統(tǒng)n");printf(" *n"); printf(" *n"); printf(&qu

34、ot; 1.商品信息錄入:n");printf(" 2.商品信息修改:n"); printf(" 3.商品信息刪除:n"); printf(" 4.商品信息查找:n"); printf(" 5.系統(tǒng)顏色選擇:n"); printf(" 6.商品信息輸出:n"); printf(" 0.退出程序n");printf(" *n"); printf(" *n"); printf(" 輸入你的選擇: "); sca

35、nf("%d",&chi); /*根據(jù)你的選擇執(zhí)行相應(yīng)的函數(shù)*/if(chi=1) input(); else if(chi=2) change();else if(chi=3) dele();else if(chi=4) search(); else if(chi=5) colour(); else if(chi=6) output();else if(chi=0) printf("你已經(jīng)退出超市商品管理系統(tǒng)!謝謝您的使用,再見n"); exit(0);elseprintf(" You Enter The Choice Is Not

36、valid ! n");getch();system("cls");start();void huanying()printf("t333333333333333333333333333333n"); printf("t3 歡迎使用 3n"); printf("t3 3n"); printf("t3 3n"); printf("t3 超市管理系統(tǒng) 3n"); printf("t3 3n"); printf("t3 3n");

37、printf("t3 444444 3n"); printf("t3 3n"); printf("t3 555555555 3n"); printf("t3 3n");printf("t3333333333333333333333333333333n");void mima()/char pass6='1','2','3','4','5','6'/*假設(shè)密碼長度是6*/ char pass="

38、;123456"/*假設(shè)密碼長度是6*/ char str6,ch;int i=0;int flag=0;printf(" 請輸入密碼:"); fflush(stdin);for(i=0;i<6;i+) ch=getch(); /*讀取字符,不顯示*/stri=ch;putchar('*'); for(i=0;i<6;i+)if(stri!=passi) flag=1;break;if(flag)printf("n密碼錯誤,登錄失敗!請重新登錄n");mima();else printf("n登錄成功n&q

39、uot;);getch();system("cls");start();void input() /*數(shù)據(jù)錄入*/FILE *fp;char flag20;fp=fopen("e:/student.txt","wt");doprintf("請輸入你的商品信息:n"); /*錄入商品的信息*/ printf("商品編號:"); scanf("%s",goodscount.goods_id); printf("商品名字:"); scanf("%s&q

40、uot;,goodscount.goods_name); printf("商品價格:"); scanf("%lf",&goodscount.goods_price); printf("商品折扣:"); scanf("%lf",&goodscount.goods_discount); printf("商品總數(shù)目:"); scanf("%d",&goodscount.goods_amount); printf("商品剩余數(shù)目:"); s

41、canf("%d",&goodscount.goods_remain); count+; /*存數(shù)的商品數(shù)加一*/ printf("是否繼續(xù)輸入數(shù)據(jù) y是 n否 : "); /*是否還想繼續(xù)輸入數(shù)據(jù)*/ scanf("%s",flag); while(strcmp(flag,"y")=0|strcmp(flag,"Y")=0);fwrite(&goods,sizeof(struct MarketGoods),count,fp);fclose(fp);output(); /*調(diào)用顯

42、示商品數(shù)據(jù)*/getch();system("cls");start();void paixu()FILE *fp; int m=0;int u,j,t;double dN+1;fp=fopen("e:/student.txt","rt");while(fread(&goodsm,sizeof(struct MarketGoods),1,fp)!=NULL)m+; fclose(fp); dN+1=goodscount.goods_price; for(u=1;u<N;u+) for(j=u+1;j<=N;j+)

43、if(du<dj)t=du;du=dj;dj=t; printf("商品信息:n"); printf(" 編號 名稱 價格 折扣 總數(shù)目 剩余數(shù)目 n"); for(u=1;u<=N;u+) printf("%4d",du);void change() /*數(shù)據(jù)修改*/ FILE *fp;int i,m=0;char ch20,a20;fp=fopen("e:/student.txt","rt");while(fread(&goodsm,sizeof(struct Marke

44、tGoods),1,fp)!=NULL)m+;fclose(fp);printf("nyou sure want change goodsInfor y/n): ");/*根據(jù)商品的id來修改數(shù)據(jù)*/ scanf("%s",ch); if(strcmp(ch,"y")=0|strcmp(ch,"Y")=0) printf("nenter you want change goods_id:"); scanf("%s",a); for(i=0;i<count;i+) if(

45、strcmp(goodsi.goods_id,a)=0) printf("nyou sure want change goods name(y/n): "); scanf("%s",ch); if(strcmp(ch,"y")=0|strcmp(ch,"Y")=0) printf("nname:");scanf("%s",goodsi.goods_name); printf("nyou sure want change goods price(y/n): "

46、;); scanf("%s",ch); if(strcmp(ch,"y")=0|strcmp(ch,"Y")=0) printf("nprice");scanf("%lf",&goodsi.goods_price); printf("nyou sure want goods discount(y/n): "); scanf("%s",ch); if(strcmp(ch,"y")=0|strcmp(ch,"Y"

47、)=0) printf("ndiscount"); scanf("%lf",&goodsi.goods_discount); printf("nyou sure want goods amount(y/n): "); scanf("%s",ch); if(strcmp(ch,"y")=0|strcmp(ch,"Y")=0) printf("namount");scanf("%d",&goodsi.goods_amount

48、);printf("nyou sure want goods remain(y/n): "); scanf("%s",ch); if(strcmp(ch,"y")=0|strcmp(ch,"Y")=0) printf("nremain"); scanf("%d",&goodsi.goods_remain); fwrite(&goods,sizeof(struct MarketGoods),count,fp);fclose(fp);output();getch(

49、);system("cls");start();void dele() /*數(shù)據(jù)刪除*/FILE *fp;int i,m=0,j;char ch20,c20;fp=fopen("e:/student.txt","rt");while(fread(&goodsm,sizeof(struct MarketGoods),1,fp)!=NULL)printf("%s",goodsm.goods_id);m+;fclose(fp);printf("nenter you want delete name :n

50、"); /*根據(jù)商品的名稱來刪除數(shù)據(jù)*/ printf("name:"); scanf("%s",c); for(i=0;i<count;i+) if(strcmp(c,goodsi.goods_name)=0) break; /*找到,即跳出循環(huán)*/ for(j=i;j<count-1;j+) goodsj=goodsj+1; printf("tttyou had delete %sn",c); count-;fp=fopen("e:/student.txt","wt");fwrite(&goods,sizeof(struct MarketGoods),count,fp);fc

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論