C課程設(shè)計報告-超市管理系統(tǒng)_第1頁
C課程設(shè)計報告-超市管理系統(tǒng)_第2頁
C課程設(shè)計報告-超市管理系統(tǒng)_第3頁
C課程設(shè)計報告-超市管理系統(tǒng)_第4頁
C課程設(shè)計報告-超市管理系統(tǒng)_第5頁
已閱讀5頁,還剩20頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、西安郵電大學(xué)C語言課程設(shè)計報告 題 目: 超市管理系統(tǒng) 院系名稱: 計算機學(xué)院 專業(yè)名稱: 計算機科學(xué)與技術(shù)班 級: 110X班學(xué)生姓名: 甘甘學(xué)號(8位): 04111XXX指導(dǎo)教師: 宋老師設(shè)計起止時間:2012年6月6日2012年6月15日一. 設(shè)計目的1、 強化上機動手能力,在理論和實踐的基礎(chǔ)上進(jìn)一步鞏固C語言程序設(shè)計課程學(xué)習(xí)的內(nèi)容,掌握工程化軟件設(shè)計的基本方法2、 學(xué)會將知識應(yīng)用于實際的方法,提高分析和解決問題的能力,增加綜合能力3、 為后續(xù)各門計算機課程的學(xué)習(xí)打下堅實基礎(chǔ)二. 設(shè)計內(nèi)容1、運用結(jié)構(gòu)體、鏈表和指針編輯一個簡單的超市商品基本信息管理系統(tǒng),使之能夠完成商品基本信息的錄入、

2、修改、刪除、添加、排序、統(tǒng)計、查詢、退出操作。2、執(zhí)行編譯操作,并根據(jù)提示調(diào)試此程序,排除所有的錯誤和警告。直到編譯成功為止。3、執(zhí)行運行操作,逐一對每個模塊進(jìn)行調(diào)試。直到全部程序運行成功為止。4、請老師檢查,向老師演練此程序,并能回答老師提出的相關(guān)問題。三概要設(shè)計1功能模塊圖;主 函 數(shù) 錄入模塊 修改模塊 刪除模塊 添加模塊 排序模塊 統(tǒng)計模塊 查詢模塊退出模塊2各個模塊詳細(xì)的功能描述。(1)錄入模塊:對定義的商品信息結(jié)構(gòu)體變量,利用循環(huán),將鍵入的商品信息保存至指定文件。其中,貨號、價格、數(shù)量定義為整型,名稱、類型定義為字符型。輸入完成后,按任意鍵返回菜單。(2)修改模塊:選擇修改選項,界

3、面顯示出所有商品信息,輸入要修改商品的貨號,利用循環(huán)、判斷語句,找到對應(yīng)的信息,再利用switch語句選擇任意一項進(jìn)行修改,若沒有與貨號所對應(yīng)的商品信息,按任意鍵返回菜單。 (3)刪除模塊: 選擇刪除選項,界面顯示出所有商品信息,選擇商品貨號,再進(jìn)行刪除。若無與貨號相對應(yīng)的商品信息,則輸出“抱歉!找不到與貨號相對應(yīng)的商品信息”。 (4)增加模塊:選擇增加選項,按界面提示逐步輸入商品信息。 (5)排序模塊:選擇排序選項。有2種排序方式:按價格排序,按貨號排序。選擇其中一項,將顯示價格從高到低的排列的商品信息或貨號從大到小排列的商品信息。(6)統(tǒng)計模塊:選擇統(tǒng)計選項。利用輸出函數(shù)將所有商品信息在界

4、面上顯示出來。(7)查找模塊:選擇查找選項。此模塊有2種查詢方式:按貨號查找、按價格查找。通過循環(huán)判斷查找,如果找到則顯示該商品的全部信息,否則,將輸出沒有查到該商品信息,,給以提示。(8)退出模塊:選擇退出選項。若想要繼續(xù)商品管理系統(tǒng)則輸入Y,否則輸入N。四詳細(xì)設(shè)計1功能函數(shù)的調(diào)用關(guān)系圖主函數(shù)登錄系統(tǒng)函數(shù)退出系統(tǒng)函數(shù)顧客系統(tǒng)員工系統(tǒng)錄入函數(shù)修改函數(shù)刪除函數(shù)增加函數(shù)排序函數(shù)統(tǒng)計函數(shù)查找函數(shù)退出函數(shù)排序函數(shù)統(tǒng)計函數(shù)查找函數(shù)退出函數(shù)按價格排序按貨號排序按價格查找按貨號查找2各功能函數(shù)的數(shù)據(jù)流程圖錄入模塊輸入信息輸入成功返回菜單修改模塊輸入修改商品貨號顯示商品基本信息信息存在貨號名稱類別單價數(shù)量選擇

5、修改項顯示修改后信息返回菜單刪除模塊顯示所有商品信息選擇貨號成功刪除顯示刪除后的商品信息返回菜單無此商品增加模塊輸入貨號輸入名稱輸入類型輸入單價輸入數(shù)量成功輸入返回菜單排序模塊按價格排序按貨號排序選擇價格選擇貨號顯示排序后商品信息返回菜單查找模塊按價格查找按貨號查找選擇價格選擇貨號顯示相應(yīng)的商品信息返回菜單無此價格無此貨號3重點設(shè)計及編碼(1)錄入模塊貨號 名稱 類型 單價(元) 數(shù)量 1 菜刀 廚具 15 8 6 蘋果 水果 5 254 空調(diào) 電器 3000 11 編碼:struct goods *input(void) int n=0;char ch;struct goods *head;

6、struct goods *p1,*p2; head=(struct goods *)malloc(L); p1=(struct goods *)malloc(L);p2=head; printf("nnttt請輸入商品信息:(按0結(jié)束輸入)nn");printf("ttt 貨號: "); scanf("%d",&p1->number); printf("ttt 名稱: "); scanf("%s",p1->name); printf("ttt 類型:")

7、; scanf("%s",p1->type); printf("ttt 單價(元):"); scanf("%d",&p1->price); printf("ttt 數(shù)量:"); scanf("%d",&p1->amount); while(p1->number!=0) p2->next=p1; p2=p1; p1=(struct goods *)malloc(L); printf("nttt 貨號: "); scanf("

8、;%d",&p1->number); if(p1->number=0) break; printf("ttt 名稱: "); scanf("%s",p1->name); printf("ttt 類型:"); scanf("%s",p1->type); printf("ttt 單價(元):"); scanf("%d",&p1->price); printf("ttt 數(shù)量:"); scanf("

9、;%d",&p1->amount); p2->next=NULL;free(p1);printf("nnttt 商品信息錄入成功!nnttt 按任意鍵返回菜單。 ");ch=getch(); return head ;(2)修改模塊選擇修改,輸入商品貨號,再選擇所需修改的項目:1貨號,2名稱,3類型,4單價,5數(shù)量。如選擇貨號:1,修改項:4單價,則在屏幕上顯示:貨號 名稱 類型 單價(元) 數(shù)量 1 菜刀 廚具 12 8(3)刪除模塊如要刪除某商品的信息,按貨號刪除,輸入該商品貨號,按回車鍵成功刪除。若選擇貨號:4,則屏幕上顯示:貨號 名稱

10、類型 單價(元) 數(shù)量 1 菜刀 廚具 15 8 6 蘋果 水果 5 25 若無與貨號相對應(yīng)的商品,如7號商品,則輸出“抱歉!找不到與貨號為7的商品信息”。(4)增加模塊 按屏幕提示依次輸入商品信息,如: 請輸入貨號:9 請輸入名稱:讀者 請輸入類型:雜志 請輸入單價:4 請輸入數(shù)量:10 (5)排序模塊1選擇按價格排序:貨號 名稱 類型 單價(元) 數(shù)量 1 菜刀 廚具 15 8 6 蘋果 水果 5 259 讀者 雜志 4 10 2選擇按價格排序:貨號 名稱 類型 單價(元) 數(shù)量 9 讀者 雜志 4 10 6 蘋果 水果 5 251 菜刀 廚具 15 8 編碼:struct goods *

11、sort1(struct goods *head) struct goods *p, *h, *q, *temp, t; /價格排序 h=head->next; printf("nnnnnttt商品按價格從高到低排序為:nn"); for(p = h; p ; p = p->next) for(q = p->next; q; q = q->next) if(p->price) - (q->price)<0) t = *p; *p = *q; *q = t; temp = p->next; p->next = q->

12、next; q->next = temp; print(head); printf("nttt按任意鍵返回菜單。"); return head; struct goods *sort2(struct goods *head) struct goods *p, *h, *q, *temp, t; /貨號排序 h=head->next; printf("nnnnnttt商品按貨號排序為:nn"); for(p = h; p; p = p->next) for(q = p->next; q; q = q->next) if(p-&

13、gt;number) - (q->number)<0) t = *p; *p = *q; *q = t; temp = p->next; p->next = q->next; q->next = temp; print(head); printf("nttt按任意鍵返回菜單。"); return head; (6)統(tǒng)計模塊在屏幕上顯示所有商品信息。(7)查找模塊 有兩種方式:1. 選擇按貨號查找,輸入貨號,屏幕出現(xiàn)相應(yīng)的商品信息。如輸入貨號9,則顯示:貨號 名稱 類型 單價(元) 數(shù)量 9 讀者 雜志 4 102. 選擇按價格查找,輸入價

14、格,屏幕出現(xiàn)相應(yīng)的商品信息。如輸入價格5,則顯示:貨號 名稱 類型 單價(元) 數(shù)量 6 蘋果 水果 5 25 若輸入的貨號貨價格不在統(tǒng)計表中,則輸出“沒有找到相關(guān)商品”。 編碼:find(struct goods *head) struct goods *p; int a,b;printf("請選擇:n"); printf("tt1.按貨號查找ntt2.按價格查找");printf("nntt請輸入序號: "); scanf("%d",&b); if(b=1) printf("n輸入你要查詢的商

15、品貨號: "); scanf("%d",&a); printf("n"); p=head->next;while(p!=NULL)if(p->number=a) printf(" tt貨號 名稱 類型 單價(元) 數(shù)量 "); printf("n t%d %s %s %d %dn",p->number,p->name,p->type,p->price,p->amount);break; p=p->next; if(p=NULL) printf(&qu

16、ot;n沒有找到相關(guān)商品nn") if(b=2) p=head->next;printf("n輸入你要查找的商品價格: "); scanf("%d",&a); while(p!=NULL)if(p->price=a printf(" tt貨號 名稱 類型 單價(元) 數(shù)量 "); printf("n t%d %s %s %d %dn",p->number,p->name,p->type,p->price,p->amount) break; p=p->

17、next; if(p=NULL) printf("n沒有找到相關(guān)商品nn"); printf("按任意鍵返回菜單。"); return(0);(8)退出模塊 選擇后,屏幕上將提示繼續(xù)操作還是退出。選擇Y返回主菜單,選擇N退出。五測試數(shù)據(jù)及運行結(jié)果1正常測試數(shù)據(jù)和運行結(jié)果錄入模塊: 修改模塊:刪除模塊:2異常測試數(shù)據(jù)及運行結(jié)果查找模塊:刪除模塊:六調(diào)試情況,設(shè)計技巧及體會1改進(jìn)方案我對這次的實驗設(shè)計完成的還比較滿意,這個超市管理系統(tǒng)主體上利用結(jié)構(gòu)體、鏈表完成,密碼部分運用了數(shù)組知識,運用VC編寫完成。 此程序的不足之處是基本信息方面還不夠完善,譬如沒有保質(zhì)

18、期,銷售狀況等方面的信息。另一方面就是在運行此程序時。需要執(zhí)行操作的提示語不夠具體和完善。改進(jìn)方法:在時間充足的情況下多建立結(jié)構(gòu)體數(shù)組存儲商品基本信息,使得商品信息更加完善。此外,可以在編程時加一些必要的提示語,如“輸入完畢,是否確認(rèn)”、“是否繼續(xù)”等。2體會課程設(shè)計看似簡單,實則不然。首先,我花費了三、四天時間寫程序,以后的大多數(shù)時間就在調(diào)程序。先是構(gòu)思結(jié)構(gòu)大體框架,再考慮細(xì)節(jié)。這讓我明白“宏觀主宰全局,細(xì)節(jié)決定成敗”的道理,即使是小到一個分號也有可能使你的程序無法運行。寫程序的時候必須很認(rèn)真,要有耐心,欲速則不達(dá)。程序的關(guān)鍵在于調(diào)試程序。C語言程序?qū)ξ覀儊碚f比較難,在匆忙的學(xué)習(xí)中更是難上加

19、難。在這次的學(xué)習(xí)中我學(xué)會了如何寫一個好程序,在老師和其他同學(xué)的的幫助下我學(xué)會了如何調(diào)試,如何查找系統(tǒng)沒有提示的錯誤,最后終于排除萬難把程序搞定。學(xué)習(xí)C語言以來,我第一次體會到原來編程也挺有意思的,也領(lǐng)略了熬夜編程的滋味,懂得了要收獲就得付出的道理。感謝老師和同學(xué)的幫助,讓我成功完成了課程設(shè)計。七.參考文獻(xiàn)C語言程序設(shè)計王曙燕版,C程序設(shè)計譚浩強版。八附錄:源代碼(電子版)#include<stdio.h>#include<malloc.h>#include<stdlib.h>#include<string.h>#include<window

20、s.h>#include<conio.h>#define L sizeof(struct goods)void welcome();void Menu(); int menu1();int menu2();int select1( );int select2();struct goods *readfile();void savefile(struct goods *p);struct goods *input(void); void modify(struct goods *head);struct goods *delet(struct goods *p0);struct

21、 goods *add(struct goods *head);void Sort(); struct goods *sort1(struct goods *head);struct goods *sort2(struct goods *head);print(struct goods *head);int find(struct goods *p); void finish(); struct goods /商品結(jié)構(gòu)體/int number;char name20;char type10; int price;int amount;struct goods *next;int n;void

22、main() /主函數(shù)/ system("color 37"); welcome();void welcome()char ch;printf("n n"); /歡迎界面,進(jìn)入主菜單欄printf(" nn"); printf(" # 歡迎 #n"); printf(" n"); printf(" 歡迎來到GAN超市! n"); printf(" n");printf(" GAN超市竭誠為您服務(wù)! n"); printf("

23、n");printf(" 如果您有任何問題,歡迎撥打客服熱線88888888. n"); printf(" n");printf(" 本超市禁止吸煙! n"); printf(" n");printf(" 請按任意鍵進(jìn)入主菜單 n"); printf(" nn");printf(" 制作人:甘娜n"); printf(" 班級:計科1103n"); printf(" 日期:2012年6月12日nn");pr

24、intf(" n");printf(" n"); ch=getch(); system("cls"); if(ch) printf("nn"); Menu();void Menu() /主菜單,進(jìn)行工作人員或顧客的選擇 int m; char code17="123456",s7; char code27="654321",t7; int i; printf("nnn nn"); printf(" 請登錄:nn"); printf(&q

25、uot; 1.工作人員管理系統(tǒng)。nn"); printf(" 2.顧客管理系統(tǒng)。nn"); printf(" 3.退出系統(tǒng)!nn"); printf(" 請選擇: "); scanf("%d",&m); printf("n nn"); if(m=1) printf("tt 請輸入密碼: "); flushall(); gets(s); for(i=0;i<2;i+) if(strcmp(code1,s)=0) system("cls"

26、;); menu1(); else printf("tt錯誤!重新輸入: "); gets(s); if(i=1) printf("tt輸入錯誤密碼已有3次,強行退出系統(tǒng)。n"); break; if(m=2) printf("tt 請輸入密碼: "); flushall(); gets(t); for(i=0;i<2;i+) if(strcmp(code2,t)=0) system("cls"); menu2(); else printf("tt錯誤!重新輸入: "); gets(t);

27、 if(i=1) printf("tt輸入錯誤密碼已有3次,強行退出系統(tǒng)。n"); break; if(m=3) exit (0);int menu1() /菜單欄1,工作人員管理系統(tǒng), printf("nnn 歡迎進(jìn)入工作人員管理系統(tǒng)nn");printf(" 進(jìn)行以下操作時,請保持仔細(xì)和認(rèn)真!nn");printf(" 1. 商品信息錄入.n");printf(" 2. 商品信息修改.n");printf(" 3. 商品刪除.n");printf(" 4. 商品

28、增加.n");printf(" 5. 商品排序.n"); printf(" 6. 商品統(tǒng)計.n");printf(" 7. 商品查找.n");printf(" 8. 退出系統(tǒng)!nn");printf(" 請選擇您要的操作(18): ");select1();return(0);int menu2() /菜單欄2,顧客管理系統(tǒng) printf("nnnn 歡迎進(jìn)入顧客管理系統(tǒng)!nn");printf(" 尊敬的顧客,歡迎您使用該系統(tǒng),希望您能滿意GAN超市的服

29、務(wù)!nn"); printf(" 如果您有任何疑問,請致電88888888!謝謝!nn");printf(" 5. 商品排序.n"); printf(" 6. 商品統(tǒng)計.n");printf(" 7. 商品查找.n");printf(" 8. 退出系統(tǒng)!nn");printf(" 請選擇您要的操作(58): ");select2();return(0);int select1() /選擇 int a;char ch; struct goods *head;head=

30、NULL;scanf("%d",&a);switch(a) case 1: system("cls");head=input();savefile(head);system("cls");menu1();break; / 1 輸入 case 2: system("cls");head=readfile();modify(head);savefile(head);ch=getch();system("cls");menu1();break; / 2 修改 case 3: system(&q

31、uot;cls");head=readfile();head=delet(head);savefile(head);ch=getch();system("cls");menu1(); break; / 3 刪除 case 4: system("cls"); head=readfile();head=add(head);savefile(head);ch=getch();system("cls"); menu1(); break; / 4 增加 case 5: system("cls");Sort();me

32、nu1();break; / 5 排序 case 6: system("cls");printf("nntttt 統(tǒng)計nn");head=readfile();print(head); printf("nnttt按任意鍵返回菜單。");ch=getch();system("cls");menu1(); break; / 6 統(tǒng)計 case 7: system("cls"); head=readfile();find(head);ch=getch();system("cls")

33、;menu1(); break; / 7 查找case 8: system("cls");finish(); break; / 8 結(jié)束 default:printf("ttt輸入錯誤代號!nttt請重新輸入: ");select1();return(a);int select2() /選擇函數(shù)/int b;char ch; struct goods *head;head=NULL;scanf("%d",&b);switch(b) case 5: system("cls");Sort();menu2();b

34、reak; / 5 排序 case 6: system("cls");printf("nntttt 統(tǒng)計nn");head=readfile();print(head); printf("nnttt按任意鍵返回菜單。");ch=getch();system("cls");menu2(); break; / 6 統(tǒng)計 case 7: system("cls"); head=readfile();find(head);ch=getch();system("cls");menu2(

35、); break; / 7 查找case 8: system("cls");finish(); break; / 8 結(jié)束 default: printf("ttt輸入錯誤代號!nttt請重新輸入: ");select2();return(b);struct goods *input(void) / 輸入 int n=0;char ch;struct goods *head;struct goods *p1,*p2; head=(struct goods *)malloc(L); p1=(struct goods *)malloc(L);p2=head;

36、 printf("nnttt請輸入商品信息:(按0結(jié)束輸入)nn");printf("ttt 貨號: "); scanf("%d",&p1->number); printf("ttt 名稱: "); scanf("%s",p1->name); printf("ttt 類型:"); scanf("%s",p1->type); printf("ttt 單價(元):"); scanf("%d",&

37、amp;p1->price); printf("ttt 數(shù)量:"); scanf("%d",&p1->amount); while(p1->number!=0) p2->next=p1; p2=p1; p1=(struct goods *)malloc(L); printf("nttt 貨號: "); scanf("%d",&p1->number); if(p1->number=0) break; printf("ttt 名稱: "); sca

38、nf("%s",p1->name); printf("ttt 類型:"); scanf("%s",p1->type); printf("ttt 單價(元):"); scanf("%d",&p1->price); printf("ttt 數(shù)量:"); scanf("%d",&p1->amount); p2->next=NULL;free(p1);printf("nnttt 商品信息錄入成功!nnttt

39、按任意鍵返回菜單。 ");ch=getch(); return head ;void modify(struct goods *head)int number;int n;struct goods *p;p=head;printf("n"); print(head);printf("n請輸入要修改商品的貨號: ");scanf("%d",&number);while(p!=NULL) if(p->number=number) printf("n要修改的商品信息項目:ntt 1.貨號ntt 2.名稱nt

40、t 3.類型ntt 4.單價ntt 5.數(shù)量n"); printf("nt 請選擇: "); scanf("%d",&n); if(n=1) printf("tt 請重新輸入貨號: "); scanf("%d",&p->number); else if(n=2) printf("tt 請重新輸入名稱: "); scanf("%s",p->name); else if(n=3) printf("tt 請重新輸入類型: "

41、); scanf("%s",p->type); else if(n=4) printf("tt 請重新輸入單價: "); scanf("%d",&p->price); else printf("tt 請重新輸入數(shù)量: "); scanf("%d",&p->amount); printf("n修改后的商品信息:"); printf(" 貨號 名稱 類型 單價(元) 數(shù)量 "); printf("nttt%d %s

42、%s %d %dn",p->number,p->name,p->type,p->price,p->amount); break; else p=p->next;/*if(p=NULL) printf("沒有找到相應(yīng)的商品信息");*/printf("nn按任意鍵返回菜單。");struct goods *delet(struct goods *head) struct goods *p,*p2;int a;printf("nn");print(head);printf("請輸入你

43、要刪除的商品貨號: "); scanf("%d",&a);p=head;while(p->number!=a&&p->next!=NULL)/*刪除時需要兩個變量,保證最后P指向要刪除結(jié)點,P2指向前一個結(jié)點*/ p2=p;p=p->next;if(p->number=a) if(p=head) head=p->next; else p2->next=p->next;printf("n貨號為 %d 的商品信息已成功刪除!nn",a); print(head);printf(&qu

44、ot;n輸入任意鍵返回菜單。");elseprintf("n抱歉!找不到與貨號為 %d 的商品相關(guān)信息。n",a); printf("n輸入任意鍵返回菜單。");return(head);struct goods *add(struct goods *head) /增加 struct goods *p,*p3; printf("nntt請輸入要添加的商品信息:n"); p3=(struct goods *)malloc(L); printf("ntt 請輸入貨號: "); scanf("%d",&p3->number); printf("tt 請輸入名稱: "); scanf("%s",p3->name); printf("tt 請輸入類型: "); scanf("%s",p3-&g

溫馨提示

  • 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

提交評論