1、 三峡大学理学院级电子信息科学与技术专业 《高档语言程序设计》课程设计 阐明书 设计题目: 客房管理系统 班级: 1421 学号: 142139 姓名: 徐晶 完毕日期: -11-23 目录 一、 设计任务……………………(2) 二、 需求分析……………………(2) 三、 系统模块图…………………(2) 四、 模块阐明……………………(3) 五、 顾客阐明…………………(18) 六、 测试成果………………… (18) 七、 设计小结………………… (19) 八、 参照目录………………… (19) 一、设计任务:
2、客房管理系统 实现顾客登记功能,要提供构造体输入操作,实现记录功能,要提供相应记录操作,实现查询功能,要提供查找操作,实现修改功能,要提供修改操作;此外尚有提供键盘式菜单实现功能选取。 二、需求分析: 1. 总体分析:整个客房管理系统被设计为顾客登记模块,记录模块,查询模块,和修改模块。 2. 详细分析: (1) 顾客登记模块 提示顾客输入自身信息以及客房信息,把数据存入Room数组中。 (2) 记录模块18设立计数器,顺序遍历ROOM数组来实现,实现对房客数、某一天房客数记录。 (3) 查询模块 通过基本查找算法查找Room数组,可以按房间号、价格、房间标记、顾客姓名、居民身份
3、证查询。 (4) 修改模块 采用基本查找算法在数组找到要修改数据。 三、系统模块图 依照需求分析,可以对这个系统设计分为如下几种模块: 客户信息管理系统 数据输入 数据记录 数据查询 数据修改 数据删除 四、模块阐明: 一种较大C语言程序不外乎由各种函数构成,本程序也并不例外。现就本程序中涉及各个函数代码和功能分别进行阐明。 1、 主函数某些: 程序: void main() /**主函数**/ { int n,w; menu(); do { printf("\t\tPlease choice you
4、number(1-5)"); scanf("%d",&n); if(n<1||n>5) w=1,getchar(); else w=0; }while(w==1); switch(n) { case 1:regist();break; case 2:stati();break; case 3:search();break; case 4:modify();break; case 5:exit(0); } } void menu () /**菜单函
5、数**/ { printf("\t\t\t************客房管理系统************\n"); puts("\n\t\t\t (1).登记 \n"); puts("\t\t\t (2).记录 \n"); puts("\t\t\t (3).查询 \n"); puts("\t\t\t (4).修改 \n"); puts("\t\t\t (5).退出 \n"); puts("\n\t*************************************************
6、\n"); } void return_confirm(void) { printf("\n按任意键返回……\n"); getchar(); } #include "stdio.h" #include "string.h" //在使用中要用到字符串都包括在本文献中 #include "stdlib.h" #include "math.h" #define NUM 50 struct Client { char
7、Name[20]; int Sex;//famale 0,male 1; int Age; char ID_card[20]; /*居民身份证*/ int year; int month; int date; /*住店时间*/ }; struct Hotel { char Room_ID[10]; /*房间号*/ char
8、 Tel[10]; int Price; /*住房单价*/ int Sign; struct Client Client_list; /*实现两个构造体嵌套*/ }Room[NUM]; 注:menu函数能提供菜单方式选取功能,可以依照顾客需要进入到所想要操作模块中,此外把menu函数独立出来,可以以便随时对它进行调用,容易返回到系统界面。并用构造体来存储客户信息。 2、各功能模块函数某些: (1)输入模块:[需求分析] 对信息进行输入 程序: void regi
9、st() /**登记函数**/
{
void printf_one(int i);
void save(int n);
void printf_back();
int load();
void printf_face();
int i,n,c;
n=load();
do
{
for(i=0;i 10、
{
printf("Room[%s] has been full\n",Room[i].Room_ID);
}
else
{
puts("\nregister new record\n");
printf("\n Room[%s] is empty",Room[i].Room_ID);
printf("\nplease enter Room[%s]'s information",Roo 11、m[i].Room_ID);
puts("\nplease enter customer's Name\n");
scanf("%15s",&Room[i].Client_list.Name);
printf("\nplease enter Sex and Age\n");
scanf("%3d %3d",&Room[i].Client_list.Sex,&Room [i].Client_list.Age);
puts("\npleas 12、e enter customer's ID_card\n");
scanf("%20s",&Room[i].Client_list.ID_card);
printf("\nplease enter year and month and date\n");
scanf("%5d %5d %5d",&Room [i].Client_list.year,&Room[i].Client_list.month,&Room [i].Client_list.date);
13、 Room[i].Sign=1;//把房间标记为已满
printf_face();
printf_one(i);
printf("\n\n Are you sure?\n\n\t1.sure\t2.cancle and again\t3.Back without save [ ]\b\b");
scanf("%d",&c);
if(c==1)
{ save(n);
14、 printf_back();
}
else if(c!=2) menu();
}
}
}while(c==2);
return_confirm();
}
int load()
{
FILE *fp;
int i;
if((fp=fopen("Hotel.txt","r"))==NULL)
{
printf("\nCannot ope 15、n file\n");
exit(0);
}
for(i=0;!feof(fp);i++)
fscanf(fp,"\n%s%s%d%d%s%d%d%s%d%d%d\n",&Room [i].Room_ID,&Room[i].Tel,&Room[i].Price,
&Room[i].Sign,&Room[i].Client_list.Name,&Room [i].Client_list.Sex,
&Room[i].Client_l 16、ist.Age,&Room [i].Client_list.ID_card,
&Room[i].Client_list.year,&Room [i].Client_list.month,&Room[i].Client_list.date);
fclose(fp);
return(i);
}
void printf_one(int i)
{
printf("\n%-5s %5s %5d %d", Room[i].Room_ID,Room[i].Tel,Roo 17、m [i].Price,Room[i].Sign);
printf("\n%-s %5d %5d %10s",Room[i].Client_list.Name,Room [i].Client_list.Sex,Room[i].Client_list.Age,Room[i].Client_list.ID_card);
printf("\n%-5d %5d %5d\n", Room[i].Client_list.year,Room [i].Client_list.month,Room[i].Client_list.date);
}
18、void save(int n)
{
FILE *fp;
int i;
if((fp=fopen("Hotel.txt","w"))==NULL)
{
printf("\nCannot open file\n");
exit(0);
}
for(i=0;i 19、 %-5d\n",
Room[i].Room_ID,Room[i].Tel,Room[i].Price,Room[i].Sign,
Room[i].Client_list.Name,Room[i].Client_list.Sex,
Room[i].Client_list.Age,Room[i].Client_list.ID_card,Room[i].Client_list.year,
Room[i].Client_list.month,Room[i].Client_list.date);
fclose 20、fp);
}
void printf_face()
{
printf("\nRoom_ID Tel Price Sign");
printf("\nName Sex Age ID_card");
printf("\nyear month date");
}
void printf_back()
{
int w;
printf("\n\n\tSuccessful.^-^\n\n");
printf("Do you want to back?\n\n\t 21、1).Yes\t2).No:[ ]\b\b");
scanf("%d",&w);
if(w==1)
menu();
}
本函数功能为登记顾客及房间信息,涉及姓名、性别、年龄、年份、月份、日期及身份证、。系统依次分派房间号并定义此房间为非空。管理员可依照详细状况登记相应顾客人数信息。在此声明由于本程序并未将顾客信息存入磁盘,因而务必先登记顾客信息再执行功能菜单中其她功能。
(2)记录模块:[需求分析] 该模块功能是显示所有客户记录信息。
程序:
void stati() /***记录函数***/
22、
{
void Time_stati();
void Room_ID_stati();
void Price_stati();
int c;
do
{
puts("\n\nstatistic by =>\n\n1).Time2).Room_ID 3) Price");
printf("Which you need<1-3>?:[ ]\b\b");
scanf("%d",&c);
if(c>3||c<1)
23、 {
puts("\nChoice errror!Please again!");
getchar();
}
}while(c>3||c<1);
switch(c)
{
case 1:Time_stati();break;
case 2:Room_ID_stati();break;
case 3:Price_stati();break;
}
retur 24、n_confirm();
}
void Time_stati() /******记录入住时间*****/
{
int n,i,k=0,w,w0=1,w2=0;
struct Hotel s;
n=load();
do
{
do
{
w=-1;
puts("\nplease enter the time that you want to statistic.\n");
put 25、s("\nplease enter the year:");
scanf("%d",&s.Client_list.year);
puts("\nplease enter the month:");
scanf("%d",&s.Client_list.month);
puts("\nplease enter the date:");
scanf("%d",&s.Client_list.date);
for(i=0,k=0;i 26、om [i].Client_list.year&&s.Client_list.month==Room [i].Client_list.month&&s.Client_list.date==Room[i].Client_list.date)
{
w=i;
printf_face();
printf_one(i);
k++;
}
printf("\nThere are %d recorders this da 27、y!",k);
if(w==-1)
{
printf("\nNO exist!please. Enter error!!");
printf("\nThere are no recorders this day!");
printf("\nDo you want to retry another?\n\n\t1).Yes 2).No and back 3).Back to menu[ ]\b\b");
scanf("%d",& 28、w0);
if(w0==2) stati();
else if(w0!=1) menu();
}
else
{ printf("\nSuccessful!^_^ ^_^.\nEnter another time?\n\n\t1).Yes 2).Back to menu\t[ ]\b\b");
scanf("%d",&w2);
if(w2!=1) menu();
}
29、 }while(w==-1&&w0==1);
}while(w2==1);
}
void Room_ID_stati() /*******记录房间号******/
{
int n,i,k=0,w,w0=1,w2=0;
struct Hotel s;
n=load();
do
{
do
{
w=-1;
puts("\nplease enter the Room_ 30、ID that you want to statistic.\n");
scanf("%s",&s.Room_ID);
for(i=0,k=0;i 31、ere are %d recorders in this Room!",k);
if(w==-1)
{
printf("\nNO exist!please. Enter error!!");
printf("\nThere are no recorders in this Room!");
printf("\nDo you want to retry another?\n\n\t1).Yes 2).No and back 3).Back to m 32、enu[ ]\b\b");
scanf("%d",&w0);
if(w0==2) stati();
else if(w0!=1) menu();
}
else
{ printf("\nSuccessful! ^_^ ^_^.\nEnter another Room_ID?\n\n\t1).Yes 2).Back to menu\t[ ]\b\b");
scanf("%d",&w2);
33、 if(w2!=1) menu();
}
}while(w==-1&&w0==1);
}while(w2==1);
}
void Price_stati() /*******记录房间单价******/
{
int n,i,k=0,w,w0=1,w2=0;
struct Hotel s;
n=load();
do
{
do
{
w=-1 34、
puts("\nplease enter the Room's price that you want to statistic.\n");
scanf("%d",&s.Price);
for(i=0,k=0;i 35、 }
printf("\nThere are %d recorders at this price!",k);
if(w==-1)
{
printf("\nNO exist!please. Enter error!!");
printf("\nThere are no recorders at this price!");
printf("\nDo you want to retry another?\n\n\t1).Yes 36、 2).No and back 3).Back to menu[ ]\b\b");
scanf("%d",&w0);
if(w0==2) stati();
else if(w0!=1) menu();
}
else
{ printf("\nSuccessful!.\nEnter another Room'price?\n\n\t1).Yes 2).Back to menu\t[ ]\b\b");
sc 37、anf("%d",&w2);
if(w2!=1) menu();
}
}while(w==-1&&w0==1);
}while(w2==1);
}
本函数功能为输出记录功能菜单选项,涉及依照按性别记录、依照年龄记录及依照入住时间记录。系统依照输入选项执行相应函数。
(3)查找模块
程序:
void search() /********查找函数********/
{
int i,n,k,w1=1,w2,w 38、3;
struct Hotel s;
n=load();
do
{
w2=-1;
do
{
k=-1;
printf("\n\nEnter ID_card that you want to search!ID_card:");
scanf("%s",&s.Client_list.ID_card);
for(i=0;i 39、Client_list.ID_card,Room
[i].Client_list.ID_card)==0)
{
k=i;
w2=1;
printf_one(k);
break;
}
if(k==-1)
{
printf("\n\nNo exit!Please.");
40、 printf("\n\nAre you again ?\n\t1).again 2).No and back [ ]\b\b");
scanf("%d",&w1);
if(w1!=1) menu();
}
}while(k==-1&&w1==1);
if(w2==1)
{
printf("\n\nSuccessful.^_^.\n");
printf 41、"\nWhat do you want to do?\n\t1).Search another 2).Back to menu [ ]\b\b");
scanf("%d",&w3);
if(w3!=1) menu();
}
}while(w3==1);
}
本函数功能为输出查询功能菜单选项,涉及依照房间号查询、依照姓名查询及依照性别查询。系统依照输入选项执行相应函数。
(4)修改模块
[需求分析] 该模块功能是插入客户记录信息并且不能覆盖原有客户信息。
程序:
void modify() 42、 /********修改函数********/
{
int modify_date(int i,int k);
struct Hotel s;
int i,n,k,w0=1,w1,w2=0;
n=load();
do
{
k=-1;
printf_face();
for(i=0;i 43、 {
printf("\n\nRemember Room_ID that you need to modify!Pass any key to continue ...");
getchar();
puts("\n\n");
}
printf_one(i);
}
do
{
printf("\n\nEnter Room_ID 44、 that you want to modify!Room_ID:");
scanf("%s",s.Room_ID);
for(i=0;i 45、se again");
}while(k==-1);
printf_face();
printf_one(k);
w1=modify_date(k,n);
if(w1==1)
{
printf("\n\nSuccessful ^_^ ^_^.\nAre you modify another?\n\n\t1).Yes 2).Back with save\t[ ]\b\b");
scanf("%d",&w0);
w2=1;
} 46、
else
{
w0=0;
if(w2==1)
Room[i]=s;
}
if(w0!=1&&w2==1)
save(n);
}while(w0==1);
menu();
}
int modify_date(int i,int k)
{
int c,w1;
do
{
puts("\n\nmodify by =>\n\n 47、 1).Name 2).Sex 3).Age\n 4).ID_card 5).Time 6).All data 7).Cancle and back");
printf("Which you need?:[ ]\b\b");
scanf("%d",&c);
if(c>7||c<1)
{
puts("\nChoice errror!Please again!");
getchar();
}
}
while(c>7 48、c<1);
do
{
switch(c)
{
case1:printf("Please enter new Name:");scanf("% s",&Room[i].Client_list.Name);break;
case 2:printf("Please enter new Sex:");scanf("% d",&Room[i].Client_list.Sex);break;
case 3:printf("Please enter new 49、 Age:");scanf("% d",&Room[i].Client_list.Age);break;
case4:printf("PleaseenternewID_card:");scanf("%s",&Room[i].Client_list.ID_card);break; case5:printf("Pleaseenternewyearmonthdate:");scanf("%d%d%d",&Room[i].Client_list.year,&Room[i].Client_list.month,&Room [i].Client_list.date);brea 50、k;
case 6:printf("Please enter new All data:");
puts("\nplease enter customer's new Name\n");
scanf("%15s",&Room[i].Client_list.Name);
printf("\nplease enter new Sex and Age\n");
scanf("%3d %3d",&Room[i].Client_list.Se






