学生宿舍管理系统源代码.docx

上传人:b****2 文档编号:23437804 上传时间:2023-05-17 格式:DOCX 页数:12 大小:55.81KB
下载 相关 举报
学生宿舍管理系统源代码.docx_第1页
第1页 / 共12页
学生宿舍管理系统源代码.docx_第2页
第2页 / 共12页
学生宿舍管理系统源代码.docx_第3页
第3页 / 共12页
学生宿舍管理系统源代码.docx_第4页
第4页 / 共12页
学生宿舍管理系统源代码.docx_第5页
第5页 / 共12页
点击查看更多>>
下载资源
资源描述

学生宿舍管理系统源代码.docx

《学生宿舍管理系统源代码.docx》由会员分享,可在线阅读,更多相关《学生宿舍管理系统源代码.docx(12页珍藏版)》请在冰豆网上搜索。

学生宿舍管理系统源代码.docx

学生宿舍管理系统源代码

数据结构课程设计

源代码

 

设计题目:

学生宿舍管理系统

院系:

计算机学院

班级:

软件1501

组别:

组长:

周佳理

组员:

韩壮壮陈义安

起止日期:

2016年12月20日~2016年12月24日

指导教师:

韩丽娜

源代码:

#define_CRT_SECURE_NO_WARNINGS

#include

#include

#include

voidAppendNode(longstudentID,charstudentName[15],charroomNumber[4],charbedNumber[4]);//向链表中添加数据

voidDisplayNode(structlink*head);//打印链表中数据

voidDisplay(structlink*head);//表头格式控制

voidDeleteMemory(structlink*head);//删除链表所占用的内存

voidSave();//保存数据

voidOpen();//打开数据

voidFindID();//按学号查找学生

voidFindName();//按姓名查找学生

voidInsertNodeNumber(longstudentID,charstudentName[15],charroomNumber[4],charbedNumber[4]);//按学号从小到大排序

voidNumberSorting();//排序

voidMenu();//菜单

控制模块功能代码:

//主函数

intmain()

{

longstudentID;

charstudentName[15];

charroomNumber[4];

charbedNumber[4];//定义要输入学生信息的变量;

charc;

intmenu;//保存要进行的选项;

while

(1){

system("pause");

Menu();

printf("请输入要进行的操作:

");

scanf("%d",&menu);

switch(menu){

case0:

exit(0);break;

case1:

printf("请输入Y或y来添加数据\n");

scanf("%c",&c);

while(c=='y'||c=='Y'){

printf("请输入学生学号:

");

scanf("%lld",&studentID);

printf("请输入学生姓名:

");

scanf("%s",&studentName);

printf("请输入房间号:

");

scanf("%s",&roomNumber);

printf("请输入床位号:

");

scanf("%s",&bedNumber);

AppendNode(studentID,studentName,roomNumber,bedNumber);

printf("请输入Y或y来添加数据\n");

scanf("%c",&c);

}

Display(head);break;

case2:

FindID();break;

case3:

FindName();break;

case4:

Display(head);//显示信息

break;

case5:

NumberSorting();

Display(head1);//排序后的学生信息

head1=NULL;break;

case6:

Save();break;

case7:

Open();break;

default:

printf("输入有误!

请重新输入");break;

}

}

DeleteMemory(head);

DeleteMemory(head1);

system("pause");

return0;

}

//菜单

voidMenu(){

system("cls");//清屏操作;

printf("\n\n\n\n\n");

printf("\t\t|.......学生宿舍管理系统..............|\n");

printf("\t\t|\t0.退出|\n");

printf("\t\t|\t1.添加学生住宿信息|\n");

printf("\t\t|\t2.查找学生(按学号)信息|\n");

printf("\t\t|\t3.查找学生(按姓名)信息|\n");

printf("\t\t|\t4.显示学生信息|\n");

printf("\t\t|\t5.按学号排序|\n");

printf("\t\t|\t6.保存信息|\n");

printf("\t\t|\t7.打开信息|\n");

printf("\t\t|.......学生宿舍管理系统..............|\n");

}

//表头格式控制

voidDisplay(structlink*head){

printf("-----------------------------------------------------------\n");

printf("学号姓名宿舍号床号\n");

printf("-----------------------------------------------------------\n");

DisplayNode(head);

}

数据模块功能代码:

//定义结构体

typedefstructstudent{

longstudentID;//学号

charstudentName[15];//姓名

charroomNumber[4];//房间号

charbedNumber[4];//床号

}STU;

//初始化链表

structlink{

STUstudent;

structlink*next;

};

structlink*head=NULL;//保存输入的学生信息数据

structlink*head1=NULL;//保存排序后的学生信息数据

//添加数据

voidAppendNode(longstudentID,charstudentName[15],charroomNumber[4],charbedNumber[4]){

structlink*p=NULL,*pr=head;

p=(structlink*)malloc(sizeof(structlink));

if(p==NULL){

printf("申请内存失败");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;

}

//打印数据

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);

}

//保存链表中的数据

voidSave(){

FILE*fp;

structlink*p=head;

fp=fopen("demo.txt","w");

if(fp==NULL){

printf("打开文件失败");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;

charstudentName[15];

charroomNumber[4];

charbedNumber[4];

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",bedNumber);

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.roomNumber,p->student.bedNumber);p=p->next;

}

}

//按学号的从小到大排序

voidInsertNodeNumber(longstudentID,charstudentName[15],charroomNumber[4],charbedNumber[4]){

structlink*pr=head1,*p=head1,*temp=NULL;

p=(structlink*)malloc(sizeof(structlink));

if(p==NULL){

printf("内存申请失败");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.studentIDnext!

=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;

}

}

}

//删除链表所占用的内存

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("没有数据查找");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);;

}

else{

printf("没有你要查找的数据");

}return;

}

//按姓名查找学生

voidFindName(){

structlink*p=head;

charstudentName[15]="";

if(head==NULL){

printf("没有数据查找");return;

}

printf("请输入你要查找的学生的姓名:

");

scanf("%s",studentName);

while(0!

=strcmp(studentName,p->student.studentName)&&p->next!

=NULL){

p=p->next;

}

if(0==strcmp(studentName,p->student.studentName)){

printf("-----------------------------------------------------------\n");

printf("学号姓名宿舍号床号\n");

printf("-----------------------------------------------------------\n");

printf("%lld%15s%13s%13s",p->student.studentID,p->student.studentName,p->student.roomNumber,p->student.bedNumber);

}

else{

printf("没有你要查找的数据");

}return;

}

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 法学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1