




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上 數(shù)據(jù)結(jié)構(gòu) 課程設(shè)計源代碼 設(shè)計題目: 學(xué)生宿舍管理系統(tǒng) 院 系: 計算機學(xué)院 班 級: 軟件1501 組 別: 六 組 長: 周佳理 組 員: 韓壯壯 陳義安 起止日期: 2016年12月20日2016年12月24日指導(dǎo)教師: 韓麗娜 專心-專注-專業(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();/打開數(shù)據(jù)void FindID();/按學(xué)號查找學(xué)生void FindName();/按姓名查找學(xué)生void InsertNodeNumber(long studentID, char stu
3、dentName15, char roomNumber4, char bedNumber4);/按學(xué)號從小到大排序void NumberSorting();/排序void Menu();/菜單控制模塊功能代碼:/主函數(shù)int main()long studentID;char studentName15;char roomNumber4;char bedNumber4;/定義要輸入學(xué)生信息的變量;char c;int menu;/保存要進行的選項;while (1) system("pause");Menu();printf("請輸入要進行的操作:");
4、scanf("%d", &menu);switch (menu) case 0:exit(0); break;case 1:printf("請輸入Y或y來添加數(shù)據(jù)n");scanf(" %c", &c);while (c = 'y' | c = 'Y') printf("請輸入學(xué)生學(xué)號:");scanf("%lld", &studentID);printf("請輸入學(xué)生姓名:");scanf("%s"
5、, &studentName);printf("請輸入房間號:");scanf("%s", &roomNumber);printf("請輸入床位號:");scanf("%s", &bedNumber);AppendNode(studentID, studentName, roomNumber, bedNumber);printf("請輸入Y或y來添加數(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("輸入有誤!請重新輸入"); 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é)號)信息 |n");printf("tt|t 3.查找學(xué)生(按姓名)信息 |n");printf("tt|t 4.顯示學(xué)生信息
8、|n");printf("tt|t 5.按學(xué)號排序 |n");printf("tt|t 6.保存信息 |n");printf("tt|t 7.打開信息 |n");printf("tt|.學(xué)生宿舍管理系統(tǒng).|n");/表頭格式控制void Display(struct link *head) printf("-n");printf(" 學(xué)號 姓名 宿舍號 床號 n");printf("-n"); DisplayNode(head);數(shù)據(jù)模塊功能代碼
9、:/定義結(jié)構(gòu)體typedef struct student long studentID; /學(xué)號char studentName15;/姓名char roomNumber4;/房間號char bedNumber4;/床號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("申請內(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("打開文件失敗"); 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ù)寫入到鏈表中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("文件打開失敗"); 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("沒有數(shù)據(jù),無法排序"); return;while (p!=NULL) InsertNodeNumber(p->student.studentID,p->student.studentName,p->
16、student.roomNumber, p->student.bedNumber);p = p->next;/按學(xué)號的從小到大排序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)存申請失敗")
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é)號查找學(xué)生void FindID() struct link *p = head;long studentID=0;if (head = NULL) printf("沒有數(shù)據(jù)查找"); return;printf("請輸入你要查找的學(xué)生的學(xué)號:");scanf("%lld", &studentID);while (studentID != p->student.studentID&&p->next != NULL) p = p->next;if (p->student.studentID = studentID) printf("-n"); printf(" 學(xué)號 姓名 宿舍號 床號 n"); printf("-n"); printf("%lld%15s%13s%13s", p->student.studentID, p->student.studentName, p->student.roomNumber, p->student.bedNumbe
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 地質(zhì)勘查活動管理辦法
- 機電安裝發(fā)票管理辦法
- 梅山鎮(zhèn)村干部管理辦法
- 醫(yī)療健康基金管理辦法
- 數(shù)字時代電影本體論研究的新趨勢
- 杭州物業(yè)應(yīng)急管理辦法
- 中職新生場域轉(zhuǎn)換研究:背景、認識與學(xué)習(xí)期待的實證調(diào)查
- 情緒智力理論與實踐應(yīng)用綜述
- 奶牛飼養(yǎng)管理策略與實踐指南
- 數(shù)字化時代的企業(yè)管理模式與創(chuàng)新路徑研究
- 億航智能介紹
- 考研題土力學(xué)
- 雙向拉伸聚酯薄膜生產(chǎn)知識
- 綠山墻的安妮-練習(xí)答案(完整版)資料
- 2022年小學(xué)美術(shù)教師進城(選調(diào))招聘考試模擬試題(共五套)
- 貴陽小升初分班全真模擬測A卷
- GB/T 77-2007內(nèi)六角平端緊定螺釘
- 中華人民共和國安全生產(chǎn)法
- 九年一貫制學(xué)校教育教學(xué)管理制度匯編
- 《C++語言基礎(chǔ)》全套課件(完整版)
- 鋼筋混凝土框架結(jié)構(gòu)設(shè)計講義
評論
0/150
提交評論