#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//房间信息结构体
struct Node
{
int Count; //指示该房间有多少个房客
char nameOne[20]; //房客1的名字
char nameTwo[20]; //房客2的名字
strcmp比较数组 int sexOne; //房客1的性别 -1代表女,0代表没有,1代表男
int sexTwo; //房客2的性别
int roomNumber; //房间号
}roomArray[5];
//初始化房间数组
void InitArray()
{
int i;
for(i=0;i<5;i++)
{
roomArray[i].roomNumber = 301+i;
memset(roomArray[i].nameOne,0,20);
memset(roomArray[i].nameTwo,0,20);
roomArray[i].sexOne = 0;
roomArray[i].sexTwo = 0;
roomArray[i].Count = 0;
}
}
void fun1() //旅客入住的操作
{
char name[20];
int sex;
int i;
printf("\n输入入住旅客和性别(空格隔开,1为男,-1为女):");
scanf("%s %d",name,&sex);
for(i=0;i<5;i++)
{
if(roomArray[i].Count == 2)
{
continue;
}
else if(roomArray[i].Count == 1)
{
if(roomArray[i].sexOne != sex)
{
continue;
}
strcpy(roomArray[i].nameTwo,name);
roomArray[i].sexTwo = sex;
roomArray[i].Count++;
system("cls");
printf("客人已经成功入住,在房间%d",roomArray[i].roomNumber);
return;;
}
else
{
strcpy(roomArray[i].nameOne,name);
roomArray[i].sexOne = sex;
roomArray[i].Count++;
system("cls");
printf("客人已经成功入住,在房间%d",roomArray[i].roomNumber);
return;;
}
}
printf("无法入住,房间已经住满或者是没有适合的房间");
}
void fun2() //退房操作
{
int i;
char name[20];
printf("请输入要退房旅客的: ");
scanf("%s",name);
for(i=0;i<5;i++)
{
if(strcmp(roomArray[i].nameOne,name) == 0)
{
memset(roomArray[i].nameOne,0,20);
roomArray[i].sexOne = 0;
roomArray[i].Count--;
system("cls");
printf("%s客人已经成功退房\n",name);
return;
}
if(strcmp(roomArray[i].nameTwo,name) == 0)
{
memset(roomArray[i].nameTwo,0,20);
roomArray[i].sexTwo = 0;
roomArray[i].Count--;
system("cls");
printf("%s客人已经成功退房\n",name);
return;
}
}
system("cls");
printf("没有名为%s的客人,请检查输入的正确性!\n",name);
}
void fun3() //查询操作
{
int index;
int i;
char name[20];
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:",roomArray[i].roomNumber);
if(roomArray[i].Count == 0)
{
printf("没有客人入住\n");
}
else if(roomArray[i].Count == 1)
{
if(roomArray[i].sexTwo == 0)
{
printf("当前有1位客人-> %s,",roomArray[i].nameOne);
if(roomArray[i].sexOne == 1)
printf("性别:男");
else if(roomArray[i].sexOne == -1)
printf("性别:女");
printf("\n");
}
else if(roomArray[i].sexOne == 0)
{
printf("当前有1位客人-> %s,",roomArray[i].nameTwo);
if(roomArray[i].sexTwo == 1)
printf("性别:男");
else if(roomArray[i].sexTwo == -1)
printf("性别:女");
printf("\n");
}
}
else
{
//printf("当前有两个客人 客人1: %s,性别%d 客人2: %s,性别%d \n",roomArray[i].nameOne,roomArray[i].sexOne,roomArray[i].nameTwo,roomArray[i].sexTwo);
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论