收藏 分销(赏)

学生宿舍标准管理系统.doc

上传人:人****来 文档编号:2827545 上传时间:2024-06-06 格式:DOC 页数:19 大小:38.54KB
下载 相关 举报
学生宿舍标准管理系统.doc_第1页
第1页 / 共19页
学生宿舍标准管理系统.doc_第2页
第2页 / 共19页
学生宿舍标准管理系统.doc_第3页
第3页 / 共19页
学生宿舍标准管理系统.doc_第4页
第4页 / 共19页
学生宿舍标准管理系统.doc_第5页
第5页 / 共19页
点击查看更多>>
资源描述

1、学生宿舍管理系统.txt52每个人都一条抛物线,天赋决定其开口,而最高点则需后天努力。没有秋日落叶飘零,何来新春绿芽饿明丽?只有懂得失去,才会重新拥有。#include stdio.h #include iostream.h #include string.h #define ERROR 0 #define OK 1 #define MAXSIZE 2500 #define EQ(a,b) (a)=(b) typedef int Status;int N=4;/全局变量来储存所输入个数; struct student /数据构造类型; char name10;int num;int room;

2、/*-*/ Status Input() /数据输入; int i=0;int flag=1;char ch;FILE * fpdata;student stuMAXSIZE;if(fpdata=fopen(studata.txt,wb)=NULL) printf(cannot open studata.c file!);return ERROR; while(flag) printf(与否继续输入(Y/N):);cinch;if(ch=y|ch=Y) scanf(%s%d%d,stui.name,&stui.num,&stui.room);fwrite(&stui,sizeof(struct

3、 student),1,fpdata);i+; else flag=0; N=i;fclose(fpdata);printf(数据输入完毕!n);return OK; Status Print(char *filename) /输出数据; FILE * fpdata;student st;int i=0;if(fpdata=fopen(filename,rb)=NULL) printf(cannot open studata.c file!);return ERROR; while(iN) fread(&st,sizeof(struct student),1,fpdata);printf(%s

4、 %d %dn,st.name,st.num,st.room);i+; fclose(fpdata);return OK; /* * * * * * * * */ /* * * * * * * * */ Status NameSort() /姓名排序; int i,j;FILE * fpdata;FILE * fpnamesort;student stuMAXSIZE;if(fpdata=fopen(studata.txt,rb)=NULL) printf(cannot open data.c file!);return ERROR; for(i=1;i=N;i+) fread(&stui,s

5、izeof(struct student),1,fpdata); fclose(fpdata);if(fpnamesort=fopen(namesort.txt,wb)=NULL) printf(cannot open nsort.c);return ERROR; for(i=2;i=N;i+) if(strcmp(stui.name,stui-1.name)0) strcpy(stu0.name,stui.name);stu0.num=stui.num;stu0.room=stui.room;strcpy(stui.name,stui-1.name);stui.num=stui-1.num;

6、stui.room=stui-1.room;for(j=i-2;(strcmp(stu0.name,stuj.name)0;j-) strcpy(stuj+1.name,stuj.name);stuj+1.num=stuj.num;stuj+1.room=stuj.room; strcpy(stuj+1.name,stu0.name);stuj+1.num=stu0.num;stuj+1.room=stu0.room; for(i=1;i=N;i+) fwrite(&stui,sizeof(struct student),1,fpnamesort); fclose(fpnamesort);re

7、turn OK; /* * * * * * * * */ /* * * * * * * * */ Status NumSort() /学号排序; int i,j;FILE * fpdata;FILE * fpnumsort;student stuMAXSIZE;if(fpdata=fopen(studata.txt,rb)=NULL) printf(cannot open data.c file!);return ERROR; for(i=1;i=N;i+) fread(&stui,sizeof(struct student),1,fpdata); fclose(fpdata);if(fpnu

8、msort=fopen(numsort.txt,wb)=NULL) printf(cannot open nsort.c);return ERROR; for(i=2;i=N;i+) if(stui.numstui-1.num) strcpy(stu0.name,stui.name);stu0.num=stui.num;stu0.room=stui.room;strcpy(stui.name,stui-1.name);stui.num=stui-1.num;stui.room=stui-1.room;for(j=i-2;stu0.numstuj.num;j-) strcpy(stuj+1.na

9、me,stuj.name);stuj+1.num=stuj.num;stuj+1.room=stuj.room; strcpy(stuj+1.name,stu0.name);stuj+1.num=stu0.num;stuj+1.room=stu0.room; for(i=1;i=N;i+) fwrite(&stui,sizeof(struct student),1,fpnumsort); fclose(fpnumsort);return OK; /* * * * * * * * */ /* * * * * * * * */ Status RoomSort() /房间号排序; int i,j;F

10、ILE * fpdata;FILE * fproomsort;student stuMAXSIZE;if(fpdata=fopen(studata.txt,rb)=NULL) printf(cannot open data.c file!);return ERROR; for(i=1;i=N;i+) fread(&stui,sizeof(struct student),1,fpdata); fclose(fpdata);if(fproomsort=fopen(roomsort.txt,wb)=NULL) printf(cannot open nsort.c);return ERROR; for

11、(i=2;i=N;i+) if(stui.roomstui-1.room) strcpy(stu0.name,stui.name);stu0.num=stui.num;stu0.room=stui.room;strcpy(stui.name,stui-1.name);stui.num=stui-1.num;stui.room=stui-1.room;for(j=i-2;stu0.roomstuj.room;j-) strcpy(stuj+1.name,stuj.name);stuj+1.num=stuj.num;stuj+1.room=stuj.room; strcpy(stuj+1.name

12、,stu0.name);stuj+1.num=stu0.num;stuj+1.room=stu0.room; for(i=1;i=N;i+) fwrite(&stui,sizeof(struct student),1,fproomsort); fclose(fproomsort);return OK; /* * * * * * * * */ /* * * * * * * * */ Status NameSearch(char * namekey) /按名字查询; /顺序查找 int i;FILE * f;student stuMAXSIZE;if(f=fopen(namesort.txt,rb

13、)=NULL) printf(cannot open namesort.txt file!);return ERROR; for(i=1;i0;-m) if(!strcmp(stum.name,namekey) printf(%s %d %dn,stum.name,stum.num,stum.room); return m;fclose(f);if(flag0) printf(%s %d %dn,stuflag.name,stuflag.num,stuflag.room); else printf(对不起,没有找到相匹配记录n);return OK; /* * * * * * * * */ /

14、* * * * * * * * */ Status NumSearch(int key) /按学号查询; int i;FILE * f;student stuMAXSIZE;if(f=fopen(numsort.txt,rb)=NULL) printf(cannot open namesort.txt file!);return ERROR; for(i=1;i=N;i+) fread(&stui,sizeof(struct student),1,f); int low=1;int high=N;int mid;int flag=0;while(lowkey) high=mid-1;else

15、low=mid+1; fclose(f);if(flag0) printf(%s %d %dn,stuflag.name,stuflag.num,stuflag.room); else printf(对不起,没有找到相匹配记录n);return OK; /* * * * * * * * */ /* * * * * * * * */ Status RoomSearch(int key) /按房间号查询; int i;FILE * f;student stuMAXSIZE;if(f=fopen(roomsort.txt,rb)=NULL) printf(cannot open roomsort.t

16、xt file!);return ERROR; for(i=1;i0;-t) if(stut.room=key) printf(%s %d %dn,stut.name,stut.num,stut.room); return t;fclose(f);if(flag0) printf(%s %d %dn,stuflag.name,stuflag.num,stuflag.room); else printf(对不起,没有找到相匹配记录n);return OK; /* * * * * * * * */ /* * * * main() * * * */ /* * * * * * * * */ void

17、main() int num;int room;int flag,flag1,flag2;char cha;char name10;cout * 学生宿舍管理系统 *endl;printf( -Powered by GUOXIAOJIEn);printf(-n);cout与否需要录入入住学生信息(Y/N)cha1;if(cha1=Y|cha1=y) printf(-n);printf(请将住宿学生信息输入(姓名 学号 房间号)n);Input();NameSort();NumSort();RoomSort(); while(flag) printf(-n);cout* 学生宿舍管理系统 *en

18、dl;printf(-n);printf(请选取操作:n);printf(A.按姓名查询n);printf(B.按学号查询n);printf(C.按房号查询n);printf(D.退出n);cout注意:字母请输入大写cha;switch(cha) case A :flag1=1;while(flag1) printf(-n);printf(A.输入要查询名字n);printf(B.按姓名所有输出n);printf(C.返回n);printf(注意:字母请输入大写n);cincha;switch(cha) case A:scanf(%s,name);printf(查询成果为:n);printf

19、(-n);NameSearch(name);printf(-n);break;case B:Print(namesort.txt);break;case C:flag1=0;break;default:printf(-n);printf(!你输入命令无效。注意:命令字母请输入大写!n); break;case B :while(flag2) printf(-n);printf(A.输入要查询学号n);printf(B.按学号所有输出n);printf(C.返回n);printf(注意:字母请输入大写n);cincha;switch(cha) case A:scanf(%d,&num);prin

20、tf(查询成果为:n);printf(-n);NumSearch(num);break;case B:Print(numsort.txt);break;case C:flag2=0;break;default:printf(-n);printf(!你输入命令无效。注意:命令字母请输入大写!n); break;case C :flag1=1;while(flag1) printf(-n);printf(A.输入要查询宿舍号n);printf(B.按宿舍号所有输出n);printf(C.返回n);printf(注意:字母请输入大写n);cincha;switch(cha) case A:scanf(%d,&room);printf(查询成果为:n);printf(-n);RoomSearch(room);printf(-n);break;case B:Print(roomsort.txt);break;case C:flag1=0;break;default:printf(-n);printf(!你输入命令无效。注意:命令字母请输入大写!n); break;case D :flag=0;break;default:printf(-n);printf(!你输入命令无效。注意:命令字母请输入大写!n);

展开阅读全文
相似文档                                   自信AI助手自信AI助手
猜你喜欢                                   自信AI导航自信AI导航
搜索标签

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2024 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服