您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 市场营销 > 酒店管理系统(c语言课程设计)
#includestdio.h#includeconio.h#includestring.h#includestdlib.h/*定义客户结构体*/structguest{charno[20];charName[20];charsex[2];charid[20];};/*声明客户数组及客户数量*/structguestguests[200];intnum=0;/*通过客户返回数组下标*/intguest_SearchByIndex(charno[]){inti;for(i=0;inum;i++){if(strcmp(guests[i].no,no)==0){return0;//i;}}return-1;}/*通过姓名返回数组下标*/intguest_SearchByName(charname[]){inti;for(i=0;inum;i++){if(strcmp(guests[i].Name,name)==0)returni;elsereturn-1;}return0;}/*显示单条客户记录*/voidguest_DisplaySingle(intindex){printf(%10s%11s%10s%15s\n,房间编号,姓名,性别,身份号码);printf(-------------------------------------------------------------\n);printf(%-10s%9s%9s%15s\n,guests[index].no,guests[index].Name,guests[index].sex,guests[index].id);}/*插入客户信息*/voidguest_Insert(){while(1){printf(请输入房间编号:);scanf(%s,guests[num].no);getchar();printf(请输入姓名:);scanf(%s,guests[num].Name);getchar();printf(请输入性别:);scanf(%s,guests[num].sex);getchar();printf(请输入身份号码:);scanf(%s,guests[num].id);while(strlen(guests[num].id)!=18){printf(请输入18位身份证号码);scanf(%s,guests[num].id);}getchar();num++;printf(是否继续?(y/n));if(getchar()=='n'||getchar()=='N'){break;}}}/*修改客户信息*/voidguest_Modify(){while(1){charno[20];intindex;printf(请输入要修改的客户的房号:);scanf(%s,no);getchar();index=guest_SearchByIndex(no);if(index==-1){printf(该客户不存在!\n);}else{printf(你要修改的客户信息为:\n);guest_DisplaySingle(index);printf(--请输入新值--\n);printf(请输入房间编号:);scanf(%s,guests[index].no);getchar();printf(请输入姓名:);scanf(%s,guests[index].Name);getchar();printf(请输入性别:);scanf(%s,guests[index].sex);getchar();printf(请输入您的身份证号码);scanf(%s,guests[index].id);while(strlen(guests[index].id)!=18){printf(请输入18位身份证号码\n);scanf(%s,guests[index].id);}getchar();}printf(是否继续?(y/n));if(getchar()=='y'||getchar()!='Y'){break;}}}/*删除客户信息*/voidguest_Delete(){inti;while(1){charno[20];intindex;printf(请输入要删除的客户房间编号:);scanf(%s,no);getchar();index=guest_SearchByIndex(no);if(index==-1){printf(该房间没人住!\n);}else{printf(你要删除的客户信息为:\n);guest_DisplaySingle(index);printf(是否真的要删除?(y/n));if(getchar()=='y'){for(i=index;inum-1;i++)guests[i]=guests[i+1];num--;}getchar();}printf(是否继续?(y/n));if(getchar()=='y'||getchar()!='Y'){break;}}}/*按姓名查询*/voidguest_Select(){while(1){charname[20];intindex;printf(请输入要查询的客户的姓名:);scanf(%s,name);getchar();index=guest_SearchByName(name);if(index==-1){printf(该客户不存在!\n);}else{printf(你要查询的客户信息为:\n);guest_DisplaySingle(index);}printf(是否继续?(y/n));if(getchar()=='y'||getchar()!='Y'){break;}}}/*按房间号码查询*/voidguest_room(){while(1){charno[20];charindex;printf(请输入要查询的房间号码:);scanf(%s,no);getchar();index=guest_SearchByIndex(no);if(index==-1){printf(该房间为空!\n);}else{printf(你要查询的客户信息为:\n);guest_DisplaySingle(index);}printf(是否继续?(y/n));if(getchar()=='y'||getchar()!='Y'){break;}}}/*显示客户信息*/voidguest_Display(){inti;printf(%10s%11s%10s%15s\n,房间编号,姓名,性别,身份号码);printf(-------------------------------------------------------------------------\n);for(i=0;inum;i++){printf(%-10s%9s%9s%15s\n,guests[i].no,guests[i].Name,guests[i].sex,guests[i].id);}getchar();}/*将客户信息从文件读出*/voidIO_ReadInfo(){FILE*fp;inti;if((fp=fopen(Database.txt,rb))==NULL){printf(不能打开文件!\n);return;}if(fread(&num,sizeof(int),1,fp)!=1)/*判断文件读入是否出错*/{num=-1;}else{for(i=0;inum;i++){fread(&guests[i],sizeof(structguest),1,fp);}}fclose(fp);}/*将客户信息写入文件*/voidIO_WriteInfo(){FILE*fp;inti;if((fp=fopen(Database.txt,wb))==NULL){printf(不能打开文件!\n);return;}if(fwrite(&num,sizeof(int),1,fp)!=1){printf(写入文件错误!\n);}for(i=0;inum;i++){if(fwrite(&guests[i],sizeof(structguest),1,fp)!=1){printf(写入文件错误!\n);}}fclose(fp);}/*主程序*/voidmain(){intm,b,x,h;IO_ReadInfo();while(1){/*主菜单*/printf(\n*********************酒店客户入住登记管理********************\n);printf(&1.增加客户记录&\n);printf(&2.修改客户记录&\n);printf(&3.删除客户&\n);printf(&4.按姓名查询客户记录&\n);printf(&5.按房间号码查询客户记录&\n);printf(&6.输出所有客户&\n);printf(&7.退出&\n);printf(**********************************************************\n);scanf(%d,&m);getchar();switch(m){case1:{printf(请您选择预定种类:\n);printf(1.单人间/夜150元\n2.双人间/夜200元\n3.标准间/夜300元\n4.总统套房/夜600元\n);scanf(%d,&b);getchar();switch(b){case1:printf(请输入预定天数\n);scanf(%d,&x);printf(请预交款为%d元\n,x*150);printf(1.确定2.返回);scanf(%d,&h);printf(您已预定成功!\n);break;case2:printf(请输入预定天数\n);scanf(%d,&x);printf(请预交款为%d元\n,x*200);printf(1.确定2.返回);scanf(%d,&h);printf(您已预定成功!\n);break;case3:printf(请输入预定天数\n);scanf(%d,&x);printf(请预交款为%d元\n,x*300);printf(1.确定2.返回);scanf(%d,&h);printf(您已预定成功!\n);break;case4:printf(请输入预定天数\n);scanf(%d,&x);printf(请预交款为%d元\n,x*600);printf(1.确定2.返回);scanf(%d,&h);printf(您已预定成功!\n);break;default:printf(您的输入有错请您重试);}guest_Insert();}break;case2:guest_Modify();break;case3:guest_Delete();break;case4:guest_Select();break;case5:guest_room();break;case6:guest_Display();break;case7:exit(0);//break;default:printf(您输入有误,请重新输入);system(cls);/*清屏*/}IO_WriteInfo();}getchar();}
本文标题:酒店管理系统(c语言课程设计)
链接地址:https://www.777doc.com/doc-5073480 .html