/*楼上的程序写得真不错
但是飞机只有十个座位啊,当键入2时,照上面的程序运行会得出:
你定的机票是:
在吸烟区!
--座位号是:11
经过一点小小的修改就可以正确运行了,见以下程序:
*/
#include <stdio.h>
#include <string.h>
#include <iostream>
using namespace std;
class Seat
{
public:
int Region;
int SeatId;
bool IsBooked;
public:
Seat();
Seat(int r,int s);
~Seat();
Diaplay();
};
Seat::Seat(int r,int s)
{
Region=r;
SeatId=s;
}
Seat::Seat()
{
}
Seat::~Seat()
{
}
Seat::Diaplay()
{
if(Region==1)
printf("\t在无烟区!\t\n");
else
printf("\t在吸烟区!\t\n");
printf("\t--座位号是%d\t\n",SeatId+1);
}
int main()
{
Seat seat[10];
Seat *pS=NULL;
Seat NoSigur[5];
Seat Sigur[5];
for(int n=0;n<10;n++)
{
if (n<5) //如果是前五位的是无烟区,Region = 1,否则为2.
seat[n].Region=1;
seat[n].Region = 2;
seat[n].IsBooked=false;
seat[n].SeatId=n;
}
/*这一部分无必要了,在前面已经做出了区分
for(n=5;n<10;n++)
{
seat[n].Region=2;
seat[n].IsBooked=false;
seat[n].SeatId = n;//seat[n].SeatId=n+5;
}
*/
bool BookSeccess;
while(1)
{
printf(" **********************************\n");
printf(" \n");
printf(" ** 吸烟区 --------1 **\n");
printf(" \n");
printf(" ** 无烟区 --------2 **\n");
printf(" \n");
printf(" **********************************\n");
int input;
BookSeccess=false;
cin >> input;
if(input==1)
{
for(int m=0;m<5;m++)
{
if(!seat[m].IsBooked)
{
seat[m].IsBooked=true;
printf("你定的机票是:\n");
seat[m].Diaplay();
BookSeccess=true;
printf("\n");
printf("\n");
printf("\n");
printf("\n");
break;
}
}
if(!BookSeccess)
{
printf("是否原意调配到吸烟区?愿意:1 不愿意:0\n");
int in2;
cin >> in2; //scanf("%d",&in2);
if(in2==1)
{
for(m=0;m<5;m++)
{
if(!seat[m+5].IsBooked)
{
seat[m+5].IsBooked=true;
printf("你定的机票是:\n");
seat[m+5].Diaplay();
BookSeccess=true;
printf("\n");
printf("\n");
printf("\n");
printf("\n");
break;
}
}
}
else
{
printf("请等下一航班,在6小时以后\n");
break;
}
if(!BookSeccess)
{
printf("对不起,该航班机票已售完,请等下一航班\n");
}
}
}
else if(input==2)
{
for(int m=5;m<10;m++)
{
if(!seat[m].IsBooked)
{
seat[m].IsBooked=true;
printf("你定的机票是:\n");
seat[m].Diaplay();
BookSeccess=true;
printf("\n");
printf("\n");
printf("\n");
printf("\n");
break;
}
}
if(!BookSeccess)
{
printf("是否原意调配到无烟区?愿意:1 不愿意:0\n");
int in2;
scanf("%d",&in2);
if(in2==1)
{
for(m=0;m<5;m++)
{
if(!seat[m].IsBooked)
{
seat[m].IsBooked=true;
printf("你定的机票是:\n");
seat[m].Diaplay();
BookSeccess=true;
printf("\n");
printf("\n");
printf("\n");
printf("\n");
break;
}
}
}
else
{
printf("请等下一航班,在6小时以后\n");
break;
}
if(!BookSeccess)
{
printf("对不起,该航班机票已售完,请等下一航班\n");
}
}
}
else
{
continue;
}
}
return 0;
}