1、宿舍管理系统源代码#include #include#include typedef struct Student char name20; char sex5; int age; char institute20; char specialty30;Student;typedef struct Roomintroomnum;introomarea;inttotalnum;intstunum;Student stu10;Room *next;Room;typedef struct Storychar storynum;Room *room;Story;/* */Student *Student
2、Creat( 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, int
3、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;Story *Dorm
4、Creat()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 *Ri,nt room_num)while (R-next!=NULL)if (R
5、-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 StudentInsert(
6、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;printf(1 、房号 2 、面积 3 、
7、可容纳人数 :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;printf(1 、姓名 2 、性别
8、 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( 专业 :); scanf(%s,
9、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+)p=&(R-stui)
10、; 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,specialty30,se
11、x5; char storynum,judge;Story *control;Story *S;Room *R;Student *Stu;control=DormCreat();do注意printf( *n);*n);*n);printf( *n);printf(nnn 宿舍管理系统 nnn);printf( 功能选择菜单 :n);printf(1 、宿舍信息录入 2 、学生信息录入 3 、删除某个宿舍 4 、删 除某个学生 n);printf(5 、宿舍信息浏览 6 、学生信息浏览 7 、宿舍信息修改 8 、学 生信息修改 n);scanf(%d,&event);switch (event)
12、case 1:doprintf( 请输入宿舍房间号,房间面积,可 容纳人数,已住入人数 :( 以空格隔开 )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);printf( 宿舍信息录入成功! n);fflush(stdin);printf( 是否继续录入宿舍信息 (Y/N)n);scanf
13、(%c,&judge); while (judge=Y);break ;case 2:doprintf( 请输入该生要入住的宿舍 :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%s%s%s,name,sex,institute,specialty);scanf(%d,&age);Stu=St
14、udentCreat(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:doprintf( 请输入要删除的宿舍号码 :n); fflush(stdin);scanf(%c%d,&storynum,&roomnum);fflush(stdin); S=StorySearch(control,storynum
15、);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:doprintf( 请输入要删除学生现住宿舍 :n); fflush(stdin);scanf(%c%d,&storynum,&roomnum); fflush(stdin);S=StorySearch(control,storynum); R=S-room;R=Ro
16、omSearch(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:doprintf( 请输入要浏览的宿舍号码 :n); fflush(stdin);scanf(%c%d,&storynum,&roomnum);fflus
17、h(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:doprintf( 请输入要浏览学生的宿舍号 码:n);fflush(stdin); scanf(%c%d,&storynum,&roomnum);fflush(stdin);S=StorySearch(control,storynum);
18、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:doscanf(%c%d,&storynum,&roomnum);fflush(stdin);S=StorySearch(control,storynum);R=S-room;R=R
19、oomSearch(R,roomnum);RoomRevamp(R);printf( 宿舍信息修改成功! n);fflush(stdin);printf( 是否继续修改 (Y/N)n);scanf(%c,&judge); while (judge=Y);break ;break ;case 8:doprintf( 请输入要修改学生的宿舍号 码: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);
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1