《宿舍管理系统源代码》由会员分享,可在线阅读,更多相关《宿舍管理系统源代码(11页珍藏版)》请在金锄头文库上搜索。
1、#include #include #include typedef struct Studentchar name20;char sex5;int age;char institute20;char specialty30;Student;typedef struct Roomint roomnum;int roomarea;int totalnum;int stunum;Student stu10;Room *next;Room;typedef struct Storychar storynum;Room *room;Story; /*-*/ Student *StudentCreat(i
2、nt age,char name,char institute,char specialty,char sex) Student *Stu;Stu=(Student *)malloc(sizeof(Student);Stu-age=age;strcpy(Stu-institute,institute);strcpy(Stu-name,name);strcpy(Stu-specialty,specialty);strcpy(Stu-sex,sex);return Stu; Room *RoomCreat(int room_num,int room_area,int total_num,int s
3、tu_num) Room *R;int i;R=(Room *)malloc(sizeof(Room);if(!R)return NULL;R-roomnum=room_num;R-roomarea=room_area;R-totalnum=total_num;R-stunum=stu_num;R-next=NULL;return R; Story *StoryCreat() Story *S;S=(Story *)malloc(sizeof(Story);S-room=RoomCreat(0,0,0,0);return S; Story *DormCreat() Story *S,*cont
4、rol;char i;control=(Story *)malloc(26*sizeof(Story);if(!control)return NULL;for(i=A;istorynum=i;controli-A=*S;return control; /*-*/ Story *StorySearch(Story *control,char storynum) return control+(storynum-A); Room *RoomSearch(Room *R,int room_num) while(R-next!=NULL)if(R-next-roomnum=room_num)break
5、;else R=R-next;return R; Student *StudentSearch(Room *R,char name) Student *p;int i;R=R-next;p=R-stu;for(i=0;istunum;i+)if(strcmp(p-name,name)=0)return p;else p+;return NULL; /*-*/ void RoomInsert(Story *S,Room *R) R-next=S-room-next;S-room-next=R; void StudentInsert(Room *R,Student *Stu) R=R-next;R
6、-stuR-stunum=*Stu;R-stunum+; void RoomDelete(Room *R) Room *p;R=R-next;p=R;R=R-next;free(p); void StudentDelete(Room *R,Student *Stu) R=R-next;Student *p;for(p=R-stu;Stustunum-1;Stu+)*Stu=*(Stu+1);R-stunum-; void RoomRevamp(Room *R) int i,k;R=R-next;printf(“1、房号 2、面积 3、可容纳人数:n“);printf(“要修改那一项:n“);
7、scanf(“%d“,switch(i)case 1:printf(“房号:“);scanf(“%d“,R-roomnum=k;break;case 2:printf(“面积:“);scanf(“%d“,R-roomarea=k;break;case 3:printf(“可容纳人数:“);scanf(“%d“,R-totalnum =k;break; void StudentRevamp(Student *Stu) int i,k;char str30; printf(“1、姓名 2、性别 3、学院 4、专业 5、年龄:n“);printf(“要修改那一项:n“); scanf(“%d“,sw
8、itch(i)case 1:printf(“姓名:“);scanf(“%s“,str);strcpy(Stu-name,str);break;case 2:printf(“性别:“);scanf(“%s“,str);strcpy(Stu-sex,str);break;case 3:printf(“学院:“);scanf(“%s“,str);strcpy(Stu-institute,str);break;case 4:printf(“专业:“);scanf(“%s“,str);strcpy(Stu-specialty,str);break;case 5:printf(“年龄:“);scanf(“
9、%d“,Stu-age =k;break; /*-*/ void RoomScan(Room *R) int i;Student *p;R=R-next;printf(“房号:%dn“,R-roomnum);printf(“面积:%dn“,R-roomarea);printf(“可容纳人数:%dn“,R-totalnum);printf(“已住入人数:%dn“,R-stunum);printf(“成员:“);for(i=0;istunum;i+)p=printf(“%s “,p-name);putchar(n); void StudentScan(Student *Stu) printf(“姓
10、名:%sn“,Stu-name);printf(“年龄:%dn“,Stu-age);printf(“性别:%sn“,Stu-sex);printf(“学院:%sn“,Stu-institute);printf(“专业:%sn“,Stu-specialty); int main() int roomnum,roomarea,totalnum,stunum,age; int event;char name20,institute20,specialty30,sex5;char storynum,judge;Story *control;Story *S;Room *R;Student *Stu;c
11、ontrol=DormCreat();doprintf(“*注意 *n“); printf(“* 先录入宿舍信息才能录入学生信息 *n“);printf(“* 先录入信息才能删除浏览或修改信息 *n“);printf(“* *n“);printf(“nnn 宿舍管理系统 nnn“);printf(“功能选择菜单:n“);printf(“1、宿舍信息录入 2、学生信息录入 3、删除某个宿舍 4、删除 某个学生n“);printf(“5、宿舍信息浏览 6、学生信息浏览 7、宿舍信息修改 8、学生 信息修改n“);scanf(“%d“,switch(event)case 1:doprintf(“请输
12、入宿舍房间号,房间面积,可容 纳人数,已住入人数:(以空格隔开)n“);fflush(stdin);scanf(“%c%d %d %d %d“,S=StorySearch(control,storynum);R=RoomCreat(roomnum,roomarea,totalnum,stunum);RoomInsert(S,R);printf(“宿舍信息录入成功!n“);fflush(stdin);printf(“是否继续录入宿舍信息(Y/N)n“);scanf(“%c“,while(judge=Y);break; case 2:doprintf(“请输入该生要入住的宿舍:n“);fflush
13、(stdin);scanf(“%c%d“,fflush(stdin);S=StorySearch(control,storynum); R=S-room;R=RoomSearch(R,roomnum);printf(“请输入该生姓名,性别,学院,专业, 年龄:(以空格隔开)n“);scanf(“%s%s%s%s“,name,sex,institute,specialty);scanf(“%d“, Stu=StudentCreat(age,name,institute,specialty,sex);StudentInsert(R,Stu);printf(“学生信息录入成功!n“);fflush(stdin);printf(“是否继续录入学生信息(Y/N)n“);scanf(“%c“,while(judge=Y);break; break; case 3:doprintf(“请输入要删除的宿舍号码:n“);fflush(stdin);scanf(“%c%d“,fflush(stdin);S=StorySearch(control,s