C語言 雜志訂閱管理軟件_第1頁
C語言 雜志訂閱管理軟件_第2頁
C語言 雜志訂閱管理軟件_第3頁
C語言 雜志訂閱管理軟件_第4頁
C語言 雜志訂閱管理軟件_第5頁
已閱讀5頁,還剩17頁未讀 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、C語言程序設計上機實習報告學院:班級:姓名:學號:指導老師:資源學院021094柴杉20091001131趙曼刖言我們學習C語言課程設計的主要目的是為了了解和熟悉C語言的編程。學習C語言要 經(jīng)過一個“理論f實踐f在理論f在實踐,的過程。而學習C語言課程設計就是要我們進 行實踐,從中發(fā)現(xiàn)問題,解決問題,提高我們運用C語言的能力。是我們能夠運用C語言 解決一些問題。通過不斷的編程,熟能生巧,是我們的理論學習也有了實踐基礎,學習理論 知識就較為容易一些,然后再通過實踐不斷的提高,如此良性循環(huán)就能是我們的C語言編 程能力更上一成樓。正文一、題目要求雜志訂閱管理軟件要求使用計算機對一種雜志的訂閱進行管理

2、,該雜志擁有的最多訂戶不超過10人,每個訂戶 的信息包括:姓名,性別,地址,電話號碼,雜志單價,訂閱數(shù),訂閱的期限(至XX年XX月).現(xiàn)在要求用菜單選擇并完成下述的功能:增加新訂戶,即將訂戶的全部信息輸入到文件中;根據(jù)當天的日期對訂戶文件進行查詢,刪除已經(jīng)到期的訂戶記錄;統(tǒng)計本期雜志的訂戶數(shù)并打印運算結果;本期訂戶信息表:訂戶名訂閱數(shù)單價金額李平25.511.0黃海15.55.5合計31.016.5二、需求分析根據(jù)題目要求,由于訂戶信息放在文件中,所以應提供文件的輸入,輸出,刪除等操作; 在程序中需要瀏覽訂戶的信息,應提供顯示、查找等操作;另外還應提供鍵盤式選擇菜單實 現(xiàn)功能等。三、總體設計根

3、據(jù)上面的需求分析,可以將這個系統(tǒng)的設計分為四大模塊:添加、查詢、統(tǒng)計、退出。其中主要功能是添加、查詢、統(tǒng)計三個模塊。四、詳細設計1、主函數(shù)主函數(shù)只提供輸入、處理和輸出部分的函數(shù)調(diào)用。其中各功能模塊用菜單方式選擇。其【程序】void menu() /* 主界面 */int w,n; /疫量n保存選擇菜單數(shù)字,w判斷輸入的數(shù)字是否在功能菜單對應數(shù)字范圍內(nèi)*/ doclrscr();printf(n);printf(tt* * * * * * * * * * * * * * * * * * * * * * * * *n); TOC o 1-5 h z printf(ttn);printf(ttn);

4、printf(tt Welcome to the magazine order system !n);printf(ttn);printf(ttn);*1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* 個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個

5、nn;.1:add_new_subscribern);2:browsen);3:statisticn);4:exitnn);printf(tt* * * * * * * * * * * * * * * * * * * * * * * * *n); printf(nntt printf(tt printf(tt printf(tt printf(tt printf(tt *nn);printf( Choice your number(1-4): bb);scanf(%d”,&n);if(n4) /*對選擇的數(shù)字作判斷*/w=1;else w=0;while (w=1);/*選擇功能*/switc

6、h(n)case 1:add();break;/*增加新訂戶記錄 */case 2:search();break;/*查找過期的訂戶記錄并刪除*/case 3:statistic();break;/*統(tǒng)計*/case 4:exit();break;/*退 出*/*主 函數(shù) */main()FILE *fp;fp=fopen(record.txt,w);/*建 立一個record.txt記事本 */ fclose(fp);menu();2、各功能模塊設計(1)添加模塊【需求分析】該模塊的功能是需要增加新的訂戶的記錄,從鍵盤輸入并逐條寫到原來的文件中,添加【程序】/*添 加模塊 */void ad

7、d()int t,i,m;clrscr();t=load_record();printf(How many groups information do you want to add?n); printf(Enter the number: bbb);scanf(d,&m); /*輸入要添加的記錄個數(shù)*/for(i=0;im;i+)printf(nInput %dth subscriber record.n,i+1);input(t+i);/*調(diào)用輸入函數(shù)*/save(t+m);/*調(diào)用保存函數(shù) 保存t+m組數(shù)據(jù)*/clrscr();/*清屏*/menu();/*返回登陸界面*/void in

8、put(int i)printf(Please input:nName sex address phone_number unit_price amount time_limit n);scanf(s%s%s%s%s%s%s,&,&orderi.sex,&orderi.address,&orderi.phone_number,&orderi.unit_price,&orderi.amount,&orderi.time_limit); (2)查詢模塊【需求分析】該模塊的功能是根據(jù)目前的日期對訂戶文件進行查詢,刪除已到期的訂戶記錄?!境绦颉?* 查詢模塊 */void sea

9、rch()FILE *fp;char date11,str2;int t,i,sum=0;t=load_record();printf(Please input the current date:bbbbbbbbbbb);scanf(s,date);printf(n);if(fp=fopen(record.txt,w)=NULL)/* 以只寫方式打開*/printf(nCannot open filen);exit(0);printf(n);for(i=0;it;i+)if(strcmp(orderi.time_limit,date)0)sum+;printf(n);printf_one(i)

10、;/*把符合條件的記錄顯示出來個個個個個個個個個個個個個個個個個個個個個個個個/printf(nnThe record is out of date!);printf(nnDo you want to delete its information?(YorN): bb);scanf(%s,str);if(strcmp(str,Y)=0|strcmp(str,y)=0)continue;fwrite(&orderi,sizeof(struct magazine),1,fp);fclose(fp);if(sum=0)printf(*nn);printf(Sorry! Cannot find the

11、 equipment which you want to.nn);printf(*nn);printf(nnnPress any key to go back the former step.n);getchar();menu();(3)統(tǒng)計模塊【需求分析】該模塊的功能是統(tǒng)計所有訂戶的資料并顯示結果。【程序】/* 統(tǒng) 計模塊 */void statistic()int t;t=load_record();printf(The amount of subscriber is%dbbb”,t);printf_n(t);printf(nnnPress any key to go back.nn);g

12、etchar();menu();void printf_one(int i)/*顯示一個儀器記錄的函數(shù)*/ printf(%-10s %-5s %-10s %-11s%-4s%-3s %-10snn”,,orderi.sex,orderi.addr,orderi.phone_number,orderi.unit_price,orderi.a mount,&orderi.time_limit);void printf_n(int n)/*顯示n個儀器記錄的函數(shù)*/ int j;printf(Namesex addressphone_number price amountti

13、me_limitnn);for(j=0;jn;j+)if(j+1)%10=0)/*控制顯示,每屏顯示10行*/printf(nnPress any key to continue .”);getchar();puts(nn);printf_one(j);/*調(diào)用顯示一個儀器記錄的函數(shù)*/3、公共函數(shù)/* 公共函數(shù) */int load_record()/*加載儀器信息并計算記錄儀器個數(shù)的函數(shù)*/ FILE *fp;int i;if(fp=fopen(record.txt”,r)=NULL)/* 以只讀方式打開*/printf(nCannot open filen);exit(0);for(i=

14、0;!feof(fp);i+)/*從文件中讀入數(shù)據(jù)并保存在結構體數(shù)組中*/ fread(&orderi,sizeof(struct magazine),1,fp);fclose(fp);return(i-1);void save(int n)/*n表示保存n組數(shù)據(jù),m表示保存在哪個文件夾里*/FILE *fp;int i;fp=fopen(record.txt”,w);/* 以只寫方式打開*/if(fp=NULL)printf(nCannot open filen);exit(0);for(i=0;in;i+)fwrite(&orderi,sizeof(struct magazine),1,f

15、p);fclose(fp);五、上機操作運行結果下面是各個模塊的界面圖:1、主菜單函數(shù)2、添加模塊在主界面出現(xiàn)后輸入1并按【enter】鍵,結果如圖。輸入要輸入的記錄數(shù)然后逐條增加,如圖所示。3、查詢模塊4、統(tǒng)計模塊六、總結在老師的帶領下進行了 C語言程序?qū)嵺`學習。在短短一周的實習期間使我獲取了不少新 知識也鞏固了許多老知識。C語言是需要有一定基礎、而且動手能力強的學科。上機實驗是學習程序設計語言必不 可少的實踐環(huán)節(jié),特別是C語言靈活、簡潔,更需要通過編程的實踐來真正掌握它。對于程 序設計語言的學習目的,可以概括為學習語法規(guī)定、鞏固貫穿系統(tǒng)知識、掌握程序設計方法、 提高程序設計能力。通過多次上

16、機練習,對于語法知識有了感性的認識,加深對它的理解,在理解的基礎上 就會自然而然地掌握C語言的語法規(guī)定。對于一些內(nèi)容自己認為在課堂上聽懂了,但上機實 踐中會發(fā)現(xiàn)原來理解的偏差,更加鞏固了學過的知識。這次上機實習讓我學到了很多有用的東西,鞏固了之前的學習,讓我學到了在教室和做 題中學不到的一些知識,通過這個程序的學習,使我進一步理解和運用結構化程序設計的思 想和方法。初步掌握開發(fā)一個小型實用系統(tǒng)的基本方法,學會調(diào)試一個比較長程序的基本方 法,學會利用流程圖表示算法,進一步掌握和提高利用C語言進行程序設計的能力。我認為這次實習對我而言是非常有意義的,使我的動手能力有了很大的提高。七.源程序#inc

17、lude#include#define max 20struct magazinechar name11;char sex8;char addr11;char phone_number12;char unit_price5;char amount4;char time_limit11;ordermax;void save(int n);int load_record();void search();void printf_n(int n);void printf_one(int i);void input(int i);void statistic();void add();void menu

18、();void exit();main()FILE *fp;fp=fopen(record.txt,w);/*建 立一個record.txt”記事本 */ fclose(fp);menu();void menu()int w,n;doprintf(n);printf(tt* * * * * * * * * * * * * * * * * * * * * * * * *n); TOC o 1-5 h z printf(ttn);printf(ttn);printf(tt Welcome to the magazine order system !n);printf(ttn);printf(ttn

19、); printf(tt* * * * * * * * * * * * * * * * * * * * * * * * *n);printf(nntt*nn;printf(tt1:add_new_subscribern);printf(tt2:browsen);printf(tt3:statisticn);printf(tt4:exitnn);printf(tt*1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1

20、* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* *1* nn;printf( Choice your number(1-4): bb);scanf(%d”,&n);if(n4) w=1;else w=0;while (w=1);/* 選擇功能 */switch(n)case 1:add();break;/*增加新訂戶記錄 */case 2:search();break;/*查找過期的訂戶記錄并刪除*/case 3:statistic();break;/*統(tǒng)計*/case 4:exit();break;/*退 出*/ /、天*/

21、 個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個/void add() int t,i,m;t=load_record();printf(How many groups information do you want to add?n);printf(Enter the number: bbb);scanf(%d”,&m);for(i=0;im;i+)printf(nInput %dth subscriber record.n”,i+1);input(t+i);/*調(diào)用輸入函數(shù)*/save(t+m);/*調(diào)用保存函數(shù) 保存t+m組數(shù)據(jù)*/

22、menu();/*返回登陸界面*/void input(int i)printf(Please input:nName sex address phone_number unit_price amount time_limit n);scanf(%s%s%s%s%s%s%s”,&,&orderi.sex,&orderi.addr,&orderi.ph one_number,&orderi.unit_price,&orderi.amount,&orderi.time_limit);/* 統(tǒng) 計 模 塊/ * void t;t=load_recor

23、d();printf(The amount of subscriber is%dbbb”,t);printf_n(t);printf(nnnPress any key to go back.nn);getchar();menu();void printf_one(int i)/*顯示一個儀器記錄的函數(shù)*/printf(%-10s %-5s%-10s%-11s%-4s%-3s %-10snn”,,orderi.sex,orderi.addr,orderi.phone_number,orderi.unit_price,orderi.am ount,orderi.time_li

24、mit);void printf_n(int n)/*顯示n個儀器記錄的函數(shù)*/int j;printf(Namesex addressphone_number price amounttime_limitnn);for(j=0;jn;j+)if(j+1)%10=0)/*控制顯示,每屏顯示10行*/printf(nnPress any key to continue .”);getchar();puts(nn);printf_one(j);/*調(diào)用顯示一個儀器記錄的函數(shù)*/*查詢模塊/ 個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個個/void sear

25、ch()FILE *fp;char date11,str2;int t,i,sum=0;t=load_record();printf(Please input the current date:bbbbbbbbbbb);scanf(%s”,date);printf(n);if(fp=fopen(record.txt”,w)=NULL)/* 以只寫方式打開*/printf(nCannot open filen);exit(0);printf(n);for(i=0;it;i+)if(strcmp(orderi.time_limit,date)0)sum+;printf(n);printf_one(i);/*把符合條件的記錄顯示出來/*printf(nnThe record is out of date!);pri

溫馨提示

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

評論

0/150

提交評論