學(xué)生宿舍管理系統(tǒng)源代碼樣本_第1頁
學(xué)生宿舍管理系統(tǒng)源代碼樣本_第2頁
學(xué)生宿舍管理系統(tǒng)源代碼樣本_第3頁
學(xué)生宿舍管理系統(tǒng)源代碼樣本_第4頁
學(xué)生宿舍管理系統(tǒng)源代碼樣本_第5頁
已閱讀5頁,還剩8頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

數(shù)據(jù)構(gòu)造課程設(shè)計(jì)源代碼設(shè)計(jì)題目:學(xué)生宿舍管理系統(tǒng)院系:計(jì)算機(jī)學(xué)院班級(jí):軟件1501組別:六組長:周佳理組員:韓壯壯陳義安起止日期:12月20日~12月24日指引教師:韓麗娜源代碼:#define_CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>voidAppendNode(longstudentID,charstudentName[15],charroomNumber[4],charbedNumber[4]);//向鏈表中添加數(shù)據(jù)voidDisplayNode(structlink*head);//打印鏈表中數(shù)據(jù)voidDisplay(structlink*head);//表頭格式控制voidDeleteMemory(structlink*head);//刪除鏈表所占用內(nèi)存voidSave();//保存數(shù)據(jù)voidOpen();//打開數(shù)據(jù)voidFindID();//按學(xué)號(hào)查找學(xué)生voidFindName();//按姓名查找學(xué)生voidInsertNodeNumber(longstudentID,charstudentName[15],charroomNumber[4],charbedNumber[4]);//按學(xué)號(hào)從小到大排序voidNumberSorting();//排序voidMenu();//菜單控制模塊功能代碼://主函數(shù)intmain(){ longstudentID; charstudentName[15]; charroomNumber[4]; charbedNumber[4];//定義要輸入學(xué)生信息變量; charc; intmenu;//保存要進(jìn)行選項(xiàng); while(1){ system("pause"); Menu(); printf("請(qǐng)輸入要進(jìn)行操作:"); scanf("%d",&menu); switch(menu){ case0: exit(0);break; case1: printf("請(qǐng)輸入Y或y來添加數(shù)據(jù)\n"); scanf("%c",&c); while(c=='y'||c=='Y'){ printf("請(qǐng)輸入學(xué)生學(xué)號(hào):"); scanf("%lld",&studentID); printf("請(qǐng)輸入學(xué)生姓名:"); scanf("%s",&studentName); printf("請(qǐng)輸入房間號(hào):"); scanf("%s",&roomNumber); printf("請(qǐng)輸入床位號(hào):"); scanf("%s",&bedNumber); AppendNode(studentID,studentName,roomNumber,bedNumber); printf("請(qǐng)輸入Y或y來添加數(shù)據(jù)\n"); scanf("%c",&c); } Display(head);break; case2: FindID();break; case3: FindName();break; case4: Display(head);//顯示信息break; case5: NumberSorting(); Display(head1);//排序后學(xué)生信息 head1=NULL;break; case6: Save();break; case7: Open();break; default: printf("輸入有誤!請(qǐng)重新輸入");break; } } DeleteMemory(head); DeleteMemory(head1); system("pause"); return0;}//菜單voidMenu(){ system("cls");//清屏操作; printf("\n\n\n\n\n"); printf("\t\t|.......學(xué)生宿舍管理系統(tǒng)..............|\n"); printf("\t\t|\t0.退出|\n"); printf("\t\t|\t1.添加學(xué)生住宿信息|\n"); printf("\t\t|\t2.查找學(xué)生(按學(xué)號(hào))信息|\n"); printf("\t\t|\t3.查找學(xué)生(按姓名)信息|\n"); printf("\t\t|\t4.顯示學(xué)生信息|\n"); printf("\t\t|\t5.按學(xué)號(hào)排序|\n"); printf("\t\t|\t6.保存信息|\n"); printf("\t\t|\t7.打開信息|\n"); printf("\t\t|.......學(xué)生宿舍管理系統(tǒng)..............|\n");}//表頭格式控制voidDisplay(structlink*head){ printf("-----------------------------------------------------------\n"); printf("學(xué)號(hào)姓名宿舍號(hào)床號(hào)\n"); printf("-----------------------------------------------------------\n");DisplayNode(head);}數(shù)據(jù)模塊功能代碼://定義構(gòu)造體typedefstructstudent{ longstudentID;//學(xué)號(hào) charstudentName[15];//姓名 charroomNumber[4];//房間號(hào) charbedNumber[4];//床號(hào)}STU;//初始化鏈表structlink{ STUstudent; structlink*next;};structlink*head=NULL;//保存輸入學(xué)生信息數(shù)據(jù)structlink*head1=NULL;//保存排序后學(xué)生信息數(shù)據(jù)//添加數(shù)據(jù)voidAppendNode(longstudentID,charstudentName[15],charroomNumber[4],charbedNumber[4]){ structlink*p=NULL,*pr=head; p=(structlink*)malloc(sizeof(structlink)); if(p==NULL){ printf("申請(qǐng)內(nèi)存失敗");return; } if(head==NULL){ head=p; } else{ while(pr->next!=NULL){ pr=pr->next; } pr->next=p; } p->student.studentID=studentID; strcpy(p->student.studentName,studentName); strcpy(p->student.roomNumber,roomNumber); strcpy(p->student.bedNumber,bedNumber); p->next=NULL;return;}//打印數(shù)據(jù)voidDisplayNode(structlink*head){ structlink*p=head; if(p==NULL){ return; } printf("%lld%15s%13s%13s",p->student.studentID,p->student.studentName,p->student.roomNumber,p->student.bedNumber); printf("\n");p=p->next;DisplayNode(p);}//保存鏈表中數(shù)據(jù)voidSave(){ FILE*fp; structlink*p=head; fp=fopen("demo.txt","w"); if(fp==NULL){ printf("打開文獻(xiàn)失敗");return; } while(p!=NULL){ fprintf(fp,"%20lld%15s%5s%4s",p->student.studentID,p->student.studentName,p->student.roomNumber,p->student.bedNumber); p=p->next; } fclose(fp);return;}//將文獻(xiàn)中獲得數(shù)據(jù)寫入到鏈表中voidOpen(){ fflush(stdin); fflush(stdout); longstudentID; charstudentName[15]; charroomNumber[4]; charbedNumber[4]; FILE*fp;charc; fp=fopen("demo.txt","a+"); if(fp==NULL){ printf("文獻(xiàn)打開失敗");return; } while((c=fgetc(fp))!=EOF){ fscanf(fp,"%20lld",&studentID); fscanf(fp,"%15s",studentName); fscanf(fp,"%5s",roomNumber); fscanf(fp,"%4s",bedNumber); AppendNode(studentID,studentName,roomNumber,bedNumber); } fclose(fp);}功能模塊功能代碼://排序函數(shù)voidNumberSorting(){ structlink*p=head; structlink*p1=head1; intsum=0; if(p==NULL){ printf("沒有數(shù)據(jù),無法排序");return; } while(p!=NULL){ InsertNodeNumber(p->student.studentID,p->student.studentName,p->student.roomNumber,p->student.bedNumber);p=p->next; }}//按學(xué)號(hào)從小到大排序voidInsertNodeNumber(longstudentID,charstudentName[15],charroomNumber[4],charbedNumber[4]){ structlink*pr=head1,*p=head1,*temp=NULL; p=(structlink*)malloc(sizeof(structlink)); if(p==NULL){ printf("內(nèi)存申請(qǐng)失敗");return; } p->next=NULL; p->student.studentID=studentID; strcpy(p->student.studentName,studentName); strcpy(p->student.roomNumber,roomNumber); strcpy(p->student.bedNumber,bedNumber); if(head1==NULL){ head1=p; } else{ while(pr->student.studentID<studentID&&pr->next!=NULL){ temp=pr;pr=pr->next; } if(pr->student.studentID>=studentID){ if(pr==head1){ p->next=head1;head1=p; } else{ pr=temp;p->next=pr->next;pr->next=p; } } else{ pr->next=p; } }}//刪除鏈表所占用內(nèi)存voidDeleteMemory(structlink*head){ structlink*p=head,*pr=NULL; while(p!=NULL){ pr=p;p=p->next;free(pr); } }//按學(xué)號(hào)查找學(xué)生voidFindID(){ structlink*p=head; longstudentID=0; if(head==NULL){ printf("沒有數(shù)據(jù)查找");return; } printf("請(qǐng)輸入你要查找學(xué)生學(xué)號(hào):"); scanf("%lld",&studentID); while(studentID!=p->student.studentID&&p->next!=NULL){ p=p->next; } if(p->student.studentID==studentID){ printf("-----------------------------------------------------------\n"); printf("學(xué)號(hào)姓名宿舍號(hào)床號(hào)\n"); printf("-----------------------------------------------------------\n"); printf("%lld%15s%13s%13s",p->student.studentID,p->student.studentName,p->student.roomNumber,p->student.bedNumber);; } else{ printf("沒有你要查找數(shù)據(jù)"); }

溫馨提示

  • 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)論