1、#include#include#includetypedef struct Student char name20; char sex5; int age; char institute20; char specialty30; Student;typedef struct Room int roomnum; int roomarea; int totalnum; int stunum; Student stu10; Room *next; Room; typedef struct Story char storynum; Room *room; Story;/*-*/ Student *S
2、tudentCreat(int 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
3、,int total_num,int stu_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;St
4、ory *DormCreat() Story *S,*control; 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!=NU
5、LL) if(R-next-roomnum=room_num)break; 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 St
6、udentInsert(Room *R,Student *Stu) R=R-next; R-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
7、; printf(1、房号 2、面积 3、可容纳人数:n); printf(要修改那一项:n); scanf(%d,&i); switch(i) case 1: printf(房号:); scanf(%d,&k); R-roomnum=k; break; case 2: printf(面积:); scanf(%d,&k); R-roomarea=k; break; case 3: printf(可容纳人数:); scanf(%d,&k); R-totalnum =k; break; void StudentRevamp(Student *Stu) int i,k; char str30; pr
8、intf(1、姓名 2、性别 3、学院 4、专业 5、年纪:n); printf(要修改那一项:n); scanf(%d,&i); switch(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(专业:); scan
9、f(%s,str); strcpy(Stu-specialty,str); break; case 5: printf(年纪:); scanf(%d,&k); 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+)
10、 p=&(R-stui); printf(%s ,p-name); putchar(n);void StudentScan(Student *Stu) printf(姓名:%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,spec
11、ialty30,sex5; char storynum,judge; Story *control; Story *S; Room *R; Student *Stu; control=DormCreat(); do printf(*注意*n); printf(* 先录入宿舍信息才能录入学生信息 *n); printf(* 先录入信息才能删除浏览或修改信息 *n); printf(*n); printf(nnn 宿舍管理系统 nnn); printf(功效选择菜单:n); printf(1、宿舍信息录入 2、学生信息录入 3、删除某个宿舍 4、删除某个学生n); printf(5、宿舍信息浏览
12、6、学生信息浏览 7、宿舍信息修改 8、学生信息修改n); scanf(%d,&event); switch(event) case 1: do printf(请输入宿舍房间号,房间面积,可容纳人数,已住入人数:(以空格隔开)n); fflush(stdin); scanf(%c%d %d %d %d,&storynum,&roomnum,&roomarea,&totalnum,&stunum); S=StorySearch(control,storynum); R=RoomCreat(roomnum,roomarea,totalnum,stunum); RoomInsert(S,R); pr
13、intf(宿舍信息录入成功!n); fflush(stdin); printf(是否继续录入宿舍信息(Y/N)n); scanf(%c,&judge); while(judge=Y); break; case 2: do printf(请输入该生要入住宿舍:n); fflush(stdin); scanf(%c%d,&storynum,&roomnum); fflush(stdin); S=StorySearch(control,storynum); R=S-room; R=RoomSearch(R,roomnum); printf(请输入该生姓名,性别,学院,专业,年纪:(以空格隔开)n);
14、 scanf(%s%s%s%s,name,sex,institute,specialty); scanf(%d,&age); Stu=StudentCreat(age,name,institute,specialty,sex); StudentInsert(R,Stu); printf(学生信息录入成功!n); fflush(stdin); printf(是否继续录入学生信息(Y/N)n); scanf(%c,&judge); while(judge=Y); break; break; case 3: do printf(请输入要删除宿舍号码:n); fflush(stdin); scanf(
15、%c%d,&storynum,&roomnum); fflush(stdin); S=StorySearch(control,storynum); R=S-room; R=RoomSearch(R,roomnum); RoomDelete(R); printf(宿舍信息删除成功!n); fflush(stdin); printf(是否继续删除宿舍信息(Y/N)n); scanf(%c,&judge); while(judge=Y); break; break; case 4: do printf(请输入要删除学生现住宿舍:n); fflush(stdin); scanf(%c%d,&story
16、num,&roomnum); fflush(stdin); S=StorySearch(control,storynum); R=S-room; R=RoomSearch(R,roomnum); printf(请输入要删除学生姓名:n); scanf(%s,name); Stu=StudentSearch(R,name); StudentDelete(R,Stu); printf(学生信息删除成功!n); fflush(stdin); printf(是否继续删除学生信息(Y/N)n); scanf(%c,&judge); while(judge=Y); break; break; case 5
17、: do printf(请输入要浏览宿舍号码:n); fflush(stdin); scanf(%c%d,&storynum,&roomnum); fflush(stdin); S=StorySearch(control,storynum); R=S-room; R=RoomSearch(R,roomnum); RoomScan(R); fflush(stdin); printf(是否继续浏览宿舍(Y/N)n); scanf(%c,&judge); while(judge=Y); break; break; case 6: do printf(请输入要浏览学生宿舍号码:n); fflush(s
18、tdin); scanf(%c%d,&storynum,&roomnum); fflush(stdin); S=StorySearch(control,storynum); R=S-room; R=RoomSearch(R,roomnum); printf(请输入要浏览学生姓名:n); scanf(%s,name); Stu=StudentSearch(R,name); StudentScan(Stu); fflush(stdin); printf(是否继续浏览学生(Y/N)n); scanf(%c,&judge); while(judge=Y); break; break; case 7:
19、do printf(请输入要修改宿舍号码:n); fflush(stdin); scanf(%c%d,&storynum,&roomnum); fflush(stdin); S=StorySearch(control,storynum); R=S-room; R=RoomSearch(R,roomnum); RoomRevamp(R); printf(宿舍信息修改成功!n); fflush(stdin); printf(是否继续修改(Y/N)n); scanf(%c,&judge); while(judge=Y); break; break; case 8: do printf(请输入要修改学
20、生宿舍号码:n); fflush(stdin); scanf(%c%d,&storynum,&roomnum); fflush(stdin); S=StorySearch(control,storynum); R=S-room; R=RoomSearch(R,roomnum); printf(请输入要修改学生姓名:n); scanf(%s,name); Stu=StudentSearch(R,name); StudentRevamp(Stu); printf(学生信息修改成功!n); fflush(stdin); printf(是否继续修改(Y/N)n); scanf(%c,&judge); while(judge=Y); break; break; fflush(stdin); printf(是否继续其它操作(Y/N)n); scanf(%c,&judge); while(judge=Y); system(pause);