收藏 分销(赏)

【C语言实战应用】客房管理系统报告.doc

上传人:仙人****88 文档编号:6649256 上传时间:2024-12-19 格式:DOC 页数:22 大小:106.04KB
下载 相关 举报
【C语言实战应用】客房管理系统报告.doc_第1页
第1页 / 共22页
【C语言实战应用】客房管理系统报告.doc_第2页
第2页 / 共22页
【C语言实战应用】客房管理系统报告.doc_第3页
第3页 / 共22页
【C语言实战应用】客房管理系统报告.doc_第4页
第4页 / 共22页
【C语言实战应用】客房管理系统报告.doc_第5页
第5页 / 共22页
点击查看更多>>
资源描述

1、C语言实践应用客房管理系统一总体设计本程序包含用户登记、统计、查询、修改等四大功能。其中用户登记功能包含用户姓名、性别、年龄、身份证、入住年份、入住月份、入住日期、房间号、房间电话及房间价格;统计功能包含按性别统计、按年龄统计及按入住时间(年月日)统计;查询功能包含按房间号查询、按姓名查询及按性别查询;修改功能包含性别修改、年龄修改、入住年份修改、入住月份修改及入住日期修改。下面以流程图的形式展示本程序设计思路: 开始 输出 1.登记2.统计3.查询4.修改5.退出 输入 n=1选择用户登记功能 输入用户信息及客房信息 系统自动分配房间号 是否继续输入用户信息输入k k=1? 是 否 输出 1

2、.登记2.统计3.查询4.修改5.退出 输入n 功能菜单选择 n=2 n=3 n=4 n=5 退出输入姓名输出1.按房间号2.按姓名3. 按性别查询输出1.按性别统计2.按年龄统计3.按入住日期统计 结束输出用户信息 输出1.性别2.年龄3.年份4.月份5.日期输入i输入i 输入a i=1 i=2 i=3 i=1 i=2 i=3 输入性别输入姓名 输入房间号输出各日期段人数 输出各年龄段人数输出男女性别人数 输入k 输入日期输入月份输入年份输入年龄输入性别 a=1 a=2 a=3 a=4 a=5输入kk=1 k=1?k=1 k=1? k=1 k=1? 是 是 是 否 否 否二设计模块一个较大的

3、C语言程序不外乎由多个函数组成,本程序也并不例外。现就本程序中涉及的各个函数的代码和功能分别进行说明。1.main函数void main()ini();menu();本函数用于调用ini函数和menu函数(介绍见下文)。2.ini函数void ini()int i=0;for(;i100;i+)Roomi.sign=false;Roomi.Room_ID=i;本函数功能为先定义所有的房间为空并依次定义各个房间的序号。3.menu函数void menu()int n,k;doprintf(1.登记n);printf(2.统计n);printf(3.查询n);printf(4.修改n);print

4、f(5.退出n);printf(Choice your number(1-5):);scanf(%d,&n);if(n5)k=1;puts(Please enter againn);else k=0;while(k=1);switch(n)case 1:dengji();break;case 2:tongji();break;case 3:chaxun();break;case 4:xiugai();break; case 5:exit(0);本函数的功能为输出功能菜单选项,其中包括登记、统计、查询、修改及退出。系统根据输入的选项调用相应的功能函数。4.dengji函数void dengji(

5、)int k=1,i=0;while(k)printf(Please enter the Name:);scanf(%s,Roomi.Client_list.Name);printf( Please enter the Sex, Men 1, Women 2 :);scanf(%d,&Roomi.Client_list.Sex);printf(Please enter the Age:); scanf(%d,&Roomi.Client_list.Age);printf(Please enter the ID_card:);scanf(%d,&Roomi.Client_list.ID_card)

6、;printf(Please enter the year:);scanf(%d,&Roomi.Client_list.year);printf(Please enter the month:);scanf(%d,&Roomi.Client_list.month);printf(Please enter the date:);scanf(%d,&Roomi.Client_list.date);printf(Please enter the Tel:);scanf(%d,&Roomi.Tel);printf(Please enter the Price:);scanf(%d,&Roomi.Pri

7、ce);Roomi.sign=true;printf(The Room_ID is:%dn,Roomi.Room_ID);i+;printf(Do you want to continue?, Yes 1, No 0: );scanf(%d,&k);if(k!=1&k!=0)printf(You have entered the wrong number, please enter againn);printf(Do you want to continue?, Yes 1, No 0: );scanf(%d,&k);menu();本函数的功能为登记用户及房间信息,包括姓名、性别、年龄、身份证

8、、年份、月份、日期、房间电话及房间价格。系统依次分配房间号并定义此房间为非空。管理员可根据具体情况登记相应用户人数的信息。在此申明由于本程序并未将用户信息存入磁盘,因此务必先登记用户信息再执行功能菜单中的其他功能。5.tongji函数void tongji()int i;printf(1.According to the sex 2.According to the age 3.According to the time:);scanf(%d,&i);if(i!=1&i!=2&i!=3)printf(You have entered the wrong number, please enter

9、 againn);tongji();switch(i)case 1: xingbie();break;case 2: nianling();break;case 3: shijian();break; 本函数的功能为输出统计功能菜单选项,包括根据按性别统计、根据年龄统计及根据入住时间统计。系统根据输入的选项执行相应的函数(介绍见下文)。6.xingbie函数void xingbie()int i,a=0,b=0,k=0;for(i=0;Roomi.sign;+i)switch(Roomi.Client_list.Sex)case 1:a+;break;case 2:b+;break;print

10、f(Men:%dn Women:%dn,a,b);printf(Do you want to continue? Yes 1, No 0: );scanf(%d,&k);if(k!=1&k!=0)printf(You have entered the wrong number, please enter againn);printf(Do you want to continue?, Yes 1, No 0: );scanf(%d,&k);if(k) tongji();else menu(); 本函数的功能为分别输出用户中男女性别的人数。7.nianling函数void nianling()i

11、nt i,a=0,b=0,c=0,k=0;for(i=0;Roomi.sign;i+)switch(Roomi.Client_list.Age/20)case 0:a+;break;case 1:b+;break;default:c+;printf(Age20:%dn20=Age=40:%dn,a,b,c);printf(Do you want to continue? Yes 1, No 0: );scanf(%d,&k);if(k!=1&k!=0)printf(You have entered the wrong number, please enter againn);printf(Do

12、 you want to continue?, Yes 1, No 0: );scanf(%d,&k);if(k) tongji();else menu(); 本函数的功能为分别输出用户中年龄在20岁以下、20至40岁及40岁以上的人数。8.shijian函数void shijian()int i,a=0,b=0,c=0,d=0,e=0,f=0,g=0,h=0,j=0,k=0;for(i=0;Roomi.sign;i+)switch(Roomi.Client_list.year)case 2009:a+;break;case 2010:b+;break;for(i=0;Roomi.sign;i

13、+)if(Roomi.Client_list.date=10) c+;else if(Roomi.Client_list.date10) d+;else e+;for(i=0;Roomi.sign;i+)if(Roomi.Client_list.month=3) f+;else if(Roomi.Client_list.month3) g+;else if(Roomi.Client_list.month6) h+;else j+;printf(2009:%dn 2010:%dn month=3:%dn3month=6:%dn6month=9:%dn9month=12:%dn date=10:%

14、dn10date=20:%dn20date30:%dn,a,b,f,g,h,j,c,d,e);printf(Do you want to continue? Yes 1, No 0:);scanf(%d,&k);if(k!=1&k!=0)printf(You have entered the wrong number, please enter againn);printf(Do you want to continue?, Yes 1, No 0: );scanf(%d,&k);if(k) tongji();else menu(); 本函数的功能为分别输出用户中入住年份在2009年及2010

15、年的人数,入住月份在3月以下、3月至6月、6月至9月、9月至12月份的人数及入住日期在10日以下、10日至20日、20日以上的人数。9.shuchu函数void shuchu(int i)printf(Name:%s Sex: %d Age: %d ID_card: %d Time: %d-%d-%d Room_ID: %d Tel: %d Price: %dn,Roomi.Client_list.Name,Roomi.Client_list.Sex,Roomi.Client_list.Age,Roomi.Client_list.ID_card,Roomi.Client_list.year,R

16、oomi.Client_list.month,Roomi.Client_list.date,Roomi.Room_ID,Roomi.Tel,Roomi.Price);本函数的功能为输出相应用户及所在房间信息,包括姓名、性别、年龄、身份证、入住时间(年月日)、房间号、房间电话及房间价格。10.chaxunvoid chaxun()int i;printf(1.According to the Room_ID 2.According to the name 3.According to the sex:);scanf(%d,&i);if(i!=1&i!=2&i!=3)printf(You have

17、 entered the wrong number, please enter againn);chaxun();switch(i)case 1: Room_ID();break;case 2: name();break;case 3: Sex();break;本函数的功能为输出查询功能菜单选项,包括根据房间号查询、根据姓名查询及根据性别查询。系统根据输入的选项执行相应的函数(介绍见下文)。11.Room_ID函数void Room_ID()int i=0,a,k;printf(Please enter the Room_ID:);scanf(%d,&a);for(;i100;+i)if(Ro

18、omi.Room_ID=a)if(Roomi.sign=true) shuchu(i);else printf(There is no person in the roomn);break;printf(Do you want to continue? Yes 1, No 0:);scanf(%d,&k);if(k!=1&k!=0)printf(You have entered the wrong number, please enter againn);printf(Do you want to continue?, Yes 1, No 0: );scanf(%d,&k);if(k) cha

19、xun();else menu();本函数的功能为系统根据输入的房间号调出该房间中的用户信息及房间信息。12.name函数void name()int i=0,k,l=0;char str20;printf(Please enter the Name:);scanf(%s,str);for(;Roomi.sign;i+)if(strcmp(str,Roomi.Client_list.Name)=0) shuchu(i);l=1;if(!l) printf(There is not the personn);printf(Do you want to continue? Yes 1, No 0:

20、);scanf(%d,&k);if(k!=1&k!=0)printf(You have entered the wrong number, please enter againn);printf(Do you want to continue?, Yes 1, No 0: );scanf(%d,&k);if(k) chaxun();else menu();本函数的功能为系统根据输入的姓名调出该用户的信息及所在房间信息,若无此用户则输出查无此人。13.Sex函数void Sex()int i=0,k,a,l=0; printf(Please enter the sex, Men 1, Women

21、 2:);scanf(%d,&a);for(;Roomi.sign;+i)if(Roomi.Client_list.Sex=a) shuchu(i);l=1;if(!l) printf(There is no the sexn);printf(Do you want to continue? Yes 1, No 0:);scanf(%d,&k);if(k) chaxun();else menu();本函数的功能为系统根据输入的性别调出该性别的用户信息及所在房间信息。14.xiugai函数void xiugai()int i=0,k,a,l=0;char str20;printf(Please

22、enter the name:);scanf(%s,str);for(;Roomi.sign;+i) if(strcmp(str,Roomi.Client_list.Name)=0) l+;shuchu(i);break;if(!l)printf(You have entered the wrong name, please enter againn);xiugai();printf(What you want to corret is as follow:n1.Sex 2.Age 3.year 4.month 5.date:);scanf(%d,&a);if(a!=1&a!=2&a!=3&a

23、!=4&a!=5)printf(You have entered the wrong number, please enter againn);printf(What you want to corret is as follow:n1.Sex 2.Age 3.year 4.month 5.date:);scanf(%d,&a);switch(a)case 1:printf(Please enter the sex:);scanf(%d,&Roomi.Client_list.Sex);break;case 2:printf(Please enter the age:);scanf(%d,&Ro

24、omi.Client_list.Age);break;case 3:printf(Please enter the year:);scanf(%d,&Roomi.Client_list.year);break;case 4:printf(Please enter the month:);scanf(%d,&Roomi.Client_list.month);break;default:printf(Please enter the date:);scanf(%d,&Roomi.Client_list.date);printf(Do you want to continue? Yes 1, No

25、0:);scanf(%d,&k);if(k!=1&k!=0)printf(You have entered the wrong number, please enter againn);printf(Do you want to continue?, Yes 1, No 0: );scanf(%d,&k);if(k) xiugai();else menu();本函数的功能为系统根据输入的姓名调出该用户及所在房间信息,同时输出修改功能菜单选项,包括修改性别、修改年龄、修改入住年份、修改月份及修改日期。系统根据输入的选项修改用户相应的信息。三.结束语C语言是一门计算机语言,如同其他计算机语言甚至日

26、常交际中常说的外语一样需要不断的练习和实践才能逐渐掌握并熟练运用。尤其是对于带有创造性的编写一个较大C语言程序时更能凸现出这一点。由于本人学习该语言理论知识时间仓促加之课下没有进行大量的程序编写练习,因此在编写及调试本程序过程中难免遇到了诸多问题。现就出现的这些问题及解决办法作简要分析。1.设计思路起初对于本程序的思路都是一片空白,对于题目中要求实现的用户登记、统计、查询、修改功能不知如何实现,重新对书中有关循环、数组、结构体、文件等知识进行了回顾,并且读了一些相关例题。本程序包含用户登记、统计、查询、修改等四大功能。其中用户登记功能包含用户姓名、性别、年龄、身份证、入住年份、入住月份、入住日

27、期、房间号、房间电话及房间价格;统计功能包含按性别统计、按年龄统计及按入住时间(年月日)统计;查询功能包含按房间号查询、按姓名查询及按性别查询;修改功能包含性别修改、年龄修改、入住年份修改、入住月份修改及入住日期修改。按题目的要求,编写能实现相应功能的函数,最后再从主函数中调用这些函数来。2.联系实际在上机调试过程中经常出现输入未给出的选项,此时系统会发生各种难以预料的结果,为避免此类情况的发生,又反复对程序代码进行了修改,以便系统能对输入的各种选项进行正确处理。例如:void tongji()int i;printf(1.According to the sex 2.According to

28、 the age 3.According to the time:);scanf(%d,&i);if(i!=1&i!=2&i!=3)printf(You have entered the wrong number, please enter againn);tongji();switch(i)case 1: xingbie();break;case 2: nianling();break;case 3: shijian();break;若i的输入值不是1、2或3则输出输入错误,请重新输入。若不考虑此情况则上机调式时当输入错误i值时会结束程序,造成不便处理的麻烦。3.代码细节 在程序编译时常常会出现各种或多或少的错误提示,其原因往往是程序代码出现了一些细节上的简单错误,或是分号缺失,或是大括号不对应,或是未定义变量等各种常见错误。这些错误虽不是致命性的严重失误但却影响了程序的编译和连接,最终仍不能使程序正常执行。为了能够消除这些错误,必须不断地、反复地修改程序代码,并且不断的调试运行。

展开阅读全文
部分上传会员的收益排行 01、路***(¥15400+),02、曲****(¥15300+),
03、wei****016(¥13200+),04、大***流(¥12600+),
05、Fis****915(¥4200+),06、h****i(¥4100+),
07、Q**(¥3400+),08、自******点(¥2400+),
09、h*****x(¥1400+),10、c****e(¥1100+),
11、be*****ha(¥800+),12、13********8(¥800+)。
相似文档                                   自信AI助手自信AI助手
搜索标签

当前位置:首页 > 教育专区 > 小学其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        获赠5币

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4008-655-100  投诉/维权电话:4009-655-100

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :gzh.png    weibo.png    LOFTER.png 

客服