




版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上 數(shù)據(jù)結(jié)構(gòu) 課程設(shè)計(jì)源代碼 設(shè)計(jì)題目: 學(xué)生宿舍管理系統(tǒng) 院 系: 計(jì)算機(jī)學(xué)院 班 級(jí): 軟件1501 組 別: 六 組 長(zhǎng): 周佳理 組 員: 韓壯壯 陳義安 起止日期: 2016年12月20日2016年12月24日指導(dǎo)教師: 韓麗娜 專(zhuān)心-專(zhuān)注-專(zhuān)業(yè)源代碼: #define _CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>void AppendNode(long studentID, char studentName15, c
2、har roomNumber4, char bedNumber4);/向鏈表中添加數(shù)據(jù)void DisplayNode(struct link *head);/打印鏈表中數(shù)據(jù)void Display(struct link *head);/表頭格式控制void DeleteMemory(struct link *head);/刪除鏈表所占用的內(nèi)存void Save();/保存數(shù)據(jù)void Open();/打開(kāi)數(shù)據(jù)void FindID();/按學(xué)號(hào)查找學(xué)生void FindName();/按姓名查找學(xué)生void InsertNodeNumber(long studentID, char stu
3、dentName15, char roomNumber4, char bedNumber4);/按學(xué)號(hào)從小到大排序void NumberSorting();/排序void Menu();/菜單控制模塊功能代碼:/主函數(shù)int main()long studentID;char studentName15;char roomNumber4;char bedNumber4;/定義要輸入學(xué)生信息的變量;char c;int menu;/保存要進(jìn)行的選項(xiàng);while (1) system("pause");Menu();printf("請(qǐng)輸入要進(jìn)行的操作:");
4、scanf("%d", &menu);switch (menu) case 0:exit(0); break;case 1:printf("請(qǐng)輸入Y或y來(lái)添加數(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"
5、, &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來(lái)添加數(shù)據(jù)n");scanf(" %c", &c);Display(head); break;case
6、 2: FindID(); break;case 3: FindName(); break;case 4:Display(head);/顯示信息 break;case 5:NumberSorting();Display(head1);/排序后的學(xué)生信息head1 = NULL; break;case 6:Save(); break;case 7:Open(); break;default:printf("輸入有誤!請(qǐng)重新輸入"); break;DeleteMemory(head);DeleteMemory(head1);system("pause");r
7、eturn 0;/菜單void Menu() system("cls");/清屏操作; printf("nnnnn"); printf("tt|.學(xué)生宿舍管理系統(tǒng).|n");printf("tt|t 0.退出 |n");printf("tt|t 1.添加學(xué)生住宿信息 |n");printf("tt|t 2.查找學(xué)生(按學(xué)號(hào))信息 |n");printf("tt|t 3.查找學(xué)生(按姓名)信息 |n");printf("tt|t 4.顯示學(xué)生信息
8、|n");printf("tt|t 5.按學(xué)號(hào)排序 |n");printf("tt|t 6.保存信息 |n");printf("tt|t 7.打開(kāi)信息 |n");printf("tt|.學(xué)生宿舍管理系統(tǒng).|n");/表頭格式控制void Display(struct link *head) printf("-n");printf(" 學(xué)號(hào) 姓名 宿舍號(hào) 床號(hào) n");printf("-n"); DisplayNode(head);數(shù)據(jù)模塊功能代碼
9、:/定義結(jié)構(gòu)體typedef struct student long studentID; /學(xué)號(hào)char studentName15;/姓名char roomNumber4;/房間號(hào)char bedNumber4;/床號(hào)STU;/初始化鏈表struct link STU student;struct link *next;struct link *head = NULL;/保存輸入的學(xué)生信息數(shù)據(jù)struct link *head1 = NULL;/保存排序后的學(xué)生信息數(shù)據(jù)/添加數(shù)據(jù)void AppendNode(long studentID, char studentName15, char
10、 roomNumber4, char bedNumber4) struct link *p = NULL, *pr = head;p = (struct link *) malloc(sizeof(struct link);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-&g
11、t;student.studentName, studentName);strcpy(p->student.roomNumber, roomNumber);strcpy(p->student.bedNumber,bedNumber);p->next = NULL; return;/打印數(shù)據(jù)void DisplayNode(struct link *head) struct link *p = head;if (p = NULL) return;printf("%lld%15s%13s%13s",p->student.studentID,p->s
12、tudent.studentName,p->student.roomNumber, p->student.bedNumber);printf("n"); p=p->next; DisplayNode(p);/保存鏈表中的數(shù)據(jù)void Save() FILE *fp;struct link *p = head;fp = fopen("demo.txt", "w");if (fp= NULL) printf("打開(kāi)文件失敗"); return;while (p != NULL) fprintf(fp,
13、"%20lld%15s%5s%4s", p->student.studentID, p->student.studentName, p->student.roomNumber,p->student.bedNumber);p = p->next;fclose(fp); return;/將文件中獲得的數(shù)據(jù)寫(xiě)入到鏈表中void Open() fflush(stdin);fflush(stdout);long studentID;char studentName15;char roomNumber4;char bedNumber4;FILE *fp;
14、char c;fp = fopen("demo.txt", "a+");if (fp= NULL) printf("文件打開(kāi)失敗"); return;while (c = fgetc(fp)!=EOF) fscanf(fp, "%20lld", &studentID);fscanf(fp, "%15s", studentName);fscanf(fp, "%5s", roomNumber);fscanf(fp,"%4s",bedNumber);Ap
15、pendNode(studentID, studentName, roomNumber, bedNumber);fclose(fp);功能模塊功能代碼:/排序函數(shù)void NumberSorting() struct link *p = head;struct link *p1 = head1;int sum = 0;if(p = NULL) printf("沒(méi)有數(shù)據(jù),無(wú)法排序"); return;while (p!=NULL) InsertNodeNumber(p->student.studentID,p->student.studentName,p->
16、student.roomNumber, p->student.bedNumber);p = p->next;/按學(xué)號(hào)的從小到大排序void InsertNodeNumber(long studentID, char studentName15, char roomNumber4, char bedNumber4) struct link *pr = head1, *p = head1, *temp = NULL;p = (struct link *)malloc(sizeof(struct link);if (p = NULL) printf("內(nèi)存申請(qǐng)失敗")
17、; 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 !=
18、 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)存void DeleteMemory(struct link *head) struct link *p = head, *pr = NULL;while (p !=
19、NULL) pr = p; p = p->next; free(pr);/按學(xué)號(hào)查找學(xué)生void FindID() struct link *p = head;long studentID=0;if (head = NULL) printf("沒(méi)有數(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.bedNumbe
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
- 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 工廠車(chē)間干燥管理制度
- 墻面防撞處理方案(3篇)
- 小區(qū)勘測(cè)現(xiàn)場(chǎng)管理制度
- 彩繪門(mén)頭改造方案(3篇)
- 肇事賠償方案(3篇)
- 建筑施工防暑演練方案(3篇)
- 地質(zhì)雷達(dá)監(jiān)測(cè)方案(3篇)
- 水系圍欄維修方案(3篇)
- 廠房樓層規(guī)劃方案(3篇)
- 工程計(jì)劃方案(3篇)
- GB/T 3672.1-2002橡膠制品的公差第1部分:尺寸公差
- GB/T 23227-2018卷煙紙、成形紙、接裝紙、具有間斷或連續(xù)透氣區(qū)的材料以及具有不同透氣帶的材料透氣度的測(cè)定
- GB/T 18049-2017熱環(huán)境的人類(lèi)工效學(xué)通過(guò)計(jì)算PMV和PPD指數(shù)與局部熱舒適準(zhǔn)則對(duì)熱舒適進(jìn)行分析測(cè)定與解釋
- 煙草專(zhuān)賣(mài)管理師崗位技能標(biāo)準(zhǔn)(2023版)
- 半條被子(紅軍長(zhǎng)征時(shí)期故事) PPT
- 電梯安裝標(biāo)準(zhǔn)合同模板
- 松下NPM貼片機(jī)基本操作培訓(xùn)教程課件
- 公司車(chē)輛駕駛扣分違章處理證明 模板
- 一次性賠償協(xié)議書(shū)模板
- (中職)車(chē)削加工技術(shù)全冊(cè)實(shí)訓(xùn)課教案完整版
- 幼兒園繪本故事:《漏》
評(píng)論
0/150
提交評(píng)論