宿舍管理系统源代码

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includestdio.h#includestdlib.h#includestring.h#defineOVERFLOW0#defineOK1structstudent{intnum;//学号charname[20];//姓名intbanj;//班级intxingb;//性别(男生0、女生1)intsusenum;//宿舍号intbednum;//床位号intbianh;//学生编号};structstudents[10000];intn;//学生人数voidfenpei();//分配宿舍intmenu();//菜单函数intsusesy();//宿舍使用情况查询函数intenter();//登记入住学生信息intshow();//输出入住信息intsearch_name();//按姓名查找函数intsearch_num();//按学号查找函数intsearch_susenum();//按宿舍号查找函数inttuifa();//退房函数intxiugxxi();//修改入住信息函数intthuansuse();//调换寝室或床位函数voidbianx();//编写信息intread_file(structstudents[]);//voidwrite_file(structstudent*s);/*************************************************************//****函数实现******//*************************************************************/voidmain(){FILE*fp;intk=1;inti=0;charyesorno;printf(\n\n);printf(\t\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\n\n);printf(\t\t\t数据结构课程设计\n);printf(\t\t\t题目:宿舍管理系统\n);printf(\t\t\t姓名:付晓飞\n);printf(\t\t\t专业班级:10级软工一班\n);printf(\t\t\t学号:201003030029\n\n);printf(\t\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\5\n\n);if((fp=fopen(students.txt,rb+))==NULL){printf(\n=========提示:文件不存在,是否要创建一个?(y/n)\n);scanf(%c,&yesorno);if(yesorno=='y'||yesorno=='Y'){//这里仅为了建立文件fp=fopen(students.txt,wb+);fclose(fp);//关闭fp所指的文件,释放文件缓冲区}else{while(!feof(fp)){if(fread(&s[i],sizeof(structstudent),1,fp)!=1)break;i++;}n=i;fclose(fp);}}while(k){menu();}}intmenu(){inti;printf(\t***************************************************\n\n);printf(\t菜单\n\n);printf(\t***************************************************\n\n);printf(\t分配宿舍0宿舍使用情况查询1\n);printf(\t输出入住信息2按姓名查找3\n);printf(\t按学号查找4按宿舍号查询5\n);printf(\t退房函数6修改入住信息7\n);printf(\t调换宿舍8编写学生信息9\n);printf(\t请按提示进行自行选择:);scanf(%d,&i);switch(i){case0:fenpei();break;case1:susesy();break;case2:show();break;case3:search_name();break;case4:search_num();break;case5:search_susenum();break;case6:tuifa();break;case7:xiugxxi();break;case8:thuansuse();break;case9:bianx();break;}returnOK;}voidbianx(){structstudentt;inti,j;intc;intb[100];inta=0;FILE*fp=NULL;fp=fopen(students1.txt,wb+);printf(\t请输入班级总数:\n\t);scanf(%d,&c);printf(\t请依次输入每班人数:\n);for(i=0;ic;i++){printf(\t);scanf(%d,&b[i]);}printf(\t学生信息为:\n);for(i=0;ic;i++){//s[i].xueh=20120010001+i*10000;printf(\t请依次输入%d班学生姓名,学号,性别(男0,女1):\n,i+1);for(j=0;jb[i];j++){printf(\t);scanf(%s%d%d,&t.name,&t.num,&t.xingb);t.banj=i+1;s[i]=t;printf(%s%d%d%d\n,s[a].name,s[a].num,s[a].banj,s[a].xingb);a++;}}fwrite(s,sizeof(structstudent)*n,1,fp);fclose(fp);n=a;}voidfenpei(){inta,b,i,l,m;a=0;b=0;l=1;m=1;for(i=0;in;i++){if(s[i].xingb==0){if(a==6){s[i].susenum=l+1;a=1;l++;}else{s[i].susenum=l;a++;}s[i].bednum=a;}else{if(b==6){s[i].susenum=m+1;b=1;m++;}else{s[i].susenum=m;b++;}s[i].bednum=b;}}}//学生调换宿舍或者床位处理函数intthuansuse(){inti,j,l,m,a;into=n,p=n;chary[20];FILE*fp=NULL;fp=fopen(students1.txt,wb+);printf(\t请输入要调换的学生学号:);scanf(%d,%d,&l,&m);for(i=0;in;i++){if(s[i].num==l)o=i;}for(j=0;jn;j++){if(s[j].num==m)p=j;}if(o==n||p==n)printf(\t调换错误,请核对后再输入!\n);else{a=s[o].num;s[o].num=s[p].num;s[p].num=a;strcpy(y,s[o].name);strcpy(s[o].name,s[p].name);strcpy(s[p].name,y);printf(\t学号:%d姓名:%s宿舍号:%d床位号:%d\n,s[o].num,s[o].name,s[o].susenum,s[o].bednum);printf(\t学号:%d姓名:%s宿舍号:%d床位号:%d\n,s[p].num,s[p].name,s[p].susenum,s[p].bednum);printf(\t调换成功!\n);}fwrite(s,sizeof(structstudent)*n,1,fp);fclose(fp);returnOK;}//按学生学号查询函数intsearch_num(){inti,a=0;intfind_num;printf(\t请输入你要查询的学生学号:);scanf(%d,&find_num);for(i=0;in;i++){if(s[i].num==find_num){printf(\t学号:%d,s[i].num);printf(姓名:%s,s[i].name);printf(班级:%d,s[i].banj);printf(性别:%d,s[i].xingb);printf(宿舍号:%d,s[i].susenum);printf(床位号:%d,s[i].bednum);printf(\n);a=a+1;}}if(a==0)printf(\t不存在该学生!\n);returnOK;}//按学生姓名查询函数intsearch_name(){inti,b=0;charfind_name[20];FILE*fp=NULL;fp=fopen(students1.txt,wb+);printf(\t请输入你要查询的学生姓名:);scanf(%s,&find_name);for(i=0;in;i++){if(strcmp(s[i].name,find_name)==0){printf(\t学号:%d,s[i].num);printf(姓名:%s,s[i].name);printf(班级:%d,s[i].banj);printf(性别:%d,s[i].xingb);printf(宿舍号:%d,s[i].susenum);printf(床位号:%d\n,s[i].bednum);returni;b=1;}//elseprintf(\t不存在该学生!\n);}if(b==1)printf(\t不存在该学生!\n);else{fwrite(s,sizeof(structstudent)*n,1,fp);fclose(fp);}returnOK;}//按学生宿舍号查询函数intsearch_susenum(){inti,b=0;intfind_susenum;printf(\t请输入你要查询的宿舍号:);scanf(%d,&find_susenum);for(i=0;in;i++){if(s[i].susenum==find_susenum){printf(\t学号:%d,s[i].num);printf(姓名:%s,s[i].name);printf(班级:%d,s[i].banj);printf(性别:%d,s[i].xingb);printf(宿舍号:%d,s[i].susenum);printf(床位号:%d\n,s[i].bednum);b=1;}}if(b==0)printf(\t未分配该宿舍!\n);returnOK;}//查询宿舍使用情况函数intsusesy(){intsuse;inti;printf(\t请输入你要查询的宿舍号:);scanf(%d,&suse);for(i=0;in;i++){if(s[i].susenum==suse)search_susenum();}returnOK;}//修改学生入住信息函数intxiugxxi(){charxgname[20];inti,b=0;printf(\t请输入你要修改的学生姓名:);scanf(%s,&xgname);for(i=0;in;i++){if(strcmp(s[i].name,xgname)==0){printf(\t修改为:\n);printf(\t学号姓名班级性别宿舍号床位号:);scanf(%d%s%d%d%d%d,&s[i].num,s[i].name,&s[i].banj,&s[i].xingb,&s[i].susenum,&s[i].bednum);b=1;

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功