1課程設(shè)計(jì) 題目十_第1頁
1課程設(shè)計(jì) 題目十_第2頁
1課程設(shè)計(jì) 題目十_第3頁
1課程設(shè)計(jì) 題目十_第4頁
1課程設(shè)計(jì) 題目十_第5頁
已閱讀5頁,還剩11頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

學(xué)生宿舍管理系統(tǒng)一設(shè)計(jì)內(nèi)容及要求:為宿舍管理人員編寫一個(gè)宿舍管理查詢軟件。要求:1)建立數(shù)據(jù)文件,數(shù)據(jù)文件按關(guān)鍵字(姓名,學(xué)號(hào),房號(hào))進(jìn)行排序(冒泡,選擇,插入排序等任意一種)2)查詢菜單(用二分法實(shí)現(xiàn)以下操作)按姓名查詢按學(xué)號(hào)查詢按房號(hào)查詢二概要設(shè)計(jì)1)需要定義一個(gè)結(jié)構(gòu)體:typedefstructpnode/*結(jié)構(gòu)體定義用于存放學(xué)生信息的節(jié)點(diǎn)*/用來存儲(chǔ)學(xué)生的信息。2)create()/*初始條件:必須保證原有記錄是空時(shí)方可建立*/操作結(jié)果:建立一個(gè)新的數(shù)據(jù)文件3)readfile()/*初始條件:數(shù)據(jù)文件已經(jīng)建立*/操作結(jié)果:獲取次文件的信息serchl()按姓名查找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ì)insert()/*添加數(shù)據(jù)紀(jì)錄的函數(shù)*/初始條件:必須已經(jīng)建立了數(shù)據(jù)文件操作結(jié)果:在數(shù)據(jù)文件中添加新的紀(jì)錄若沒有建立數(shù)據(jù)文件則添加失敗。delete()/*刪除數(shù)據(jù)紀(jì)錄的函數(shù)*/初始條件:必須建立了數(shù)據(jù)庫并且數(shù)據(jù)文件中含有數(shù)據(jù)紀(jì)錄操作結(jié)果:刪除輸入學(xué)號(hào)的學(xué)生的一切相關(guān)紀(jì)錄updata()/*修改數(shù)據(jù)紀(jì)錄的函數(shù)*/初始條件:必須建立了數(shù)據(jù)庫并且數(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()查詢函數(shù)serch1()查詢函數(shù)serch2()查詢函數(shù)serch3()6. 加數(shù)據(jù)紀(jì)錄函數(shù)insert()7. 刪除數(shù)據(jù)紀(jì)錄函數(shù)delete()8. 修改數(shù)據(jù)紀(jì)錄函數(shù)updata()數(shù)據(jù)文件讀取函數(shù)readfile()查詢當(dāng)前所有紀(jì)錄冰按學(xué)號(hào)升序輸出的函數(shù)output()三設(shè)計(jì)思想:采用模塊化編程思想,將程序劃分為11個(gè)模塊,在逐個(gè)模塊細(xì)化編程,最后再將個(gè)個(gè)模塊組裝成軟件。四測(cè)試測(cè)試結(jié)果及數(shù)據(jù)如下:數(shù)據(jù)數(shù)據(jù)的數(shù)號(hào)個(gè)前名號(hào)室一以姓星建取除改岀岀創(chuàng)讀查查查更刪修輸退pleasechoice<0 9>請(qǐng)輸入thefilename:請(qǐng)輸入姓名,學(xué)號(hào)<thesamelength>)寢室號(hào),剩余空|可“n血ithttli023023肚022022Lcie021021pleasechoice<0021021pleasechoice<0hauagotit,thecurrentis:li023021021pleasechoice<0hauagotit,thecurrentis:li023023請(qǐng)輸入你想要查找的寢室號(hào):021有該信息,該信息是:xiepleaseenterthenameyouuanttodelete:liareyousuretodeleteit?y/n?ypleaseclioice<0請(qǐng)輸入姓名,學(xué)號(hào)和寢室號(hào)hanq020020 五程序源代碼如下:#include<stdio.h>#include<stdlib.h>#include<string.h>typedefstructpnode{charname[8];charxh[16];charfh[30];}personnode;charfilename[20];FILE*fp;voidcreat(){personnode*person;person=(personnode*)malloc(sizeof(personnode));printf("\n請(qǐng)輸入thefilename:\n");scanf("%s",filename);if((fp=fopen(filename,"w+"))==NULL){printf("\n你還沒有輸入,不能建立檔案");exit(0);}printf("\n請(qǐng)輸入姓名,學(xué)號(hào)(thesamelength),寢室號(hào),剩余空間,endwith#\n");scanf("%s",person->name);while(strcmp(person->name,"#")){scanf("%s%s",person->xh,person->fh);fprintf(fp,"%-10s%-20s%-50s\n",person->name,person->xh,person->fh);scanf("%s",person->name);}fclose(fp);}voidreadfile(){printf("\npleaseenterthefileroad:\n");scanf("%s",filename);if((fp=fopen(filename,"r+"))==NULL){printf("\ncan'topenthefile:\n");exit(0);}fclose(fp);voidoutput(){personnode*person;longoffset1,offset2;charname1[8],name2[8],name3[8];charxh1[16],xh2[16],xh3[16];charfh1[30],fh2[30],fh3[30];person=(personnode*)malloc(sizeof(personnode));if((fp=fopen(filename,"r"))==NULL){printf("\ncan'topenthefile");exit(0);}while(!feof(fp)){inta,b,c,d;if((fp=fopen(filename,"r+"))==NULL){printf("\ncan'topenthefile");exit(0);}while(!feof(fp)){while(!feof(fp)){offset1=ftell(fp);fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);strcpy(name1,person->name);strcpy(xh1,person->xh);strcpy(fh1,person->fh);if(feof(fp))break;offset2=ftell(fp);fscanf(fp,"%s%s%s\n",person->name,person->xh,person->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&&d>0)strcpy(name3,name1);strcpy(name1,name2);strcpy(name2,name3);strcpy(xh3,xh1);strcpy(xh1,xh2);strcpy(xh2,xh3);strcpy(fh3,fh1);strcpy(fh1,fh2);strcpy(fh2,fh3);fseek(fp,offset1,SEEK_SET);strcpy(person->name,name1);strcpy(person->xh,xh1);strcpy(person->fh,fh1);fprintf(fp,"%-10s%-20s%-50s\n",person->name,person->xh,person->fh);strcpy(person->name,name2);strcpy(person->xh,xh2);strcpy(person->fh,fh2);fprintf(fp,"%-10s%-20s%-50s\n",person->name,person->xh,person->fh);}fseek(fp,offset2,SEEK_SET);}rewind(fp);while(!feof(fp)){offset1=ftell(fp);fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);strcpy(xh1,person->xh);if(feof(fp)){a=1;break;}offset2=ftell(fp);fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);strcpy(xh2,person->xh);b=strlen(xh1);c=strlen(xh2);d=strcmp(xh1,xh2);if(b==c&&d<=0)a=1;else{a=0;break;}fseek(fp,offset2,SEEK_SET);if(a)break;rewind(fp);}if(a)break;}rewind(fp);printf("%35s\n","thefile(thefilehavaprintfasstudentnumber)");printf("%-10s%-20s%-50s\n","name","studentnumber","roomnumber");while(!feof(fp)){fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);printf("%-10s%-20s%-50s\n",person->name,person->xh,person->fh);}fclose(fp);printf(*\n\n");printf(voidsearch1(){intk=0;charnamekey[8];personnode*person;person=(personnode*)malloc(sizeof(personnode));printf("\npleaseenterthenameheadyouneed:");scanf("%s",namekey);if((fp=fopen(filename,"rb"))==NULL){printf("\ncan'topenthefile");exit(0);}while(!feof(fp)){fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);if(!strcmp(namekey,person->name)){printf("\n\nhaveserched,thecourrentis:");printf("%-10s%-20s%-50s\n",person->name,person->xh,person->fh);k=1;}}if(!k)printf("\n\nsorry,thereisnotthecurrentofthisspeople\n");fclose(fp);}voidsearch2(){intk=0;charxhkey[16];personnode*person;person=(personnode*)malloc(sizeof(personnode));printf("\npleaseentertheroomnumberyouwanttoserch:");scanf("%s",xhkey);if((fp=fopen(filename,"rb"))==NULL){printf("\ncan'topenthefile");exit(0);}while(!feof(fp)){fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);if(!strcmp(xhkey,person->xh)){printf("\n\nhavegotit,thecurrentis:");printf("%-10s%-20s%-50s\n",person->name,person->xh,person->fh);k=1;}}if(!k)printf("\n\n對(duì)不起,目前沒有沒有這個(gè)人\n");fclose(fp);}voidsearch3(){intk=0;charfhkey[30];personnode*person;person=(personnode*)malloc(sizeof(personnode));printf("\n請(qǐng)輸入你想要查找的寢室號(hào):");scanf("%s",fhkey);if((fp=fopen(filename,"rb"))==NULL){printf("\n不能打開該檔案");exit(0);}while(!feof(fp)){fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);if(!strcmp(fhkey,person->fh)){printf("\n\n有該信息,該信息是:");printf("%-10s%-20s%-50s\n",person->name,person->xh,person->fh);k=1;}}if(!k)printf("\n\n對(duì)不起,這沒有該人當(dāng)前的信息\n");fclose(fp);}voidappend(){personnode*person;person=(personnode*)malloc(sizeof(personnode));if((fp=fopen(filename,"a"))==NULL){printf("\ncan'topenthefile");exit(0);}printf("\n請(qǐng)輸入姓名,學(xué)號(hào)和寢室號(hào)\n");scanf("%s%s%s",person->name,person->xh,person->fh);fprintf(fp,"%-10s%-20s%-50s\n",person->name,person->xh,person->fh);fclose(fp);}voidmodify(){intk=0;longoffset;charnamekey[8];personnode*person;person=(personnode*)malloc(sizeof(personnode));printf("\n請(qǐng)輸入你想更新的學(xué)號(hào):");scanf("%s",namekey);if((fp=fopen(filename,"r+"))==NULL){printf("\n不能打開該檔案");exit(0);}while(!feof(fp)){offset=ftell(fp);fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);if(!strcmp(namekey,person->name)){k=1;break;}}if(k){printf("\n有,目前是:");printf("%-10s%-20s%-50s\n",person->name,person->xh,person->fh);printf("\n請(qǐng)輸入姓名,學(xué)號(hào)和寢室號(hào):");scanf("%s%s%s",person->name,person->xh,person->fh);fseek(fp,offset,SEEK_SET);fprintf(fp,"%-10s%-20s%-50s\n",person->name,person->xh,person->fh);}elseprintf("\nsorry,thereisnotthecurrentofthispeople\n");fclose(fp);}voiddeleted(){intk=0;charm;longoffset;charnamekey[8];personnode*person;person=(personnode*)malloc(sizeof(personnode));printf("\npleaseenterthenameyouwanttodelete:");scanf("%s",namekey);if((fp=fopen(filename,"r+"))==NULL)printf("\n不能打開該檔案");exit(0);while(!feof(fp)){offset=ftell(fp);fscanf(fp,"%s%s%s\n",person->name,person->xh,person->fh);if(!strcmp(namekey,person->name)){k=1;break;}}if(k){printf("\nhavagotit,thecurrentis:");printf("%-10s%-20s%-50s\n",person->name,person->xh,person->fh);printf("\nareyousuretodeleteit?y/n?");scanf("%s",&m);if(m=='y'){fseek(fp,offset,SEEK_SET);fprintf(fp,"%-10s%-20s%-50s\n","","","");}elserewind(fp);}elseprintf("\n對(duì)不起,這沒有該學(xué)生的數(shù)據(jù)。\n");fclose(fp);}voidmain(){intm,flag=1;while(flag){printf("%33s\n","thefile");printf(" \n");printf("\t\t0 創(chuàng)建一個(gè)新的數(shù)據(jù)檔案\n");printf("\t\t1 讀取以前的數(shù)據(jù)\n");printf("\t\t2 查找姓名\n");printf("\t\t3 查找學(xué)號(hào)\n");printf("\t\t4 查找寢室號(hào)\n");printf("\t\t5 更新\n");printf("\t\t6 刪除\n");printf("\t\t7 修改\n");printf("\t\t8 輸出 \n");printf("\t\t9 退出\n");printf(" \n");printf("\tpleasechoice(0 9)\n");scanf("%d",&m);switch(m){case0:creat();break;case1:readfile();break;case2:search1();break;case3:search2();break;case4:search3();break;case5:modify();break;case6:deleted();break

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(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)論