課程設(shè)計(jì)說(shuō)明書(shū)zxl_第1頁(yè)
課程設(shè)計(jì)說(shuō)明書(shū)zxl_第2頁(yè)
課程設(shè)計(jì)說(shuō)明書(shū)zxl_第3頁(yè)
課程設(shè)計(jì)說(shuō)明書(shū)zxl_第4頁(yè)
課程設(shè)計(jì)說(shuō)明書(shū)zxl_第5頁(yè)
已閱讀5頁(yè),還剩15頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、中北大學(xué)數(shù)據(jù)結(jié)構(gòu)課 程 設(shè) 計(jì) 說(shuō) 明 書(shū)學(xué)生姓名:張旭亮學(xué) 號(hào):學(xué) 院:電子與計(jì)算機(jī)科學(xué)技術(shù)學(xué)院專 業(yè):軟件工程題 目:宿舍管理查詢系統(tǒng)成績(jī)指導(dǎo)教師周海英 靳雁霞2009 年 6 月 24 日1.設(shè)計(jì)目的數(shù)據(jù)結(jié)構(gòu)課程設(shè)計(jì)的目的是,通過(guò)設(shè)計(jì)掌握數(shù)據(jù)結(jié)構(gòu)課程中學(xué)到的基本理論和算法并綜合運(yùn)用于解決實(shí)際問(wèn)題中,它是理論與實(shí)踐相結(jié)合的重要過(guò)程。設(shè)計(jì)要求學(xué)會(huì)如何對(duì)實(shí)際問(wèn)題定義相關(guān)數(shù)據(jù)結(jié)構(gòu),并采用恰當(dāng)?shù)脑O(shè)計(jì)方法和算法解決問(wèn)題,同時(shí)訓(xùn)練學(xué)生進(jìn)行復(fù)雜程序設(shè)計(jì)的技能和培養(yǎng)良好的程序設(shè)計(jì)習(xí)慣。.2.設(shè)計(jì)內(nèi)容和要求2.1設(shè)計(jì)內(nèi)容: 為宿舍管理人員編寫(xiě)一個(gè)宿舍管理查詢軟件。 要求:1)建立數(shù)據(jù)文件,數(shù)據(jù)文件按關(guān)鍵字(

2、姓名,學(xué)號(hào),房號(hào))進(jìn)行排序(冒泡,選擇,插入排序等任意一種)2)查詢菜單(用二分法實(shí)現(xiàn)以下操作) A按姓名查詢 B按學(xué)號(hào)查詢 C按房號(hào)查詢2.2基本要求:1)系統(tǒng)功能的完善;2)代碼中有必要的注釋。、3概要設(shè)計(jì)1 1)需要定義一個(gè)結(jié)構(gòu)體:typedef struct pnode /結(jié)構(gòu)體定義 用于存放學(xué)生信息的節(jié)點(diǎn) char name 8; /姓名 char xh16; /學(xué)號(hào) char fh30; /房號(hào)personnode;用來(lái)存儲(chǔ)學(xué)生的信息。2)create() /初始條件:必須保證原有記錄是空時(shí)方可建立 操作結(jié)果:建立一個(gè)新的數(shù)據(jù)文件3) readfile() / 初始條件:數(shù)據(jù)文件已

3、經(jīng)建立 操作結(jié)果:獲取次文件的信息 4)serch1()按姓名查找serch2()按學(xué)號(hào)查找serch3()按宿舍號(hào)查找初始條件:數(shù)據(jù)文件中含有紀(jì)錄操作結(jié)果:不支持模糊查詢必須查詢項(xiàng)和關(guān)鍵字吻合情況下才可查詢。調(diào)用按不同關(guān)鍵字查詢的子函數(shù)若存在相應(yīng)的查詢結(jié)果則顯示在屏幕上,若查找的紀(jì)錄不存在則提示該紀(jì)錄不存在,請(qǐng)建立相應(yīng)的數(shù)據(jù)紀(jì)5)insert() /添加數(shù)據(jù)紀(jì)錄的函數(shù)初始條件:必須已經(jīng)建立了數(shù)據(jù)文件操作結(jié)果:在數(shù)據(jù)文件中添加新的紀(jì)錄若沒(méi)有建立數(shù)據(jù)文件則添加失敗。6) delete() /刪除數(shù)據(jù)紀(jì)錄的函數(shù)初始條件:必須建立了數(shù)據(jù)庫(kù)并且數(shù)據(jù)文件中含有數(shù)據(jù)紀(jì)錄操作結(jié)果:刪除輸入學(xué)號(hào)的學(xué)生的一切相

4、關(guān)紀(jì)錄7)updata() /修改數(shù)據(jù)紀(jì)錄的函數(shù)初始條件:必須建立了數(shù)據(jù)庫(kù)并且數(shù)據(jù)文件中含有數(shù)據(jù)紀(jì)錄操作結(jié)果:修改輸入的學(xué)號(hào)相對(duì)應(yīng)的學(xué)生的一切信息。如不存在相應(yīng)的紀(jì)錄則提示不存在8)output() /輸出函數(shù) 初始條件:數(shù)據(jù)文件已經(jīng)建立 操作結(jié)果:起泡法排序 按學(xué)號(hào)順序輸出記錄2本程序包含10個(gè)函數(shù):1. 主函數(shù)main()2. 新建數(shù)據(jù)文件create()3. 查詢函數(shù)serch1()4. 查詢函數(shù)serch2()5. 查詢函數(shù)serch3()6. 加數(shù)據(jù)紀(jì)錄函數(shù)insert()7. 刪除數(shù)據(jù)紀(jì)錄函數(shù)delete() 8. 修改數(shù)據(jù)紀(jì)錄函數(shù)updata()9. 數(shù)據(jù)文件讀取函數(shù)readfi

5、le () 10. 查詢當(dāng)前所有紀(jì)錄冰按學(xué)號(hào)升序輸出的函數(shù)output()各函數(shù)間關(guān)系:利用主函數(shù)調(diào)用其他的各個(gè)函數(shù),新建數(shù)據(jù)文件函數(shù)create()是其它各個(gè)函數(shù)的基礎(chǔ),有了它其它函數(shù)才能夠使用。查詢函數(shù)insert1.2.3()添加數(shù)據(jù)紀(jì)錄函數(shù)insert()刪除數(shù)據(jù)紀(jì)錄函數(shù)delete ()修改數(shù)據(jù)紀(jì)錄函數(shù)updata ()這些函數(shù)都是在同一等級(jí)上的函數(shù),是平行關(guān)系。查詢當(dāng)前所有紀(jì)錄的函數(shù)output()以學(xué)號(hào)為關(guān)鍵字查詢函數(shù)serch1()以姓名為關(guān)鍵字查詢函數(shù)serch2()以床號(hào)為關(guān)鍵字查詢函數(shù)serch3()以宿舍號(hào))這些函數(shù)都是查詢函數(shù)中的子函數(shù),他們之間是平行的關(guān)系。4功能模

6、塊詳細(xì)設(shè)計(jì)1. 主函數(shù)main() 通過(guò)swich分支 構(gòu)建圖形用戶界面 一次調(diào)用其他模塊完成總體功能;2新建數(shù)據(jù)文件create() 2.1為節(jié)點(diǎn)分配內(nèi)存 2.2創(chuàng)建二進(jìn)制文件用于存儲(chǔ)學(xué)生信息 2.3通過(guò)一個(gè)循環(huán) 一次錄入學(xué)生信息2.4關(guān)閉文件3. 查詢函數(shù)serch1() 3.1 打開(kāi)文件 3.2遍歷整個(gè)文件找到與指定姓名匹配的信息 3.3輸出查詢到的信息 3.4關(guān)閉文件4. 查詢函數(shù)serch2() 4.1打開(kāi)文件 4.2遍歷整個(gè)文件找到與制定學(xué)號(hào)匹配的信息 4.3輸出查詢到的信息 5.4關(guān)閉文件5. 查詢函數(shù)serch3() 5.1打開(kāi)文件 5.2遍歷整個(gè)文件找到與制定床號(hào)匹配的信息

7、5.3輸出查詢到的信息 5.4關(guān)閉文件6.加數(shù)據(jù)紀(jì)錄函數(shù)insert() 6.1打開(kāi)文件 6.2將制定記錄插入到文件的末尾 6.3關(guān)閉文件7.刪除數(shù)據(jù)紀(jì)錄函數(shù)delete() 7.1打開(kāi)文件 7.2遍歷文件找到與制定姓名匹配的記錄 并刪除 7.3關(guān)閉文件8. 修改數(shù)據(jù)紀(jì)錄函數(shù)updata() 8.1打開(kāi)文件 8.2遍歷整個(gè)文件找到與制定姓名匹配的記錄并修改 8.3關(guān)閉文件9. 數(shù)據(jù)文件讀取函數(shù)readfile () 9.1打開(kāi)文件 9.2讀取文件 9.3關(guān)閉文件10.查詢當(dāng)前所有紀(jì)錄冰按學(xué)號(hào)升序輸出的函數(shù)output() 10.1打開(kāi)文件 10.2遍歷文件(嵌套遍歷) 依次比較學(xué)號(hào)大小 用起泡

8、法進(jìn)行排序 10.3遍歷文件 依次輸出文件中的記錄4.1 詳細(xì)設(shè)計(jì)思想 采用模塊化編程思想,將程序劃分為11個(gè)模塊,在逐個(gè)模塊細(xì)化編程,最后再將個(gè)個(gè)模塊組裝成軟件。.4.2 源代碼#include#include#includetypedef struct pnode /結(jié)構(gòu)體定義 用于存放學(xué)生信息的節(jié)點(diǎn) char name 8; /姓名 char xh16; /學(xué)號(hào) char fh30; /房號(hào)personnode;char filename20; /文件名FILE *fp; /指向文件的指針void creat() /創(chuàng)建新數(shù)據(jù)文件的函數(shù) 創(chuàng)建一個(gè)二進(jìn)制文件 用于存放學(xué)生數(shù)據(jù) person

9、node *person; person=(personnode *)malloc(sizeof(personnode); /為節(jié)點(diǎn)分配內(nèi)存 printf(n please enter the filename:n); scanf(%s,filename); if(fp=fopen(filename,w+)=NULL) printf(n you have no enter the filename,can not font the file); exit(0); printf(n please enter the name,studentnumbeer (the same length) an

10、d roomnumber,spare with space,endwith #n); scanf(%s,person-name); while(strcmp(person-name,#) /該循環(huán)用于控制 學(xué)生信息的錄入 當(dāng)輸入#時(shí) 學(xué)生信息錄入完畢 scanf(%s %s,person-xh,person-fh); fprintf(fp,%-10s%-20s%-50sn,person-name,person-xh,person-fh); scanf(%s,person-name); fclose(fp);void readfile() /文件讀取函數(shù) 用于打開(kāi)已有的二進(jìn)制數(shù)據(jù)文件printf

11、(n please enter the fileroad:n); scanf(%s,filename); /此處輸入為文件的路徑 如c:zhang if(fp=fopen(filename,r+)=NULL) printf(n cant open thefile:n); exit(0); fclose(fp);void output() /輸出函數(shù) 用于輸出文件的全部信息 personnode *person; long offset1,offset2; char name18,name28,name38; char xh116,xh216,xh316; char fh130,fh230,fh

12、330;person=(personnode *)malloc(sizeof(personnode); if(fp=fopen(filename,r)=NULL) printf(n cant open the file); exit(0); while(!feof(fp) /此循環(huán)用于 對(duì)文件數(shù)據(jù)中關(guān)鍵字學(xué)號(hào)進(jìn)行從小到大冒泡排序 int a,b,c,d; /a為循環(huán)結(jié)束判定變量 b,c,d用于起泡排序時(shí)學(xué)號(hào)交換的替換 if(fp=fopen(filename,r+)=NULL) printf(n cant open the file); exit(0); while(!feof(fp) / 從

13、文件頭開(kāi)始遍歷 while(!feof(fp) /對(duì)兩組數(shù)據(jù)進(jìn)行排序 offset1=ftell(fp); /獲取文件內(nèi)部當(dāng)前指針位置 fscanf(fp,%s%s%sn,person-name,person-xh,person-fh); strcpy(name1,person-name); strcpy (xh1,person-xh); strcpy(fh1,person-fh); if(feof(fp) break; /文件結(jié)束 跳出循環(huán) offset2=ftell(fp); /獲取文件內(nèi)部下一指針位置 fscanf(fp,%s%s%sn,person-name,person-xh,per

14、son-fh); strcpy (name2,person-name); strcpy(xh2,person-xh); strcpy(fh2,person-fh); b=strlen(xh1); c=strlen(xh2); d=strcmp(xh1,xh2); if(b=c&d0) /如果 學(xué)號(hào)1大于等于學(xué)號(hào)2 怎交換全部數(shù)據(jù) strcpy(name3,name1); strcpy(name1,name2); strcpy(name2,name3); strcpy(xh3,xh1); strcpy(xh1,xh2); strcpy(xh2,xh3); strcpy(fh3,fh1); str

15、cpy(fh1,fh2); strcpy(fh2,fh3); fseek(fp,offset1,SEEK_SET); /將文件指針移動(dòng)offset1個(gè)字節(jié) strcpy(person-name,name1); strcpy(person-xh,xh1); strcpy(person-fh,fh1); fprintf(fp,%-10s%-20s%-50sn,person-name,person-xh,person-fh);/排序后寫(xiě)入文件 strcpy(person-name,name2); strcpy(person-xh,xh2); strcpy( person-fh,fh2); fprin

16、tf(fp,%-10s%-20s%-50sn,person-name,person-xh,person-fh);/排序后寫(xiě)入文件 fseek(fp,offset2,SEEK_SET); /將文件位置指針從文件頭向前移動(dòng)offset2個(gè)字節(jié) rewind(fp); /指向頭文件 while(!feof(fp) /此循環(huán)用于判斷學(xué)號(hào)是否有序 offset1=ftell(fp); fscanf(fp,%s%s%sn,person-name,person-xh,person-fh); strcpy (xh1,person-xh); if(feof(fp) a=1; break; offset2=fte

17、ll(fp); fscanf(fp,%s%s%sn,person-name,person-xh,person-fh); strcpy(xh2,person-xh); b=strlen(xh1); c=strlen(xh2); d=strcmp(xh1,xh2); if(b=c&dname,person-xh,person-fh); printf(%-10s%-20s%-50sn,person-name,person-xh,person-fh); fclose(fp); printf(*nn);void search1() / 按姓名搜索函數(shù) int k=0; char namekey8; pe

18、rsonnode *person; person=(personnode *)malloc(sizeof(personnode); printf(n please enter the namehead you need :); scanf(%s,namekey); if(fp=fopen(filename,rb)=NULL) printf(n cant open thefile); exit(0); while(!feof(fp) fscanf(fp,%s %s %sn,person-name,person-xh,person-fh); if(!strcmp(namekey,person-na

19、me) /比較是否相同 相同則輸出結(jié)果 否則輸出未找到記錄 printf(nn have serched,the courrent is:); printf(%-10s%-20s%-50sn,person-name,person-xh,person-fh); k=1; if(!k) printf(nn sorry,there is not the current of thiss people n); fclose(fp);void search2() /按學(xué)號(hào)搜索函數(shù) int k=0; char xhkey16; personnode *person; person=(personnode

20、*)malloc(sizeof(personnode); printf(n please enter the roomnumber you want to serch:); scanf(%s,xhkey); if(fp=fopen(filename,rb)=NULL) printf(n cant open the file ); exit(0); while(!feof(fp) fscanf(fp,%s %s %sn,person-name,person-xh,person-fh); if(!strcmp(xhkey,person-xh) /比較是否相同 相同則輸出結(jié)果 否則輸出未找到記錄 p

21、rintf(nn have got it,the current is:); printf(%-10s%-20s%-50sn,person-name,person-xh,person-fh); k=1; if(!k) printf(nn sorry,there is not the current of thiss people n); fclose(fp);void search3() /按房號(hào)搜索函數(shù) int k=0; char fhkey30; personnode *person; person=(personnode *)malloc(sizeof(personnode); prin

22、tf(n please enter the roomnumber you want to serch:); scanf(%s,fhkey); if(fp=fopen(filename,rb)=NULL) printf(n cant open thefile); exit(0); while(!feof(fp) fscanf(fp,%s %s %sn,person-name,person-xh,person-fh); if(!strcmp(fhkey,person-fh) /比較是否相同 相同則輸出結(jié)果 否則輸出未找到記錄 printf(nn have got it,the current is

23、:); printf(%-10s%-20s%-50sn,person-name,person-xh,person-fh); k=1; if(!k) printf(nn sorry,there is not the current of thiss peoplen); fclose(fp);void append() /插入函數(shù) 用于像已有文件插入一條新的學(xué)生信息記錄 personnode *person; person=(personnode *)malloc(sizeof(personnode); if(fp=fopen(filename,a)=NULL) printf(n cant ope

24、n the file); exit(0); printf(n please enter the name,studentnumber and roomnumber n); scanf(%s %s %s,person-name,person-xh,person-fh); fprintf(fp,%-10s%-20s%-50sn,person-name,person-xh,person-fh); fclose(fp);void modify() /更新函數(shù) 用于修改指定學(xué)生姓名的記錄 int k=0; long offset; char namekey8; personnode *person; p

25、erson=(personnode *)malloc(sizeof(personnode); printf(n please enter the studentname you want to updata :); scanf(%s,namekey); if(fp=fopen(filename,r+)=NULL) printf(n cant open thefile); exit(0); while(!feof(fp) offset=ftell(fp); fscanf(fp,%s %s %sn,person-name,person-xh,person-fh); if(!strcmp(namek

26、ey,person-name) /比較是否相同 如 k=1; break; if(k) /相同 輸出記錄并進(jìn)行修改 printf(n hava got it,the current is:); printf(%-10s%-20s%-50sn,person-name,person-xh,person-fh); printf(n please enter the new studentname,studentnumber and roomnumber :); scanf(%s %s %s,person-name,person-xh,person-fh); fseek(fp,offset,SEEK_

27、SET); fprintf(fp,%-10s%-20s%-50sn,person-name,person-xh,person-fh); else printf(n sorry,there is not the current of this people n); fclose(fp);void deleted() /刪除函數(shù) 用于刪除指定學(xué)生姓名的記錄 int k=0; char m; long offset; char namekey8; personnode *person; person=(personnode *)malloc(sizeof(personnode); printf(n

28、please enter the name you want to delete :); scanf(%s,namekey); if(fp=fopen(filename,r+)=NULL) printf(n cant open the file ); exit(0); while(!feof(fp) /此循環(huán)遍歷整個(gè)文件 查找需要?jiǎng)h除的記錄 offset=ftell(fp); fscanf(fp,%s%s%sn,person-name,person-xh,person-fh); if(!strcmp(namekey,person-name) k=1; break; if(k) printf(n

29、 hava got it,the current is:); printf(%-10s%-20s%-50sn,person-name,person-xh,person-fh); printf(n are you sure to delete it?y/n?); scanf(%s,&m); if(m=y) /刪除確認(rèn)按鈕 fseek(fp,offset,SEEK_SET); /刪除記錄 fprintf(fp,%-10s%-20s%-50sn,); else rewind(fp); else printf(n sorry,there is not the current of this peopl

30、e n); fclose(fp);void main() /主函數(shù) int m,flag=1; / m用于控制菜單的選擇項(xiàng) flag用于控制菜單彈出 while(flag) printf(%33sn,thefile); printf(-n); printf(tt0-creat a new datafilen); printf(tt1-read the oldfilen); printf(tt2- serch as namen); printf(tt3- serch as studentnumbern); printf(tt4- serch as roomnumbern); printf(tt5-updatan); printf(tt6-deleten); printf(tt7-insertn); printf(tt8-printfn); printf(tt9-exitn); printf(-n); printf(t please choice(0-9)n); scanf(%d,&m); switch(m) case 0:creat(); break; case 1

溫馨提示

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

評(píng)論

0/150

提交評(píng)論