1、C语言课程设计报告学生宿舍管理系统方案高级语言程序设计课程设计说明书设计题目: 学生宿舍管理系统 一、总体设计 3 1程序的总体设计 32. 函数原型声明 3二、用户说明 4 1、菜单界面 52、入住登记界面 53、删除界面 54、浏览界面 65、查询修改 66、排序界面 67、退出 6三、小结 7四、参考文献 7 五、源程序代码 7 一、总体设计1程序的总体设计 确定界面,使用户可选择操作项目(录入,删除,浏览,修改,查询,排序)。 录入:使用结构体,要求用户输入 楼栋、房号、面积、可住人数、已住人数 删除:按房号删除以上信息 查询:按房号查询以上信息修改:按房号修改以上信息排序:按已住人数
2、排序信息2. 函数原型声明struct room *add(struct room *head);/添加函数struct room *del(struct room *h);/删除函数void show(struct room *h);/信息浏览函数void serh(struct room *h);/查询与修改函数struct room *sort(struct room *head);/排序函数void can();/结束函数 二、用户使用说明运行程序后即可按提示模仿以上操作进行。 1、菜单界面 2、入住登记界面 3、删除界面 4、浏览界面 5、查询修改 6、排序界面 7、退出 三、小结通
3、过编写该程序,熟悉了C语言的基本语法,选择,循环等结构,深入练习了函数的调用方法,和文件的读写方法,熟悉了结构体的使用,更加深化了面向过程语言思想,和一些基本算法。通过对程序的后期调试,熟悉了C常见错误,锻炼了思维的严密性,和完备性。通过对程序的注释和画流程图,形成了一套自己编程的风格,和清晰地思路,使思维更加条理化,清晰化。四、参考文献1谭浩强.C程序设计(第二版).:清华大学,19992邓文新.宏烈.工业大学3XX.五、附件源程序代码#include#include#include#include struct room int Lnum; int Fnum; int squa; int
4、maxnum; int innum; struct room *next;struct room *add(struct room *head);/添加函数struct room *del(struct room *h);/删除函数void show(struct room *h);/信息浏览函数void serh(struct room *h);/查询与修改函数struct room *sort(struct room *head);/排序函数/修改点void can();/结束函数void main() struct room *head; int x,y; head=(struct ro
5、om *)malloc(sizeof(struct room); head-next=NULL; printf(欢迎使用学生宿舍管理系统!n); printf(按回车键进入菜单界面n); getchar(); while(1) A: printf(-n); printf(|-|n); printf(| 1.入住登记 |n); printf(| 2.删除信息 |n); printf(| 3.信息浏览 |n); printf(| 4.查询修改 |n); printf(| 5.按入住人数排序 |n); printf(| 6.退出系统 |n); printf(|-|n); printf(-n); pr
6、intf(请选择服务项目!n); flushall(); scanf(%d,&x);/菜单选择 if(head-next=NULL&x!=1&x!=6) printf(系统中无入住信息,请先进行入房登记!n); goto A; switch(x) case 1: head=add(head); system(cls); printf(登记完毕!n); continue; case 2: head=del(head);T: scanf(%d,&y); while(y!=1&y!=0) printf(输入错误!请重新输入!n); goto T; if(y=1) system(cls); conti
7、nue; else can(); goto N; case 3: show(head); printf(是否返回菜单界面进行其他操作?(1/0)n);J: scanf(%d,&y); while(y!=1&y!=0) printf(输入错误!请重新输入!n); goto J; if(y=1) system(cls); continue; else can(); goto N; case 4: serh(head); system(cls); continue; case 5: head=sort(head);/修改点 printf(是否返回菜单界面进行其他操作?(1/0)n); scanf(%
8、d,&y); while(y!=1&y!=0) printf(输入错误!请重新输入!n); goto J; if(y=1) system(cls); continue; else can(); goto N; continue; case 6: can(); goto Q; default: printf(输入错误!请重新输入!n); N: if(y=0) break;Q: if(x=6) break; struct room *add(struct room *head)/入住登记 struct room *h,*p; int i=0,n; h=head; printf(请输入要登记的入房数
9、:n); scanf(%d,&n); printf(请输入入住信息:n楼号 房号 面积 最大入住人数 已入住人数n); printf(数据须按规定顺序输入,不同数据用空格分开。n); for(i=0;iLnum,&p-Fnum,&p-squa,&p-maxnum,&p-innum); p-next=h-next; h-next=p; return h;struct room *del(struct room *h)/退房登记 int x; struct room *p,*q; p=h-next; q=h; printf(请输入退房房号:n); scanf(%d,&x); if(p=NULL)
10、printf(不存在此入房登记!n是否返回菜单界面进行其他操作?(1/0)); else while(p) if(p-Fnum=x) q-next=p-next; free(p); printf(删除成功!是否返回菜单界面进行其他操作?(1/0)n); goto K; else q=p; p=p-next; if(p=NULL) printf(不存在此入房登记!n是否返回菜单界面进行其他操作?(1/0)n); K: return h; return h; void show(struct room *h) struct room *p; p=h-next; if(p=NULL) printf(
11、无信息可显示!n); else printf(n楼号 房号 面积 所容纳人数 已入住人数nn); while(p) printf(%-7d%-7d%-8d%-13d%-8dn,p-Lnum,p-Fnum,p-squa,p-maxnum,p-innum); p=p-next; void serh(struct room *h)/入住信息查询与修改 struct room *p; int x,y,z; p=h-next;H: printf(请输入要查找的房号:n); scanf(%d,&z); while(p-Fnum!=z) p=p-next; if(p=NULL) break; if(p=NU
12、LL) printf(您所查询的房间号无人入住!是否继续查找?(1/0)n);Z: scanf(%d,&x); while(x!=1&x!=0) printf(输入错误!请重新输入!n); goto Z; if(x=1) goto H; else printf(查询结果如下:n); printf(n楼号 房号 面积 所容纳人数 已入住人数nn); printf(%-7d%-7d%-8d%-13d%-8dn,p-Lnum,p-Fnum,p-squa,p-maxnum,p-innum); printf(如需修改请选择1,按其他任意键返回菜单界面n); scanf(%d,&y); if(y=1) p
13、rintf(请对入住信息进行修改(按顺序输入)n); scanf(%d%d%d%d%d,&p-Lnum,&p-Fnum,&p-squa,&p-maxnum,&p-innum); printf(修改成功!修改结果如下:n); printf(n楼号 房号 面积 所容纳人数 已入住人数nn); printf(%-7d%-7d%-8d%-13d%-8dn,p-Lnum,p-Fnum,p-squa,p-maxnum,p-innum); struct room *sort(struct room *h)/修改点 struct room *p1,*p2,*t,*temp,*q; /*定义临时指针*/ tem
14、p=h-next; /*将原表的头指针所指的下一个结点作头指针*/ h-next=NULL; /*第一个结点为新表的头结点*/ while(temp!=NULL) /*当原表不为空时,进行排序*/ t=temp; /*取原表的头结点*/ temp=temp-next; /*原表头结点指针后移*/ p1=h; /*设定移动指针p1,从头指针开始*/ p2=h; /*设定移动指针p2做为p1的前驱,初值为头指针*/ while(t-innuminnum&p1!=NULL) /*作成绩平均分比较*/ p2=p1; /*待排序点值小,则新表指针后移*/ p1=p1-next; if(p1=p2) /*
15、p1=p2,说明待排序点值大,应排在首位*/ t-next=p1; /*待排序点的后继为p*/ h=t; /*新头结点为待排序点*/ else /*待排序点应插入在中间某个位置p2和p1之间,如p为空则是尾部*/ t-next=p1; /*t的后继是p1*/ p2-next=t; /*p2的后继是t*/ q=(struct room *)malloc(sizeof(struct room);/修改点 q-next=h;/修改点 while (h-next!=NULL) printf(%-7d%-7d%-8d%-13d%-8dn,h-Lnum,h-Fnum,h-squa,h-maxnum,h-innum); h=h-next; h=q; return h;/修改点 void can() printf(欢迎再次使用学生宿舍管理系统!再见n);
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2