C语言课程设计报告学生宿舍管理系统方案.docx
《C语言课程设计报告学生宿舍管理系统方案.docx》由会员分享,可在线阅读,更多相关《C语言课程设计报告学生宿舍管理系统方案.docx(18页珍藏版)》请在冰豆网上搜索。
C语言课程设计报告学生宿舍管理系统方案
《高级语言程序设计》课程设计
说明书
设计题目:
学生宿舍管理系统
一、总体设计……………………………………………………………………3
1.程序的总体设计…………………………………………………………3
2.函数原型声明……………………………………………………………3
二、用户说明……………………………………………………………………4
1、菜单界面………………………………………………………………5
2、入住登记界面……………………………………………………………5
3、删除界面…………………………………………………………………5
4、浏览界面…………………………………………………………………6
5、查询修改…………………………………………………………………6
6、排序界面…………………………………………………………………6
7、退出………………………………………………………………………6
三、小结…………………………………………………………………………7
四、参考文献……………………………………………………………………7
五、源程序代码…………………………………………………………………7
一、总体设计
1.程序的总体设计
◎确定界面,使用户可选择操作项目(录入,删除,浏览,修改,查询,排序)。
◎录入:
使用结构体,要求用户输入楼栋、房号、面积、可住人数、已住人数
◎删除:
按房号删除以上信息
◎查询:
按房号查询以上信息
◎修改:
按房号修改以上信息
◎排序:
按已住人数排序信息
2.函数原型声明
structroom*add(structroom*head);//添加函数
structroom*del(structroom*h);//删除函数
voidshow(structroom*h);//信息浏览函数
voidserh(structroom*h);//查询与修改函数
structroom*sort(structroom*head);//排序函数
voidcan();//结束函数
二、用户使用说明
运行程序后即可按提示模仿以上操作进行。
1、菜单界面
2、入住登记界面
3、删除界面
4、浏览界面
5、查询修改
6、排序界面
7、退出
三、小结
通过编写该程序,熟悉了C语言的基本语法,选择,循环等结构,深入练习了函数的调用方法,和文件的读写方法,熟悉了结构体的使用,更加深化了面向过程语言思想,和一些基本算法。
通过对程序的后期调试,熟悉了C常见错误,锻炼了思维的严密性,和完备性。
通过对程序的注释和画流程图,形成了一套自己编程的风格,和清晰地思路,使思维更加条理化,清晰化。
四、参考文献
[1]谭浩强.C程序设计(第二版).:
清华大学,1999
[2]邓文新.宏烈.工业大学
[3]XX.
五、附件源程序代码
#include
#include
#include
#include
structroom
{
intLnum;
intFnum;
intsqua;
intmaxnum;
intinnum;
structroom*next;
};
structroom*add(structroom*head);//添加函数
structroom*del(structroom*h);//删除函数
voidshow(structroom*h);//信息浏览函数
voidserh(structroom*h);//查询与修改函数
structroom*sort(structroom*head);//排序函数//修改点
voidcan();//结束函数
voidmain()
{
structroom*head;
intx,y;
head=(structroom*)malloc(sizeof(structroom));
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");
printf("请选择服务项目!
\n");
flushall();
scanf("%d",&x);//菜单选择
if(head->next==NULL&&x!
=1&&x!
=6)
{
printf("系统中无入住信息,请先进行入房登记!
\n");
gotoA;
}
switch(x)
{
case1:
head=add(head);
system("cls");
printf("登记完毕!
\n");
continue;
case2:
head=del(head);
T:
scanf("%d",&y);
while(y!
=1&&y!
=0)
{
printf("输入错误!
请重新输入!
\n");
gotoT;
}
if(y==1)
{system("cls");
continue;}
else
can();
gotoN;
case3:
show(head);
printf("是否返回菜单界面进行其他操作?
(1/0)\n");
J:
scanf("%d",&y);
while(y!
=1&&y!
=0)
{
printf("输入错误!
请重新输入!
\n");
gotoJ;
}
if(y==1)
{system("cls");
continue;}
else
{
can();
gotoN;
}
case4:
serh(head);
system("cls");
continue;
case5:
head=sort(head);//修改点
printf("是否返回菜单界面进行其他操作?
(1/0)\n");
scanf("%d",&y);
while(y!
=1&&y!
=0)
{
printf("输入错误!
请重新输入!
\n");
gotoJ;
}
if(y==1)
{system("cls");
continue;}
else
{
can();
gotoN;
}
continue;
case6:
can();
gotoQ;
default:
printf("输入错误!
请重新输入!
\n");
}
N:
if(y==0)
break;
Q:
if(x==6)
break;
}
}
structroom*add(structroom*head)//入住登记
{
structroom*h,*p;
inti=0,n;
h=head;
printf("请输入要登记的入房数:
\n");
scanf("%d",&n);
printf("请输入入住信息:
\n楼号房号面积最大入住人数已入住人数\n");
printf("数据须按规定顺序输入,不同数据用空格分开。
\n");
for(i=0;i{
p=(structroom*)malloc(sizeof(structroom));
flushall();
scanf("%d%d%d%d%d",&p->Lnum,&p->Fnum,&p->squa,&p->maxnum,&p->innum);
p->next=h->next;
h->next=p;
}
returnh;
}
structroom*del(structroom*h)//退房登记
{
intx;
structroom*p,*q;
p=h->next;
q=h;
printf("请输入退房房号:
\n");
scanf("%d",&x);
if(p==NULL)
{
printf("不存在此入房登记!
\n是否返回菜单界面进行其他操作?
(1/0)");
}
else
{
while(p)
{
if(p->Fnum==x)
{
q->next=p->next;
free(p);
printf("删除成功!
是否返回菜单界面进行其他操作?
(1/0)\n");
gotoK;
}
else
{
q=p;
p=p->next;
}
}
if(p==NULL)
{
printf("不存在此入房登记!
\n是否返回菜单界面进行其他操作?
(1/0)\n");
}
K:
returnh;
}
returnh;
}
voidshow(structroom*h)
{
structroom*p;
p=h->next;
if(p==NULL)
{
printf("无信息可显示!
\n");
}
else
{
printf("\n楼号房号面积所容纳人数已入住人数\n\n");
while(p)
{
printf("%-7d%-7d%-8d%-13d%-8d\n",p->Lnum,p->Fnum,p->squa,p->maxnum,p->innum);
p=p->next;
}
}
}
voidserh(structroom*h)//入住信息查询与修改
{
structroom*p;
intx,y,z;
p=h->next;
H:
printf("请输入要查找的房号:
\n");
scanf("%d",&z);
while(p->Fnum!
=z)
{
p=p->next;
if(p==NULL)
break;
}
if(p==NULL)
{
printf("您所查询的房间号无人入住!
是否继续查找?
(1/0)\n");
Z:
scanf("%d",&x);
while(x!
=1&&x!
=0)
{
printf("输入错误!
请重新输入!
\n");
gotoZ;
}
if(x==1)
gotoH;
}
else
{
printf("查询结果如下:
\n");
printf("\n楼号房号面积所容纳人数已入住人数\n\n");
printf("%-7d%-7d%-8d%-13d%-8d\n",p->Lnum,p->Fnum,p->squa,p->maxnum,p->innum);
printf("如需修改请选择1,按其他任意键返回菜单界面\n");
scanf("%d",&y);
if(y==1)
{
printf("请对入住信息进行修改(按顺序输入)\n");
scanf("%d%d%d%d%d",&p->Lnum,&p->Fnum,&p->squa,&p->maxnum,&p->innum);
printf("修改成功!
修改结果如下:
\n");
printf("\n楼号房号面积所容纳人数已入住人数\n\n");
printf("%-7d%-7d%-8d%-13d%-8d\n",p->Lnum,p->Fnum,p->squa,p->maxnum,p->innum);
}
}
}
structroom*sort(structroom*h)//修改点
{
structroom*p1,*p2,*t,*temp,*q;/*定义临时指针*/
temp=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)/*p1==p2,说明待排序点值大,应排在首位*/
{
t->next=p1;/*待排序点的后继为p*/
h=t;/*新头结点为待排序点*/
}
else/*待排序点应插入在中间某个位置p2和p1之间,如p为空则是尾部*/
{
t->next=p1;/*t的后继是p1*/
p2->next=t;/*p2的后继是t*/
}
}
q=(structroom*)malloc(sizeof(structroom));//修改点
q->next=h;//修改点
while(h->next!
=NULL)
{
printf("%-7d%-7d%-8d%-13d%-8d\n",h->Lnum,h->Fnum,h->squa,h->maxnum,h->innum);
h=h->next;
}
h=q;
returnh;//修改点
}
voidcan()
{
printf("欢迎再次使用学生宿舍管理系统!
再见~\n");
}