超市管理系統(tǒng)、C語言課程設計_第1頁
超市管理系統(tǒng)、C語言課程設計_第2頁
超市管理系統(tǒng)、C語言課程設計_第3頁
超市管理系統(tǒng)、C語言課程設計_第4頁
超市管理系統(tǒng)、C語言課程設計_第5頁
已閱讀5頁,還剩32頁未讀 繼續(xù)免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

1、C 語言程序設計超市管理統(tǒng)目錄第一章 課程設計目的要求1.1 設計目的 31.2 設計要求 31.3 設計思路 3第二章 課程設計任務內容2.1 課程設計題目 32.2 課程設計任務 42.2.1 設計內容 4222 各組員任務4第三章詳細設計說明3.1 系統(tǒng)模塊圖43.2 主要函數(shù)定義553.3 結構體的建立和文件的使用 83.3.1 結構體的建立8第四章 課程設計心得與體會 10附錄程序源代碼參考文獻第一章課程設計目的要求設計“超市管理系統(tǒng)”的主要目的是鍛煉學生綜合運用所學的 C語言程序 設計知識的能力,獨自利用 C語言知識編寫承訓解決實際問題的能力,培養(yǎng)同 學嚴謹?shù)墓ぷ鲬B(tài)度和良好的程序設

2、計習慣,讓同學們認識到必須重視實踐環(huán)節(jié), 多讀程序,多編寫程序,多上機實踐。進一步培養(yǎng)結構化程序設計的思想,加深 對高級語言要素和控制結構的理解。通過課程設計的訓練,學生能夠了解程序設 計的基本開發(fā)過程,掌握編寫、調試和測試C語言程序的基本過程,掌握程序設計的技巧的大體流程。本次程序設計主要側重于知識的運用,把平時學到的運 用到實踐中去。1.1設計目標:1. 熟悉c語言的編譯連接和運行過程。2. 掌握c語言的數(shù)據(jù)類型,熟悉整型、實型、字符型變量的定義方式及 如何給它們賦值。3. 掌握if語句及switch語句的運用方法及嵌套應用方法。4. 掌握實現(xiàn)循環(huán)結構的三種語句 while、do-whil

3、e. 、for的使用。5. 掌握函數(shù)的定義方法和調用方法。6. 能夠采用模塊化思想調試程序。7. 指針和文件的使用,結構體的使用1.2設計要求:1. 源程序要有適當?shù)淖⑨?,使程序容易閱讀。2. 必須用結構體和文件等數(shù)據(jù)結構。3. 程序的運行結果要求使用文件作備份。4. 至少輸出一份報表,鼓勵自行增加新功能。第二章 課程設計任務內容2.1課程設計題目超市管理系統(tǒng)2.2課程設計任務系統(tǒng)為超市管理系統(tǒng),在此系統(tǒng)當中需要用到許多函數(shù),包括系統(tǒng) 函數(shù)以及自定義的函數(shù),在這個系統(tǒng)當中,總共分為五個模塊:管理員登 陸、客戶信息管理、商品管理、購物結算、銷售結算。2.2.1 設計內容本次實習中,主要用到的C語

4、言知識有結構體、指針、文件、數(shù)組。層層鑲嵌的思路將各個模塊要實現(xiàn)的功能環(huán)環(huán)相扣。其中,在管理員登陸后,進入的是主菜單,在這個環(huán)節(jié)當中,我們將菜單設計為函數(shù),并將菜 單函數(shù)放入一個單獨的C文件中管理,實現(xiàn)層層進入功能。主菜單函數(shù)又 分為商品管理、客戶管理、購物結算、銷售結算等函數(shù)的管理,在此當中, 主要采用結構體定義客戶信息,文件訪問等。為保證設計在規(guī)定時間內完成,我們將各模塊分工到個人。確保任務 有質量有效率的同時鍛煉團隊的團結協(xié)作能力。第三章詳細設計說明3.1系統(tǒng)模塊圖(未完)#in elude #in elude“MyParamsH#include“ Mymenu.h”#include“

5、common.h”#include“ CustMan.h”#include“Goodsman.h”二使用了 main() 函數(shù)、 aboutUs() 函數(shù) ,login()函數(shù)和 pcontinue() 函數(shù) void main()char choice=3; / 存儲判斷的選項dosystem(cls); / 清屏命令printf(nn*歡迎進入檸檬 5 超市管理系統(tǒng) *nn);printf(n 請您選擇操作選項: nn);printf(ttt1.登錄 n);printf(ttt2.關于我們 n);printf(ttt3.退出系統(tǒng) n);printf(nn*nn);printf(n 請輸入您

6、的選項 (1,2,3):);choice=getch(); void aboutUs() system(cls);BreakLine;prin tf(tt版權所有型南工學院網(wǎng)絡1101班檸檬 5nn);printf(ttt 檸檬 5專屬,翻版必究nn);printf(tt技術扶持 Tell:);BreakLine;pcontinue(); int login()char upwd8;int i;system(cls);for(i=1;i4;i+)BreakLine;printf( 請輸入您的 8位數(shù)密碼 );scanf(%s,upwd);if(strcmp (upwd,realpassword

7、)=0)return 1;printf( 您好,您的密碼錯誤,請確認后重新輸入 n);printf(您還有d次輸入機會, (3-i);printf(n 系統(tǒng)鄭重提示,您不是合法用戶,強制退出 n);exit(0); 在common.c定義void pcontinue()函數(shù)實現(xiàn)按任意鍵繼續(xù)功能void pcontinue()按任意鍵繼續(xù) n);printf(tgetch();三清屏語句, Do while ,宏定義等的使用 清屏語句: system(cls);使用了 Do While 循環(huán)實現(xiàn)了在進入關于我們部分時可以再次返回登陸界面使用了宏定義。在頭文件 MyParam.h中定義BreakL

8、ine #define BreakLineprintf(nn*nn)使用了 switch 語句進行了選擇并且在語句中使用了多種函數(shù)嵌套使功能完整。switch(choice)case 1:if(login()=1)showMainMenu();break;case 2: aboutUs(); break;case 0: printf(nn系統(tǒng)安全退出 nn);exit(0);break;在輸入密碼部分使用了 For 循環(huán),實現(xiàn)了在登陸三次密碼不正確的情況下強制 退出系統(tǒng):for(i=1;i4;i+)BreakLine;printf( 請輸入您的 8位密碼 :);scanf(%s,upwd);

9、/數(shù)組名代表數(shù)組的首地址,所以不要 &if(strcmp(upwd,realpassword)=0)return(1); /1 表示登錄成功prin tf(n您好,您的密碼錯誤,請確認后重新輸入 n);printf(n您還有第c次輸入機會,(3-i);printf(n系統(tǒng)鄭重提示,您不是合法用戶,強制退出npcontinue();exit(0);void showMainMenu();再在 void showMainMenu(); 其中嵌套void showGoodsMenu();void showCustMenu();void showShopMenu();void showSaleMenu

10、();和銷在這些函數(shù)中也就是商品管理,客戶信息管理,購物結算 , 售結算四大功能模塊。依照前面的嵌套方法一一實現(xiàn)他的功能。 在四大模塊菜單中有void addGoods();void findGoodsAll();void updateGoods();voiddelGoods();voidaddcust();voiddelcust();voidupdatecust();voidfindall();voidsaveAll();voidsaveall();實現(xiàn)了客戶管理中:添加客戶、查詢客戶、刪除客戶、修改客戶、返回上一級 商品管理中:添加商品、查詢商品、刪除商品、修改商品、返回上一級 等部分的功

11、能。在四大模塊菜單中有void showVIP();void Goodseffect();void Goodssave();void Birthdayperson();void showMymenue();void shopping(); 實現(xiàn)了購物結算中:商品交易信息、返回上一級 銷售預算中: 顯示最具有貢獻精神 VIP 客戶排行榜 顯示最具有影響力的商品排行榜 顯示庫存商品量排行榜 當月生日的客戶 以及返回上一級等功能3.3 結構體的建立和文件的使用在實現(xiàn)添加功能時使用了結構體、指針等對現(xiàn)階段我們來說較難理解 的內容。我們會在程序中用到如下結構體語句:Struct date/ 日期int

12、year/ 年 int month/ 月 int day/ 日 Struct cust/ 客戶信息 int no/ 編號 char name20 姓名 char sex/ 性別 int age/ 年齡 struct date birthday/生日double expenditure/ 花費char tel/ 電話號碼Struct goods/ 商品信息nt num/ 商品代碼char name50/ 商品名字int sale/ 商品數(shù)量float price/ 商品單價int lacation/ 商品位置在整個程序中我們會如下用到結構體語句,不同的結構體類型:struct custint n

13、o;char name20;char sex;int age; struct date birthday; double expendituer; char tel20; cust1000;3 3.2 文件的使用客戶信息管理和商品管理都有用到文件,它于我們是重點也是難點 定義文件FILE*fp;int i;if(fp=fopen(cust.dat,wb)=NULL)printf(n 無法打開文件 n);return;for(i=0;itotal;i+) fwrite(&custi,sizeof(struct cust),1,fp);fclose(fp); 定義函數(shù) read_message()

14、 打開文件i nt read_message()FILE*fp;int i=0;/ 記數(shù)/ 打開文件if(fp=fopen(cust.dat,rb)=NULL)printf(n* 暫無任何可讀消息 , 按任意鍵繼續(xù) *n); getch();return 0; / 循環(huán)讀取文件中的每一條記錄 (3)結合循環(huán)語句,關閉文件while(!feof(fp)fread(&custi,sizeof(struct cust), 1, fp);if(custi.no=0)break;else i+;fclose(fp);return i;第四章 程序設計心得與體會 通過為期兩周的課程設計,我們不僅復習了課本

15、上所學知識,還通過查閱 資料、詢問老師同學學到了很多課本上沒有的只是, 從而啟發(fā)我們: 要想寫好程 序,在學好課本只是的同時還需要多閱讀和專業(yè)有關的書記, 同時還需要多動腦 子,要有縝密的邏輯思維能力和綜合應用能力。簡而言之,我們要做到三心:編 寫代碼要細心;檢查錯誤要耐心;完成任務要恒心。除此,在學到知識的同時鍛 煉了我們的團結合作精神,也使得我們小組成員之間有更深的交流。所以,很感謝學校和老師給我們提供這樣一個機會。在鍛煉自己的同時讓 自己養(yǎng)成了良好的學習習慣。我希望自己能一直帶著這份心態(tài)和習慣大步向前。參考文獻1武愛平 卜耀華 孫東衛(wèi) C語言程序設計M.長春:吉林大學出版社。附錄檸檬 5

16、supermarket管理系統(tǒng)源代碼Source Files1. com mon .cvoid pcontinue();void pcontinue()printf(t 按任意鍵繼續(xù) n);getch();2. Main.c#include #include / 字符串 先到系統(tǒng)的庫找,再到用戶庫#include #include #include MyParams.h#include common.h#include mymenu.hvoid aboutUs();int login();char realpassword8=ningmeng; / 系統(tǒng)的真實登錄密碼void main()ch

17、ar choice=3; / 存儲判斷的選項dosystem(cls); / 清屏命令/ 打印出程序歡迎界面printf(nn*歡迎進入檸檬 5超市管理系統(tǒng)*nn);printf(n 請您選擇操作選項: nn);printf(ttt1.登錄 n);printf(ttt2.關于我們n);printf(ttt3.退出系統(tǒng)n);printf(nn*nn); /完成輸入操作printf(n請輸入您的選項(1,2,3):);choice=getch(); /getch()從鍵盤輸入一個字符/ 判斷 switch( 變量) case值 1: xxx; break; default xxx;switch(c

18、hoice)case 1: if(login()=1)showMymenue(); break;case 2: aboutUs();break;case 3: printf(nn系統(tǒng)安全退出 nn);exit(0);break; while(1);void aboutUs()system(cls);BreakLine;prin tf(tt 版權所有型南工學院網(wǎng)絡1101班檸檬 5nn); printf(ttt檸檬 5專屬,翻版必究nn);printf(tt技術扶持 Tell:);BreakLine;pcontinue();int login()char upwd8;int i;system(c

19、ls);for(i=1;i4;i+)BreakLine;printf( 請輸入您的 8位數(shù)密碼 :);scanf(%s,upwd); if(strcmp (upwd,realpassword)=0) return 1;printf( 您好,您的密碼錯誤,請確認后重新輸入 n); printf(您還有d次輸入機會, (3-i);printf(n 系統(tǒng)鄭重提示, 您不是合法用戶, 為系統(tǒng)安全, 強制退出 n); exit(0);3. mymenu.c#include #include #include #include #include mymenu.h#include common.h #inc

20、lude MyParams.h #include CustMan.h#include Goodsman.h void showGoodsmenue(); void showCustmenue(); void showSales(); void showSell();void showMymenue()char choice=5;while(1)system(cls);BreakLine;printf(tt1.商品管理 n);printf(tt2.客戶管理 n);printf(tt3.購物預算 n);printf(tt4.銷售預算 n);printf(tt5.退出系統(tǒng) n);BreakLine;

21、printf(nn 請輸入您的選擇 (1,2,3,4,5):);choice=getch();switch (choice)case1: showGoodsmenue(); break;case2: showCustmenue(); break;case3: showSell(); break;case4: showSales(); break;case5:printf(nn 系統(tǒng)安全退出 nn); exit(0);break;default: printf(n 您的輸入有誤,請檢查后重新輸入 n);pcontinue();void showGoodsmenue()char choice=5;

22、while(1)system(cls);BreakLine;printf(tt1.添加商品 n);printf(tt2.查詢商品 n);printf(tt3.更新商品 n);printf(tt4.刪除商品 n);printf(tt5.返回上一級 n);BreakLine;printf(nn請輸入您的選擇 (1,2,3,4,5):choice=getch();switch (choice)case1: addgoods();break;case2: findgoods();break;case3: updategoods();break;case4: delgoods();break;case5

23、: showMymenue();break;default: printf(n您的輸入有誤,請檢查后重新輸入 n);pcontinue();void showCustmenue()char choice=5;while(1) system(cls); BreakLine;printf(tt1.printf(tt2.添加客戶 n); 查找客戶 n);printf(tt3.printf(tt4. printf(tt5. BreakLine;修改客戶 n); 刪除客戶 n); 返回上一級 n);printf(nn請輸入您的選擇 (1,2,3,4,5):);choice=getch();switch

24、(choice)case1: addcust();break;case2: findall();break;case3: updatecust();break;case4: delcust();break;case5: showMymenue();break;default: printf(n您的輸入有誤,請檢查后重新輸入 n);pcontinue();void showSales()char choice=5;while(1) system(cls);BreakLine;printf(tt1.printf(tt2.printf(tt3.顯示最具有貢獻精神VIP客戶排行榜n); 顯示最具有影響

25、力的商品排行榜 n); 顯示庫存商品量排行榜 n);printf(tt4. printf(tt5. BreakLine;當月生日的客戶 n);返回上一級 n);printf(ntt請輸入您的選擇 (1,2,3,4,5):);choice=getch();switch(choice)case 1: showVIP(); break;case 2: Goodseffect(); break;case 3: Goodssave(); break;case 4: Birthdayperson(); break;case 5: showMymenue(); break;default: printf(n

26、tt您的輸入有誤, 請確認重新輸入 .n);pcontinue();/ 調用按任意鍵繼續(xù)void showSell()char choice=2;while(1)system(cls);BreakLine;printf(tt1.商品交易信息 n);printf(tt2.返回上一級 n);BreakLine;printf(ntt 請輸入您的選擇 (1,2,):); choice=getch();switch(choice)case 1: shopping(); break;case 2: showMymenue(); break;default: printf(ntt您的輸入有誤, 請確認重新輸

27、入 .n);pcontinue(); / 調用按任意鍵繼續(xù)4. Custman.c#include #include #include #include #include MyParams.h#include common.h#include mymenu.h#include CustMan.h read_message();struct dataint year; int month;int day; ; struct custint no; / 編號char name20; /名字double expenditure;/總花費char tel20;/電話號碼struct data birt

28、hday;/生日cust1000; / 最多存 1000 個客戶信息int total; / 現(xiàn)在 cust.dat 文件中總的紀錄條數(shù) void saveAll()FILE*fp;int i;if(fp=fopen(cust.dat,wb)=NULL) printf(n 無法打開文件 n);return; for(i=0;i0)printf(n*顯示所有客戶信息 *n);printf(n 編號 t 姓名 t 消費 tt 電話 tt 生日 );for(i=0;itotal;i+) c=custi;printf(n %dt %st %lft %st %d-%d-%dtn,c.no,,

29、c.expenditure,c.tel,c.birthday);printf(nnnnn);elseprintf(n* 系統(tǒng)中暫無任何客戶信息 *); pcontinue();getch();void updatecust()int i;int toupdateno; /要更新的編號int j;system(cls);total=read_message(); / 讀出信息 printf(n 請輸入您要更新的客戶編號 :); scanf(%d,&toupdateno); / 查找 for(i=0;itotal;i+)if(toupdateno=custi.no)break; /i 里面記錄了要

30、更新的客戶的索引 if(i=total)printf(n 沒有找到要更新的客戶 n); printf( 按任意鍵繼續(xù) n);getch();return;printf(n*請更新用戶信息 *n);printf( 請輸入客戶姓名 :);scanf(%s,); printf( 請輸入客戶消費 :);scanf(%d,&custi.expenditure);printf( 請輸客戶電話 :);scanf(%s,custi.tel);printf( 請輸入客戶的生日 ( 格式: 1999-9-9):);scanf(%d-%d-%d,&custi.birthday.year,&cus

31、ti.birthday.month,&custi.birthday.day);BreakLine;saveAll();printf(n 更新客戶信息成功,按任意鍵繼續(xù) n);getch();void delcust()int i;int todelno;/ 刪除客戶的編號int j;char choice=n; / 記錄是否真正刪除 system(cls);total=read_message();/ 先讀出數(shù)據(jù)printf(n 請輸入您要刪除的客戶的編號 :); scanf(%d, &todelno);for(i=0;itotal;i+)if(todelno=custi.no)break;i

32、f(i=total)printf(n 沒有找到您要刪除的客戶 n); pcontinue();getch();return;(y or n);printf( 親愛的管理員,刪除后無法恢復,您確定要刪除嗎? choice=getch();if (choice=n)printf(n 放棄刪除,返回上一級 n); printf(n 按任意鍵繼續(xù) n);getch();return;/ 真正刪除, 實際上是覆蓋 for(j=i;jtotal;j+)custj=custj+1;total-=1;saveAll();printf(n 刪除客戶數(shù)據(jù)成功 n); printf(n 按任意鍵繼續(xù) n);getc

33、h();5. Goodsman.c#include #include #include #include #include MyParams.h#include common.h#include mymenu.h#include Goodsman.hstruct date int year;int month; int day;J,struct goodsint no; /編碼:char name20; / 名稱:struct date scday; /生產(chǎn)期 struct date:表示結構體類型 date 型scday 變量名 生日 :-struct dateint expenda;/ 原

34、價 :int expendb;/ 單價:int save; /庫存量int sell; /出售量goods100000; / 定義一個全局的結構體數(shù)組 100000 int total;int read_Message()FILE *fp;int i=0;if(fp=fopen(goods.dat,rb)=NULL)printf(n* 暫無任何可讀信息, 按任意鍵繼續(xù) *); getch();return 0;while(feof(fp)!=1) fread(&goodsi,sizeof(struct goods),1,fp); if(goodsi.no=0)break;elsei+; fcl

35、ose(fp);return i;void saveall()FILE*fp;int i; if(fp=fopen(goods.dat,wb)=NULL) printf(n 無法打開文件 n);return; for(i=0;itotal;i+) fwrite(&goodsi,sizeof(struct goods),1,fp); fclose(fp);void addgoods()struct goods newgoods; / 新加入的結構體數(shù)組 char choice=y; / 是否繼續(xù)錄入信息FILE *fp; / int i=0; /i do文件指針,用它指向一個文件是一個計數(shù)器,因

36、為文件中最多存 1000 個數(shù)據(jù)system(cls);printf(n*添加商品信息 *n);printf( 請輸入商品編碼 :);scanf(%d,&newgoods.no); / 取地址因為它是一個基本類型的數(shù)據(jù) BreakLine;printf(請輸入商品名稱 :);scanf(%s,&);BreakLine;printf( 請輸入商品生產(chǎn)期 :( 格式如下 :1999-9-9):); scanf(%d-%d-%d,&,&,&;printf( 請輸入商品原價 :);scanf(%d,&newgoods.expenda);printf( 請輸入商品單價 :);s

37、canf(%d,&newgoods.expendb);printf( 請輸入商品出售量 :);scanf(%d,&newgoods.sell);printf( 請輸入商品庫存量 :);scanf(%d,&newgoods.save);/ 以上完成了輸入客戶信息的操作;/ 將 newcust 結構體中的數(shù)據(jù)保存到一個磁盤文件中if(fp=fopen(goods.dat,ab)=NULL)printf( 無法打開文件 );return; / 如果打得開文件 / 要保存數(shù)據(jù)的地址 這個數(shù)據(jù)類型的長度 幾個數(shù)組文件指針 fwrite(&newgoods, sizeof(struct goods), 1

38、, fp);fclose(fp); / 重新確認是否繼續(xù)錄入 printf(n 還要繼續(xù);錄入商品信息嗎 ?(y/n); choice=getch();while(choice=y);void delgoods()int i,j;int todelno;char choice=n;system(cls);total=read_Message();printf(n 請輸入你要刪除的商品的編碼 :);scanf(%d,&todelno);for(i=0;itotal;i+)if(todelno=goodsi.no)break; / 如果,沒有找到要刪除的商品if(i=total)printf(n沒

39、有找到您想刪除的商品 n);printf(n按任意鍵繼續(xù) n);getch();return;(y/n);printf( 親愛的管理員,刪除后無法恢復,您確定要刪除嗎? choice=getch();if(choice=n)printf(n 放棄刪除,返回上一級 n);printf(n 按任意鍵繼續(xù) n);getch();return;for(j=i;jtotal;j+)goodsj=goodsj+1 ;total-=1;saveall();printf(n 刪除商品數(shù)據(jù)成功 n); pcontinue();getch();void updategoods()int i;int todelno

40、;struct goods gx;char choice=n;system(cls); total=read_Message(); printf(n 請輸入你要更新的商品的編號 :); scanf(%d,&todelno); for(i=0;i0)printf(n* 顯示所有商品信息 *n);printf(n編號t名稱t生產(chǎn)期tt 原價t單價t出售量t庫存量 n);for(i=0;itotal;i+)c=goodsi;printf(n%dt%st%d-%d-%dt%dt%dt%dt%dn,c.no,,c.expenda,c.expendb,c.sell,c.save);BreakL

41、ine;elseprintf(n*系統(tǒng)中暫無任何商品信息 *n);printf(n 按任意鍵繼續(xù) n);getch();6. Save.c#include #include #include Save.h#include common.h#include MyParams.h#include mymenu.hint read_message();int read_Message();struct dataint year;int month;int day;struct custint no;/編號char name20;/名字double expenditure; /總花費char tel20;/電話號碼生日struct data birthday; /cust1000; /int total; /現(xiàn)在 cust.dat 文件中總的紀錄條數(shù)最多存 1000 個客戶信息struct goodsint no;/編碼:char name20;/名稱:struct data scday;/生產(chǎn)期 struct date: 表示結構體類型date 型 scday 變量名生日 :- struct dateint expenda;/原價:int expendb;/單價:int s

溫馨提示

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

評論

0/150

提交評論