学生宿舍管理系统源代码_第1页
学生宿舍管理系统源代码_第2页
学生宿舍管理系统源代码_第3页
学生宿舍管理系统源代码_第4页
学生宿舍管理系统源代码_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、咸苗即篦草院数据结构课程设计源代码设计题目:学生宿舍管理系统院系:计算机学院班级:软件1501组别:A组长:周佳理组员:韩壮壮陈义安起止日期:起16年12月20日2016年12月24日指导教师:韩丽娜源代码:#define_CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>#include<string.h>voidAppendNode(longstudentID,charstudentName15,charroomNumber4,char打印链表中数据表头格式控制删除链表所占用的内存bedNu

2、mber4);/向链表中添加数据voidDisplayNode(structlink*head);/voidDisplay(structlink*head);/voidDeleteMemory(structlink*head);/voidSave();/保存数据voidOpen();/打开数据voidFindID();/按学号查找学生voidFindName();/按姓名查找学生voidInsertNodeNumber(longstudentID,charstudentName15,charroomNumber4,charbedNumber4);/按学号从小到大排序voidNumberSort

3、ing();/排序voidMenu();/菜单控制模块功能代码:/主函数intmain()longstudentID;charstudentName15;charroomNumber4;charbedNumber4;/定义要输入学生信息的变量;charc;intmenu;/保存要进行的选项;while(1)system("pause");Menu();printf("请输入要进行的操作:");scanf("%d",&menu);switch(menu)case0:exit(0);break;case 1:printf(&quo

4、t;请输入Y或y来添加数据n");scanf("%c",&c);while(c='y'|c='Y')printf("请输入学生学号:");scanf("%lld",&studentID);printf("请输入学生姓名:");scanf("%s",&studentName);printf("请输入房间号:");scanf("%s",&roomNumber);printf("

5、请输入床位号:");scanf("%s",&bedNumber);AppendNode(studentID,studentName,roomNumber,bedNumber);printf("请输入Y或y来添加数据n");scanf("%c",&c);Display(head);break;case 2:FindID();break;case3:FindName();break;case 4:Display(head);/显示信息break;case 5:NumberSorting();Display(hea

6、d1);/排序后的学生信息head1=NULL;break;case 6:Save();break;case 7:Open();break;default:printf("输入有误!请重新输入");break;DeleteMemory(head);DeleteMemory(head1);system("pause");return0;/菜单voidMenu()system("cls");/清屏操作;printf("nnnnn");printf("tt|学生宿舍管理系统|n");printf(&q

7、uot;tt|t0.退出|n");printf("tt|t1.添加学生住宿信息|n");printf("tt|t2.查找学生(按学号)信息|n");printf("tt|t3.查找学生(按姓名)信息|n");printf("tt|t4.显示学生信息|n");printf("tt|t5.按学号排序|n");printf("tt|t6.保存信息|n");printf("tt|t7.打开信息|n");printf("tt|学生宿舍管理系统|n

8、");/表头格式控制voidDisplay(structlink*head)床号 n");printf("n");printf("学号姓名宿舍号printf("n");DisplayNode(head);数据模块功能代码:/定义结构体typedefstructstudentlongstudentID;/学号charstudentName15;/姓名charroomNumber4;/房间号charbedNumber4;/床号STU;/初始化链表structlinkSTUstudent;structlink*next;保存输入的

9、学生信息数据保存排序后的学生信息数据;structlink*head=NULL;/structlink*head1=NULL;/添加数据voidAppendNode(longstudentID,charstudentName15,charroomNumber4,charbedNumber4)structlink*p=NULL,*pr=head;p=(structlink*)malloc(sizeof(structlink);if(p=NULL)printf("申请内存失败");return;if(head=NULL)head=p;elsewhile(pr->next!

10、=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;/打印数据voidDisplayNode(structlink*head)structlink*p=head;if(p=NULL)return;prin

11、tf("%lld%15s%13s%13s",p->student.studentID,p->student.studentName,p->student.roomNumber,p->student.bedNumber);printf("n");p=p->next;DisplayNode(p);/保存链表中的数据voidSave()FILE*fp;structlink*p=head;fp=fopen("demo.txt","w");if(fp=NULL)printf("打开文件

12、失败");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;/将文件中获得的数据写入到链表中voidOpen()fflush(stdin);fflush(stdout);longstudentID;charstudentName15;charroomNum

13、ber4;charbedNumber4;FILE*fp;charc;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",bed

14、Number);AppendNode(studentID,studentName,roomNumber,bedNumber);fclose(fp);功能模块功能代码:/排序函数voidNumberSorting()structlink*p=head;structlink*p1=head1;intsum=0;if(p=NULL)printf("没有数据,无法排序");return;while(p!=NULL)InsertNodeNumber(p->student.studentID,p->student.studentName,p->student.room

15、Number,p->student.bedNumber);p=p->next;/按学号的从小到大排序voidInsertNodeNumber(longstudentID,charstudentName15,charroomNumber4,charbedNumber4)structlink*pr=head1,*p=head1,*temp=NULL;p=(structlink*)malloc(sizeof(structlink);if(p=NULL)printf("内存申请失败");return;p->next=NULL;p->student.stude

16、ntID=studentID;strcpy(p->student.studentName,studentName);strcpy(p->student.roomNumber,roomNumber);strcpy(p->student.bedNumber,bedNumber);if(head1=NULL)head1=p;elsewhile(pr->student.studentID<studentID&&pr->next!=NULL)temp=pr;pr=pr->next;if(pr->student.studentID>=s

17、tudentID)if(pr=head1)p->next=head1;head1=p;elsepr=temp;p->next=pr->next;pr->next=p;elsepr->next=p;/删除链表所占用的内存voidDeleteMemory(structlink*head)structlink*p=head,*pr=NULL;while(p!=NULL)pr=p;p=p->next;free(pr);/按学号查找学生voidFindID()structlink*p=head;longstudentID=0;if(head=NULL)printf(&

18、quot;没有数据查找");return;printf("请输入你要查找的学生的学号:");scanf("%lld",&studentID);while(studentID!=p->student.studentID&&p->next!=NULL)p=p->next;if(p->student.studentID=studentID)printf("n");printf("学号姓名宿舍号床号n");printf("n");printf("%lld%15s%13s%13s",p->student.studentID,p->student.studentName,p->student.roomNumber,p->student.bedNumber);elseprin

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论