《高级语言程序设计》课程设计
说明书
设计题目: 学生宿舍管理系统
目 录
一、总体设计…………………………………………………………………… 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. 函数原型声明
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、退出
三、小结
通过编写该程序,熟悉了C语言的基本语法,选择,循环等结构,深入练习了函数的调用方法,和文件的读写方法,熟悉了结构体的使用,更加深化了面向过程语言思想,和一些基本算法。
通过对程序的后期调试,熟悉了C常见错误,锻炼了思维的严密性,和完备性。
通过对程序的注释和画流程图,形成了一套自己编程的风格,和清晰地思路,使思维更加条理化,清晰化。
四、参考文献
[1]谭浩强.C程序设计(第二版).北京:清华大学出版社,1999
[2]邓文新.张宏烈.哈尔滨工业大学出版社
[3]百度.
五、附件源程序代码
#include<stdio.h>
#include<malloc.h>
#include<string.h>
#include <stdlib.h>
struct room
{
int Lnum;
int Fnum;
int squa;
int 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 room *)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");
printf("请选择服务项目!\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");
continue;}
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("%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("请输入要登记的入房数:\n");
scanf("%d",&n);
printf("请输入入住信息:\n楼号 房号 面积 最大入住人数 已入住人数\n");
printf("数据须按规定顺序输入,不同数据用空格分开。\n");
for(i=0;i<n;i++)
{
p=(struct room*)malloc(sizeof(struct room));
flushall();
scanf("%d%d%d%d%d",&p->Lnum,&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)
{
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("无信息可显示!\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;
}
}
}
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==NULL)
{
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楼号 房号 面积 所容纳人数 已入住人数\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);
}
}
}
struct room *sort(struct room *h)//修改点
{
struct room *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->innum<p1->innum&&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=(struct room *)malloc(sizeof(struct room));//修改点
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;
return h;//修改点
}
void can()
{
printf("欢迎再次使用学生宿舍管理系统!再见~\n");
}
电子信息科学与技术专业课程设计题单班级_***_学生***课程名称专业课程设计_课题密码锁的设计设计要求利用visualc#作为前…
数据库课程设计报告指导老师贺亚茹组名组长组员完成日期成绩数据库课程设计报告一项目名称学生信息管理系统二项目需求分析1项目需求分析简…
C语言课程设计报告一问题描述题目七学生成绩管理系统设计学生成绩信息包括学期学号班别姓名四门课程成绩语文数学英语和计算机等主要功能1…
java学生成绩管理系统课程设计报告以及代码共享Java语言课程期末作业题目第9题学生成绩管理系统学院计算机学院专业计算机科学与技…
山东交通学院数据库课程设计学生学籍管理系统院系别信息科学与电气工程学院班级学号姓名指导教师时间课程设计任务书题目学生学籍管理系统系…
毕业设计论文开题报告20xx届毕业设计论文题目院系电气与电子工程学院专业名称电子信息工程学生姓名学生学号指导教师XXXX学院学生毕…
毕业设计论文开题报告题目通用学生宿舍管理系统计算机科学与工学院班级学生姓名开题日期程学院专业学号指导教师20xx314计技术算机科…
学生宿舍管理系统可行性分析报告学生宿舍管理系统可行性分析报告绪论管理信息系统在现代社会已深入到各行各业由于计算机技术的迅速发展和普…
学生宿舍管理系统可行性分析报告学生宿舍管理系统可行性分析报告信息071班王君军070814128绪论管理信息系统在现代社会已深入到…
北京科技大学天津学院本科生毕业设计论文选题报告目录1文献综述211宿舍管理系统概述212本课题国外研究进展213本课题国内研究进展…