酒店管理系统代码(C语言版).doc
精品文档,仅供学习与交流,如有侵权请联系网站删除#include <stdio.h>#include <stdlib.h>#include <string.h>/房间信息结构体struct Nodeint Count; /指示该房间有多少个房客char nameOne20; /房客1的名字char nameTwo20; /房客2的名字int sexOne; /房客1的性别 -1代表女,0代表没有,1代表男int sexTwo; /房客2的性别int roomNumber; /房间号roomArray5; /初始化房间数组void InitArray()int i;for(i=0;i<5;i+)roomArrayi.roomNumber = 301+i;memset(roomArrayi.nameOne,0,20);memset(roomArrayi.nameTwo,0,20);roomArrayi.sexOne = 0;roomArrayi.sexTwo = 0;roomArrayi.Count = 0;void fun1() /旅客入住的操作char name20;int sex;int i;printf("n输入入住旅客姓名和性别(空格隔开,1为男,-1为女):");scanf("%s %d",name,&sex);for(i=0;i<5;i+)if(roomArrayi.Count = 2)continue;else if(roomArrayi.Count = 1)if(roomArrayi.sexOne != sex)continue;strcpy(roomArrayi.nameTwo,name);roomArrayi.sexTwo = sex;roomArrayi.Count+;system("cls");printf("客人已经成功入住,在房间%d",roomArrayi.roomNumber);return;elsestrcpy(roomArrayi.nameOne,name);roomArrayi.sexOne = sex;roomArrayi.Count+;system("cls");printf("客人已经成功入住,在房间%d",roomArrayi.roomNumber);return;printf("无法入住,房间已经住满或者是没有适合的房间");void fun2() /退房操作int i;char name20;printf("请输入要退房旅客的姓名: ");scanf("%s",name);for(i=0;i<5;i+)if(strcmp(roomArrayi.nameOne,name) = 0)memset(roomArrayi.nameOne,0,20);roomArrayi.sexOne = 0;roomArrayi.Count-;system("cls");printf("%s客人已经成功退房n",name);return;if(strcmp(roomArrayi.nameTwo,name) = 0)memset(roomArrayi.nameTwo,0,20);roomArrayi.sexTwo = 0;roomArrayi.Count-;system("cls");printf("%s客人已经成功退房n",name);return;system("cls");printf("没有名为%s的客人,请检查输入的正确性!n",name);void fun3() /查询操作int index;int i;char name20;int number;int j;system("cls");printf("*请选择要查询的种类*n");printf(" 1.所有房间入住信息显示n");printf(" 2.按照姓名查询n");printf(" 3.按照房号查询n");scanf("%d",&index);if(index = 1) for( i=0;i<5;i+)printf("房间%d:",roomArrayi.roomNumber);if(roomArrayi.Count = 0)printf("没有客人入住n");else if(roomArrayi.Count = 1)if(roomArrayi.sexTwo = 0)printf("当前有1位客人-> 姓名%s,",roomArrayi.nameOne);if(roomArrayi.sexOne = 1)printf("性别:男");else if(roomArrayi.sexOne = -1)printf("性别:女");printf("n");else if(roomArrayi.sexOne = 0)printf("当前有1位客人-> 姓名%s,",roomArrayi.nameTwo);if(roomArrayi.sexTwo = 1)printf("性别:男");else if(roomArrayi.sexTwo = -1)printf("性别:女");printf("n");else/printf("当前有两个客人 客人1: 姓名%s,性别%d 客人2: 姓名%s,性别%d n",roomArrayi.nameOne,roomArrayi.sexOne,roomArrayi.nameTwo,roomArrayi.sexTwo);printf("当前有2位客人-> 姓名%s,",roomArrayi.nameOne);if(roomArrayi.sexOne = 1)printf("性别:男,");else if(roomArrayi.sexOne = -1)printf("性别:女,");printf("姓名:%s,",roomArrayi.nameTwo);if(roomArrayi.sexTwo = 1)printf("性别:男,");else if(roomArrayi.sexOne = -1)printf("性别:女,");printf("n");else if(index = 2)printf("请输入你要查询房客的姓名:");scanf("%s",name);for(i=0;i<5;i+)if(strcmp(roomArrayi.nameOne,name) = 0 | strcmp(roomArrayi.nameTwo,name) = 0)printf("%s房客入住在房间%d!n",name,roomArrayi.roomNumber);return;printf("没有找到该旅客的信息!");else if(index = 3)printf("请输入你要查询的房间号:");scanf("%d",&number);j = number - 301;if(roomArrayj.Count = 0)printf("没有客人入住n");else if(roomArrayj.Count = 1)printf("当前有1位客人-> 姓名%s,性别%d!",roomArrayj.nameOne,roomArrayj.sexOne);elseprintf("当前有两个客人入住 姓名%s,性别%d 姓名%s,性别%d n",roomArrayj.nameOne,roomArrayj.sexOne,roomArrayj.nameTwo,roomArrayj.sexTwo);void show()system("color 9f");printf("*请选择操作*n");printf(" 1.旅客入住n");printf(" 2.旅客退房n");printf(" 3.信息查询n");printf(" 4.退出 exitn");printf("请输入你要选择的操作: ");int main()int i= 100;InitArray();printf("*宾馆信息管理软件*n");while(i != 4)printf("n");show();scanf("%d",&i);switch(i)case 1:fun1();break;case 2:fun2();break;case 3:fun3();break;system("pause");return 0;【精品文档】第 4 页