酒店管理系统(c语言课程设计).docx
酒店管理系统(c语言课程设计) #include #include #include#include/*定义客户结构体*/struct guest char no20;char Name20;char sex2;char id20;/*声明客户数组及客户数量*/struct guest guests200;int num=0;/*通过客户返回数组下标*/int guest_SearchByIndex(char no) int i;for (i=0;i<num;i+)if (strcmp(guestsi.no,no)=0)return 0;/i;return -1;/*通过姓名返回数组下标*/int guest_SearchByName(char name) int i;for (i=0;i<num;i+)if (strcmp(guestsi.Name,name)=0)return i;else return -1;return 0;/*显示单条客户记录*/void guest_DisplaySingle(int index) printf("%10s%11s%10s%15sn","房间编号","姓名","性别","身份号码");printf("-n");printf(" %-10s%9s%9s%15sn",guestsindex.no,guestsindex.Name,guestsindex.sex,guestsindex.id);/*插入客户信息*/void guest_Insert()while(1)printf("请输入房间编号:");scanf("%s",guestsnum.no);getchar();printf("请输入姓名:");scanf("%s",guestsnum.Name);getchar();printf("请输入性别:");scanf("%s",guestsnum.sex);getchar();printf("请输入身份号码:");scanf("%s",guestsnum.id);while(strlen(guestsnum.id)!=18)printf("请输入18位身份证号码");scanf("%s",guestsnum.id);getchar();num+;printf("是否继续?(y/n)");if (getchar()='n'|getchar()='N')break;/*修改客户信息*/void guest_Modify()while(1)char no20;int index;printf("请输入要修改的客户的房号:");scanf("%s",no);getchar();index=guest_SearchByIndex(no);if (index=-1)printf("该客户不存在!n");elseprintf("你要修改的客户信息为:n");guest_DisplaySingle(index);printf("- 请输入新值-n");printf("请输入房间编号:");scanf("%s",guestsindex.no);getchar();printf("请输入姓名:");scanf("%s",guestsindex.Name);getchar();printf("请输入性别:");scanf("%s",guestsindex.sex);getchar();printf("请输入您的身份证号码");scanf("%s",guestsindex.id);while(strlen(guestsindex.id)!=18)printf("请输入18位身份证号码n");scanf("%s",guestsindex.id);getchar();printf(" 是否继续?(y/n)");if (getchar()='y'|getchar()!='Y')break;/*删除客户信息*/void guest_Delete()int i;while(1)char no20;int index;printf("请输入要删除的客户房间编号:");scanf("%s",no);getchar();index=guest_SearchByIndex(no);if (index=-1)printf("该房间没人住!n");elseprintf("你要删除的客户信息为:n");guest_DisplaySingle(index);printf("是否真的要删除?(y/n)");if (getchar()='y') for (i=index;i<num-1;i+)guestsi=guestsi+1;num-; getchar();printf("是否继续?(y/n)");if (getchar()='y'|getchar()!='Y')break;/*按姓名查询*/void guest_Select()while(1)char name20;int index;printf("请输入要查询的客户的姓名:");scanf("%s",name);getchar();index=guest_SearchByName(name);if (index=-1)printf("该客户不存在!n");elseprintf("你要查询的客户信息为:n");guest_DisplaySingle(index); printf("是否继续?(y/n)");if (getchar()='y'|getchar()!='Y')break;/*按房间号码查询*/void guest_room()while(1)char no20;char index;printf("请输入要查询的房间号码:");scanf("%s",no);getchar();index=guest_SearchByIndex(no);if (index=-1)printf("该房间为空!n");elseprintf("你要查询的客户信息为:n");guest_DisplaySingle(index);printf("是否继续?(y/n)");if (getchar()='y'|getchar()!='Y')break;/*显示客户信息*/void guest_Display() int i;printf("%10s%11s%10s%15sn","房间编号","姓名","性别","身份号码");printf("-n");for (i=0;i<num;i+)printf(" %-10s%9s%9s%15sn",guestsi.no,guestsi.Name,guestsi.sex,guestsi.id);getchar();/*将客户信息从文件读出*/void IO_ReadInfo()FILE *fp;int i;if (fp=fopen("Database.txt","rb")=NULL)printf("不能打开文件!n");return;if (fread(&num,sizeof(int),1,fp)!=1) /*判断文件读入是否出错*/num=-1;elsefor(i=0;i<num;i+)fread(&guestsi,sizeof(struct guest),1,fp);fclose(fp);/*将客户信息写入文件*/void IO_WriteInfo()FILE *fp;int i;if (fp=fopen("Database.txt","wb")=NULL)printf("不能打开文件!n");return;if (fwrite(&num,sizeof(int),1,fp)!=1)printf("写入文件错误!n");for (i=0;i<num;i+)if (fwrite(&guestsi,sizeof(struct guest),1,fp)!=1)printf("写入文件错误!n"); fclose(fp);/*主程序*/void main()int m,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)case 1:printf("请您选择预定种类:n"); printf("1.单人间/夜150元n2.双人间/夜200元n3.标准间/夜300元n4.总统套房/夜600元n");scanf("%d",&b);getchar();switch(b) case 1:printf("请输入预定天数n");scanf("%d",&x);printf("请预交款为%d元n",x*150);printf("1.确定 2.返回");scanf("%d",&h);printf("您已预定成功!n");break;case 2:printf("请输入预定天数n");scanf("%d",&x);printf("请预交款为%d元n",x*200);printf("1.确定 2.返回");scanf("%d",&h);printf("您已预定成功!n");break;case 3:printf("请输入预定天数n");scanf("%d",&x);printf("请预交款为%d元n",x*300); printf("1.确定 2.返回 ");scanf("%d",&h);printf("您已预定成功!n");break;case 4:printf("请输入预定天数n");scanf("%d",&x);printf("请预交款为%d元n",x*600); printf("1.确定 2.返回");scanf("%d",&h);printf("您已预定成功!n");break;default:printf("您的输入有错请您重试");guest_Insert();break;case 2:guest_Modify();break;case 3:guest_Delete();break;case 4:guest_Select();break;case 5:guest_room();break;case 6: guest_Display();break;case 7:exit(0);/break;default:printf("您输入有误,请重新输入");system("cls"); /*清屏*/IO_WriteInfo();getchar();