/*
1.编制一个航班订票系统
该航班仅有一架100座飞机;
该飞机座位分为吸烟区(30个座位)和无烟区(70个);
订票系统界面是选择菜单:
1.选吸烟区座位号;
2.选无烟区座位号;
用户输入自己的选择后,该区若有空位,则顺序地分配一个座号;否则致歉;
若吸烟区已满而无烟区有空位,则征求顾客意见,是否愿意得到无烟区的空位,若愿意,则在无烟区分配一个座 号,否则致歉退出;
顾客不得自主挑选座位号;
完成上题的基础上,进一步试做自主选号系统。
*/
#include<stdio.h>
#include<stdlib.h>
#define SMOKE_ZONE 30
#define NO_SMOKE_ZONE 70
int smoke_site[SMOKE_ZONE]={0};
int no_smoke_site[NO_SMOKE_ZONE]={0};
int count_smoke=0;
int count_no_smoke=0;
void smoke()
{
if(smoke_site[count_smoke]==0)
{
printf("此座位没有人");
smoke_site[count_smoke]=1;
}
else if(smoke_site[count_smoke]==1)
{
printf("此坐有人,请重新输入");
}
}
void no_smoke()
{
if(no_smoke_site[count_no_smoke]==0)
{
printf("此座位没有人");
no_smoke_site[count_no_smoke]=1;
}
else if(smoke_site[count_smoke]==1)
{
printf("此坐有人,请重新输入");
}
}
int smoke_full()//若吸烟区已满,征询用户意见
{
int i;
int count=0;
for(i=0;i<SMOKE_ZONE;i++)
{
if(smoke_site[i]==1)
{
count++;
}
}
return count;
}
void main()
{
int choice=0;
while(1)
{
printf("请输入你的选择,1是吸烟区,2是无烟区");
scanf("%d",&choice);
if(choice==1)
{
printf("吸烟区");
printf("请输入你的座位号");
scanf("%d",&count_smoke);
smoke();
if(smoke_full()+1==30)
{
printf("是否到无烟区就坐");
}
}
else if(choice==2)
{
printf("非吸烟区");
printf("请输入你的座位号");
scanf("%d",&count_no_smoke);
no_smoke();
}
else
{
printf("请输入1,2");
}
}
}