这篇文章主要讲解了“C语言如何实现酒店管理系统”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“C语言如何实现酒店管理系统”吧!
系统框架:
代码:
#include <stdio.h>#include <stdlib.h>#include <string.h>int dan=988,shuang=1299,tao=2998;//初始房间价格int sdan=1000,sshuang=600,stao=200;//初始房间数量int Day;//天数int num=0;//客户数量long N=10000000;//现金流struct DINGDAN//订单结构体{ long hao;//订单号 struct YHXX *p;//客户信息结构体地址};struct DINGDAN Dingdan[2000];struct YHXX//客户信息结构体{ char ID[18]; char name[10]; char sex;//性别 int rooms;//房间数 char rooml;//房间类型 int rday[3];//入住日期 int sday;//住宿时间 long dingdanhao;//订单号};struct YHXX yhxx[2000];void zhucaidan()//主菜单{ printf("\n\n"); printf("\t\t******大壮酒店管理系统******\n"); printf("\t\t* 1.:用户信息查询 *\n"); printf("\t\t* 2.:客房经营管理 *\n"); printf("\t\t* 3.:客房管理 *\n"); printf("\t\t****************************\n\n");}void caidan1()//用户信息查询菜单{ printf("\n"); printf("\t\t--------用户信息查询--------\n"); printf("\t\t* 1.:按订单号查询 *\n"); printf("\t\t* 2.:按姓名查询 *\n"); printf("\t\t* 3.:按身份证号查询 *\n"); printf("\t\t* 4.:用户信息目录 *\n"); printf("\t\t----------------------------\n\n");}void caidan2()//客房经营管理菜单{ printf("\n"); printf("\t\t--------客房经营管理--------\n"); printf("\t\t* 1.:预定客房或登记入住*\n"); printf("\t\t* 2.:退房操作 *\n"); printf("\t\t* 3.:客房状态 *\n"); printf("\t\t----------------------------\n\n");}void caidan3()//房间管理菜单{ printf("\n"); printf("\t\t----------房间管理----------\n"); printf("\t\t* 1.:更改房价 *\n"); printf("\t\t* 2.:增加客房 *\n"); printf("\t\t* 3.:减少客房 *\n"); printf("\t\t----------------------------\n\n");}void save(){ FILE *fp; //int i; if((fp=fopen("kehu","wb"))==NULL)//打开输出文件 { printf("\t\tcannot open file\n"); return; } fseek(fp,0L,2); if(fwrite(&yhxx[num],sizeof(struct YHXX),1,fp)!=1) printf("\t\tfile write error\n"); fclose(fp);//关闭wenj}void print(){ int i,t=0; FILE *fp; if((fp=fopen("kehu.dat","wb"))==NULL)//打开输入文件 { printf("cannot open file\n"); exit(0); } rewind(fp);//使文件位置标记返回文件开头 for(i=0;i<num;i++) { fread(&yhxx[i],sizeof(struct YHXX),1,fp); printf("\t\t姓名:%s\t",yhxx[i].name); if(yhxx[i].sex=='Y') printf("性别: 男\n"); else printf("性别 女\n"); printf("\t\t身份证号:%s\n",yhxx[i].ID); printf("\t\t入住日期: %d %d %d",yhxx[i].rday[0],yhxx[i].rday[1],yhxx[i].rday[2]); printf(" 入住时间: %d\n",yhxx[i].sday); t=1; } if(t==0) printf("\t\t 无用户信息!\n"); fclose(fp);//关闭文件}void H()//更改房价{ int x; char ch;Hto: printf("\t\t豪华单间:D 豪华双人:S 贵宾套房:T\n"); printf("\t\t请输入房间类型和更改后价格: "); scanf("%c %d",&ch,&x); switch(ch) { case 'D':dan=x;break; case 'S':shuang=x;break; case 'T':tao=x;break; default : goto Hto; } printf("\t\t更改后分别为:\n\t\t%d %d %d\n\t\t",dan,shuang,tao);}void I()//增加客房{ int x; char ch;Ito: printf("\t\t豪华单间:D 豪华双人:S 贵宾套房:T\n"); printf("\t\t请输入房间类型和增加数量: "); scanf("%c %d",&ch,&x); switch(ch) { case 'D':sdan+=x;break; case 'S':sshuang+=x;break; case 'T':stao+=x;break; default : goto Ito; } printf("\t\t更改后分别为:%d %d %d\n\t\t",sdan,sshuang,stao);}void J()//减少客房{ int x; //int sdan=1000,sshuang=600,stao=200; char ch;Jto: printf("\t\t豪华单间:D 豪华双人:S 贵宾套房:T\n"); printf("\t\t请输入房间类型和减少数量: "); scanf("%c %d",&ch,&x); switch(ch) { case 'D':sdan-=x;break; case 'S':sshuang-=x;break; case 'T':stao-=x;break; default : goto Jto; } printf("\t\t更改后分别为:%d %d %d\n\t\t",sdan,sshuang,stao);}void DE()//预定客房或登记入住{ char lroom; int sroom; int jiner=0; printf("\t\t订房功能\n"); to: printf("\t\t豪华单间:D 豪华双人:S 贵宾套房:T\n"); printf("\t\t请输入房间类型:"); getchar(); scanf("%c",&lroom); printf("\t\t数量:"); scanf("%d",&sroom); switch(lroom) { case 'D':jiner=sroom*dan;sdan-=sroom;break; case 'S':jiner=sroom*shuang;sshuang-=sroom;break; case 'T':jiner=sroom*tao;stao-=sroom;break; default:goto to; } if((lroom=='D'&&sroom<=sdan)||(lroom=='S'&&sroom<=sshuang)||(lroom=='T'&&sroom<=stao)) { printf("\t\t请输入您的信息: \n"); printf("\t\t姓名: "); scanf("%s",yhxx[num].name); getchar(); printf("\t\t性别: (男:Y 女:X) :"); scanf("%c",&yhxx[num].sex); printf("\t\t身份证ID: "); scanf("%s",yhxx[num].ID); printf("\t\t入住日期: "); scanf("%d %d %d",&yhxx[num].rday[0],&yhxx[num].rday[1],&yhxx[num].rday[2]); printf("\t\t入住时间: "); scanf("%d",&yhxx[num].sday); printf("\t\t订单总额:%d\n",jiner*yhxx[num].sday); N+=jiner;jiner=0; yhxx[num].rooms=sroom; yhxx[num].rooml=lroom; yhxx[num].dingdanhao=100000+num;//生成订单号; save(); Dingdan[num].hao=yhxx[num].dingdanhao;//插入订单号到订单号结构体; Dingdan[num].p=&yhxx[num];//将客户信息结构体地址插入到订单结构体中; printf("\t\t订单号:%ld\n",yhxx[num].dingdanhao); num++; printf("\t\t订购成功!\n"); }}void F()//退房操作{ int i,j,t=0; char name1[10],ID1[18]; printf("\t\t退房操作:\n"); printf("\t\t请输入姓名: "); scanf("%s",name1); printf("\n\t\t请输入身份证号:"); scanf("%s",ID1); for(i=0;i<num;i++) { if(strcmp(name1,yhxx[i].name)==0&&strcmp(ID1,yhxx[i].ID)==0) { switch(yhxx[i].rooml) { case 'D':N-=yhxx[i].rooms*dan; case 'S':N-=yhxx[i].rooms*shuang; case 'T':N-=yhxx[i].rooms*tao; } for(j=i-1;i<num;j++,i++) { strcpy(yhxx[j].ID,yhxx[i].ID); strcpy(yhxx[j].name,yhxx[i].name); yhxx[j].sex=yhxx[i].sex; yhxx[j].rooms=yhxx[i].rooms; yhxx[j].rooml=yhxx[i].rooml; yhxx[j].sday=yhxx[i].sday; yhxx[j].rday[0]=yhxx[i].rday[0]; yhxx[j].rday[1]=yhxx[i].rday[1]; yhxx[j].rday[1]=yhxx[i].rday[1]; } num--; t=1; break; } else printf("\t\t查询到无此用户!"); } if(t==1)printf("\t\t退房成功!\n");}void G()//客房状态{ printf("\t\t空余客房:豪华单间:%d 豪华双间:%d 豪华套房:%d\n",1000-sdan,600-sshuang,200-stao); printf("\t\t\t现金流:%ld\n",N);}void A()//按订单号查询{ int i,t=0; long h; struct YHXX *p0; printf("\t\t请输入订单号:"); scanf("%ld",&h); for(i=0;i<num;i++) { if(h==Dingdan[i].hao) { p0=Dingdan[i].p; printf("\t\t姓名:%s\t",p0->name); if(p0->sex=='Y') printf("性别: 男\n"); else printf("性别 女\n"); printf("\t\t身份证号:%s ",p0->ID); switch(yhxx[i].rooml) { case 'D':printf(" 豪华单间: %d\n",p0->rooms);break; case 'S':printf(" 豪华双间: %d\n",p0->rooms);break; case 'T':printf(" 豪华套房: %d\n",p0->rooms);break; } printf("\t\t入住日期: %d %d %d",p0->rday[0],p0->rday[1],p0->rday[2]); printf(" 入住时间: %d\n",p0->sday); t=1; break; } } if(t==0) printf("\t\t客户信息不存在!\n");}void B()//按姓名查询{ int i,t=0; FILE *fp; char names[10]; printf("\t\t请输入姓名:"); scanf("%s",names); if((fp=fopen("kehu.dat","wb"))==NULL)//打开文件 { printf("cannot open file\n"); exit(0); } rewind(fp);//使文件位置标记返回文件开头 for(i=0;i<num;i++) { fread(&yhxx[i],sizeof(struct YHXX),1,fp); if(strcmp(names,yhxx[i].name)==0) { printf("\t\t姓名:%s\t",yhxx[i].name); if(yhxx[i].sex=='Y') printf("性别: 男\n"); else printf("性别 女\n"); printf("\t\t身份证号:%s",yhxx[i].ID); switch(yhxx[i].rooml) { case 'D':printf(" 豪华单间: %d\n",yhxx[i].rooms);break; case 'S':printf(" 豪华双间: %d\n",yhxx[i].rooms);break; case 'T':printf(" 豪华套房: %d\n",yhxx[i].rooms);break; } printf("\t\t入住日期: %d %d %d",yhxx[i].rday[0],yhxx[i].rday[1],yhxx[i].rday[2]); printf(" 入住时间: %d\n",yhxx[i].sday); t=1; break; } } if(t==0) printf("\t\t客户信息不存在!\n"); fclose(fp);//关闭文件}void C()//按身份证号查询{ int i,t=0; FILE *fp; char ids[10]; printf("\t\t请输入身份证号:"); scanf("%s",ids); if((fp=fopen("kehu.dat","wb"))==NULL)//打开文件 { printf("cannot open file\n"); exit(0); } rewind(fp);//使文件位置标记返回文件开头 for(i=0;i<num;i++) { fread(&yhxx[i],sizeof(struct YHXX),1,fp); if(strcmp(ids,yhxx[i].ID)==0) { printf("\t\t姓名:%s\t",yhxx[i].name); if(yhxx[i].sex=='Y') printf("性别: 男\n"); else printf("性别 女\n"); printf("\t\t身份证号:%s",yhxx[i].ID); switch(yhxx[i].rooml) { case 'D':printf(" 豪华单间: %d\n",yhxx[i].rooms);break; case 'S':printf(" 豪华双间: %d\n",yhxx[i].rooms);break; case 'T':printf(" 豪华套房: %d\n",yhxx[i].rooms);break; } printf("\t\t入住日期: %d %d %d",yhxx[i].rday[0],yhxx[i].rday[1],yhxx[i].rday[2]); printf(" 入住时间: %d\n",yhxx[i].sday); t=1; break; } } if(t==0) printf("\t\t客户信息不存在!\n"); fclose(fp);//关闭文件}void zhukongzhi()//主控制函数{ int x1,x2; rrr: zhucaidan();//首页菜单 printf("\t\t请输入选项:"); scanf("%d",&x1); if(x1==1)//用户信息查询模块 { qqq: caidan1();//用户信息查询菜单 printf("\t\t请输入选项:"); scanf("%d",&x2); switch(x2) { case 1:A();break;//按订单号查询 case 2:B();break;//按姓名查询 case 3:C();break;//按身份证号查询 case 4:print();break;//用户目录浏览 default: goto qqq;//重新输入 } } else if(x1==2)//客房经营管理模块 { www: caidan2();//客房经营管理菜单 printf("\t\t请输入选项:"); scanf("%d",&x2); switch(x2) { case 1:DE();break;//预定客房或登记入住 case 3:F();break;//退房操作 case 4:G();break;//客房状态 default: goto www;//重新输入 } } else if(x1==3)//房间管理模块 { eee: caidan3();//客房管理菜单 printf("\t\t请输入选项:"); scanf("%d",&x2); switch(x2) { case 1:H();break;//更改房价 case 2:I();break;//增加客房 case 3:J();break;//减少客房 default: goto eee;//重新输入 } } else goto rrr;//返回主菜单重新输入}int main(){ int x=0; do { zhukongzhi();//进入主控制函数; printf("\t\t--------是否需要继续?--------\n"); printf("\t\t----回复: 1 (继续): 0 (结束)----\n\t\t请选择:"); scanf("%d",&x); }while(x); return 0;}
感谢各位的阅读,以上就是“C语言如何实现酒店管理系统”的内容了,经过本文的学习后,相信大家对C语言如何实现酒店管理系统这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是编程网,小编将为大家推送更多相关知识点的文章,欢迎关注!