欢迎来到天天文库
浏览记录
ID:58875938
大小:48.50 KB
页数:12页
时间:2020-09-21
《学生宿舍管理系统方案.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、..学生宿舍管理系统.txt52每个人都一条抛物线,天赋决定其开口,而最高点则需后天的努力。没有秋日落叶的飘零,何来新春绿芽的饿明丽?只有懂得失去,才会重新拥有。#include"stdio.h"#include"iostream.h"#include"string.h"#defineERROR0#defineOK1#defineMAXSIZE2500#defineEQ(a,b)((a)==(b))typedefintStatus;intN=4;//全局变量来储存所输入的个数;structstudent{//数据结构类型;charname
2、[10];intnum;introom;};/*--------------------------------------------------------------------------*/StatusInput(){//数据输入;inti=0;intflag=1;charch;FILE*fpdata;studentstu[MAXSIZE];if((fpdata=fopen("studata.txt","wb"))==NULL){printf("cannotopenstudata.cfile!");returnERROR;}wh
3、ile(flag){printf("是否继续输入(Y/N):");.....cin>>ch;if(ch=='y'
4、
5、ch=='Y'){scanf("%s%d%d",stu[i].name,&stu[i].num,&stu[i].room);fwrite(&stu[i],sizeof(structstudent),1,fpdata);i++;}elseflag=0;}N=i;fclose(fpdata);printf("数据输入完成!");returnOK;}StatusPrint(char*filename){//输出数据;FILE*
6、fpdata;studentst;inti=0;if((fpdata=fopen(filename,"rb"))==NULL){printf("cannotopenstudata.cfile!");returnERROR;}while(i7、*****************************//***************************************************************/StatusNameSort(){//排序;inti,j;.....FILE*fpdata;FILE*fpnamesort;studentstu[MAXSIZE];if((fpdata=fopen("studata.txt","rb"))==NULL){printf("cannotopendata.cfile!");returnERROR;}for(i8、=1;i<=N;i++){fread(&stu[i],sizeof(structstudent),1,fpdata);}fclose(fpdata);if((fpnamesort=fopen("namesort.txt","wb"))==NULL){printf("cannotopennsort.c");returnERROR;}for(i=2;i<=N;i++){if(strcmp(stu[i].name,stu[i-1].name)<0){strcpy(stu[0].name,stu[i].name);stu[0].num=stu[i9、].num;stu[0].room=stu[i].room;strcpy(stu[i].name,stu[i-1].name);stu[i].num=stu[i-1].num;stu[i].room=stu[i-1].room;for(j=i-2;(strcmp(stu[0].name,stu[j].name))<0;j--){strcpy(stu[j+1].name,stu[j].name);stu[j+1].num=stu[j].num;stu[j+1].room=stu[j].room;}strcpy(stu[j+1].name,s10、tu[0].name);stu[j+1].num=stu[0].num;stu[j+1].room=stu[0].room;}}for(i=1;i<=N;i++){fwrite(&stu[i]
7、*****************************//***************************************************************/StatusNameSort(){//排序;inti,j;.....FILE*fpdata;FILE*fpnamesort;studentstu[MAXSIZE];if((fpdata=fopen("studata.txt","rb"))==NULL){printf("cannotopendata.cfile!");returnERROR;}for(i
8、=1;i<=N;i++){fread(&stu[i],sizeof(structstudent),1,fpdata);}fclose(fpdata);if((fpnamesort=fopen("namesort.txt","wb"))==NULL){printf("cannotopennsort.c");returnERROR;}for(i=2;i<=N;i++){if(strcmp(stu[i].name,stu[i-1].name)<0){strcpy(stu[0].name,stu[i].name);stu[0].num=stu[i
9、].num;stu[0].room=stu[i].room;strcpy(stu[i].name,stu[i-1].name);stu[i].num=stu[i-1].num;stu[i].room=stu[i-1].room;for(j=i-2;(strcmp(stu[0].name,stu[j].name))<0;j--){strcpy(stu[j+1].name,stu[j].name);stu[j+1].num=stu[j].num;stu[j+1].room=stu[j].room;}strcpy(stu[j+1].name,s
10、tu[0].name);stu[j+1].num=stu[0].num;stu[j+1].room=stu[0].room;}}for(i=1;i<=N;i++){fwrite(&stu[i]
此文档下载收益归作者所有