hello,i'm yuri and i'm new here..
i have to make program about airline seating..
but up till now..we still have some problems with the program..
it's not working as we expect it to be..
so,i'm asking anybody that can help me..please..
i'm quite desperate now..we've been work on this program for 3 weeks...*_*
this is the question:
Airline seating:write a program that assigns seats on airplane.assume that airplane has 20 seats in first class(5 rows of 4 seats each,separated by an aisle) and 180 seats in economy class(30 rows of 6 seats each,separated by an aisle). Your program should take three commands, add passengers, show seating(use ‘*’ to indicates that the seat is available; ‘X’ to indicates that the seat is occupied), and quit. When passengers are added, ask for the class(first or economy), the number of passengers traveling together(1 or 2 in first class;1 to 3 in economy), and the seating preference(aisle or window in first class; aisle, center, or window in economy). Then try to match and assign the seats. If no match exists,print a message.
#include<iostream>
#include<string>
using namespace std;
const int numOfRowF=5;
const int numOfColumnF=4;
const int numOfRowE=30;
const int numOfColumnE=6;
const char SENTINEL='N';
char quit='Y';
char First[numOfRowF][numOfColumnF];
char Eco[numOfRowE][numOfColumnE];
int i,j,s;
char typeClass;
int passenger;
string seat;
void main()
{
cout<<"######## WELCOME TO AIRLINE SEATING BOOKING TICKET ########"<<endl;
cout<<endl;
cout<<"This company have 2 types of class seating: "<<endl;
cout<<"A) FIRST CLASS"<<endl;
cout<<"B) ECONOMY CLASS"<<endl;
cout<<endl;
cout<<"Below are condition before choosing a seat for those class: "<<endl;
cout<<"A) FIRST CLASS: maximum passenger = 2. "<<endl;
cout<<"If more than 2 please re-enter this program for the passenger that over the maximum passenger"<<endl;
cout<<endl;
cout<<"B) ECONOMY CLASS: maximum passenger = 3. "<<endl;
cout<<"If more than 3 please re-enter this program for the passenger that over the maximum passenger"<<endl;
cout<<endl;
cout<<"This sign'*' is for available seat and this sign 'X' is for not available seat"<<endl;
cout<<" This is the seat arrangement: ";
cout<<endl<<endl;
cout<<"Press 'Y' to continue this program, 'N' to quit the program: ";
cin>>quit;
while (quit=!SENTINEL)
{
cout<<"Enter your class choice (F=FIRST CLASS, E=ECONOMY CLASS): ";
cin>>typeClass;
if(typeClass=='F')
{
if(First[i][j]=='*')
{
cout<<"Enter number of passenger: ";
cin>>passenger;
}
for(s=0;s<passenger++;s++)
{
cout<<"Enter of your seating position: "<<endl;
cout<<"(WR = right window, WL = left window,"<<endl;
cout<<"AR = right aisle, AL = left aisle)"<<endl;
cin>>seat;
}
for(i=0;i<numOfRowF;i++)
{
if(seat=="WR")
{
j=0;
First[i][j]='X';
}
I recommend you to use the following code as a basis. I left the most difficult part (implementing addPassengers) to you. But like this the code becomes much more readable than yours. (in fact i just reorganized yours).
#include<iostream>
#include<string>
usingnamespace std;
constint numOfRowF=5;
constint numOfColumnF=4;
constint numOfRowE=30;
constint numOfColumnE=6;
constchar SENTINEL='N';
char quit='Y';
char First[numOfRowF][numOfColumnF];
char Eco[numOfRowE][numOfColumnE];
int i,j,s;
char typeClass;
int passenger;
string seat;
void main()
{
cout<<"######## WELCOME TO AIRLINE SEATING BOOKING TICKET ########"<<endl;
cout<<endl;
cout<<"This company have 2 types of class seating: "<<endl;
cout<<"A) FIRST CLASS"<<endl;
cout<<"B) ECONOMY CLASS"<<endl;
cout<<endl;
cout<<"Below are condition before choosing a seat for those class: "<<endl;
cout<<"A) FIRST CLASS: maximum passenger = 2. "<<endl;
cout<<"If more than 2 please re-enter this program for the passenger that over the maximum passenger"<<endl;
cout<<endl;
cout<<"B) ECONOMY CLASS: maximum passenger = 3. "<<endl;
cout<<"If more than 3 please re-enter this program for the passenger that over the maximum passenger"<<endl;
cout<<endl;
cout<<"This sign'*' is for available seat and this sign 'X' is for not available seat"<<endl;
cout<<" This is the seat arrangement: ";
cout<<endl<<endl;
for(i=0;i<numOfRowF;i++)
{
for(j=0;j<numOfColumnF;j++)
First[i][j]='*';
}
for(i=0;i<numOfRowE;i++)
{
for(j=0;j<numOfColumnE;j++)
Eco[i][j]='*';
}
cout<<"First Class";
cout<<endl<<endl<<endl;
for(i=0;i<numOfRowF;i++)
{
for(j=0;j<numOfColumnF;j++)
cout<<First[i][j]<<" ";
cout<<endl<<endl;
}
cout<<"Economy Class";
cout<<endl<<endl<<endl;
for(i=0;i<numOfRowE;i++)
{
for(j=0;j<numOfColumnE;j++)
cout<<Eco[i][j]<<" ";
cout<<endl<<endl;
}
cout<<"Press 'Y' to continue this program, 'N' to quit the program: ";
cin>>quit;
while (quit=!SENTINEL)
{
cout<<"Enter your class choice (F=FIRST CLASS, E=ECONOMY CLASS): ";
cin>>typeClass;
if(typeClass=='F')
{
if(First[i][j]=='*')
{
cout<<"Enter number of passenger: ";
cin>>passenger;
}
for(s=0;s<passenger++;s++)
{
cout<<"Enter of your seating position: "<<endl;
cout<<"(WR = right window, WL = left window,"<<endl;
cout<<"AR = right aisle, AL = left aisle)"<<endl;
cin>>seat;
}
for(i=0;i<numOfRowF;i++)
{
if(seat=="WR")
{
j=0;
First[i][j]='X';
}
if(seat=="WL")
{
j=3;
First[i][j]='X';
}
if(seat=="AR")
{
j=1;
First[i][j]='X';
}
if(seat=="AL")
{
j=2;
First[i][j]='X';
}
}
}
elseif(typeClass=='E')
{
if(Eco[i][j]=='*')
{
cout<<"Enter number of passenger: ";
cin>>passenger;
}
for(s=0;s<passenger++;s++)
{
cout<<"Enter of your seating position: "<<endl;
cout<<"(WR = right window, WL = left window,"<<endl;
cout<<"CR = right centre, CL = Left Centre"<<endl;
cout<<"AR = right aisle, AL = left aisle)"<<endl;
cin>>seat;
}
for(i=0;i<numOfRowF;i++)
{
if(seat=="WR")
{
j=0;
Eco[i][j]='X';
}
if(seat=="WL")
{
j=5;
Eco[i][j]='X';
}
if(seat=="AR")
{
j=2;
Eco[i][j]='X';
}
if(seat=="AL")
{
j=3;
Eco[i][j]='X';
}
if(seat=="CR")
{
j=1;
Eco[i][j]='X';
}
if(seat=="CL")
{
j=4;
Eco[i][j]='X';
}
else cout<<"INVALID CODE"<<endl;
}
}
cout<<"First Class";
cout<<endl<<endl<<endl;
for(i=0;i<numOfRowF;i++)
{
for(j=0;j<numOfColumnF;j++)
cout<<First[i][j]<<" ";
cout<<endl<<endl;
}
cout<<"Economy Class";
cout<<endl<<endl<<endl;
for(i=0;i<numOfRowE;i++)
{
for(j=0;j<numOfColumnE;j++)
cout<<Eco[i][j]<<" ";
cout<<endl<<endl;
}
cout<<"Press 'Y' to continue this program, 'N' to quit the program: ";
cin>>quit;
}
}
#include<iostream>
#include<string>
usingnamespace std;
constint numOfRowF=5;
constint numOfColumnF=4;
constint numOfRowE=30;
constint numOfColumnE=6;
constchar SENTINEL='n';
char quit;
char First[numOfRowF][numOfColumnF];
char Eco[numOfRowE][numOfColumnE];
int i,j,s;
char typeClass;
int passenger;
string seat;
void main()
{
cout<<"######## WELCOME TO AIRLINE SEATING BOOKING TICKET ########"<<endl;
cout<<endl;
cout<<"This company have 2 types of class seating: "<<endl;
cout<<"A) FIRST CLASS"<<endl;
cout<<"B) ECONOMY CLASS"<<endl;
cout<<endl;
cout<<"Below are condition before choosing a seat for those class: "<<endl;
cout<<"A) FIRST CLASS: maximum passenger = 2. "<<endl;
cout<<"If more than 2 please re-enter this program for the passenger that over the maximum passenger"<<endl;
cout<<endl;
cout<<"B) ECONOMY CLASS: maximum passenger = 3. "<<endl;
cout<<"If more than 3 please re-enter this program for the passenger that over the maximum passenger"<<endl;
cout<<endl;
cout<<"This sign'*' is for available seat and this sign 'X' is for not available seat"<<endl;
cout<<" This is the seat arrangement: ";
cout<<endl<<endl;
for(i=0;i<numOfRowF;i++)
{
for(j=0;j<numOfColumnF;j++)
First[i][j]='*';
}
for(i=0;i<numOfRowE;i++)
{
for(j=0;j<numOfColumnE;j++)
Eco[i][j]='*';
}
cout<<"First Class";
cout<<endl<<endl<<endl;
for(i=0;i<numOfRowF;i++)
{
for(j=0;j<numOfColumnF;j++)
cout<<First[i][j]<<" ";
cout<<endl<<endl;
}
cout<<"Economy Class";
cout<<endl<<endl<<endl;
for(i=0;i<numOfRowE;i++)
{
for(j=0;j<numOfColumnE;j++)
cout<<Eco[i][j]<<" ";
cout<<endl<<endl;
}
cout<<"Press 'y' to continue this program, 'n' to quit the program: ";
cin>>quit;
while (quit!=SENTINEL)
{
cout<<"Enter your class choice (f=FIRST CLASS, e=ECONOMY CLASS): ";
cin>>typeClass;
if(typeClass=='F')
{
cout<<"Enter number of passenger: ";
cin>>passenger;
for(i=0;i<numOfRowF;i++)
{
for(j=0;j<numOfColumnF;j++)
for(s=0;s<passenger;s++)
{
cout<<"Enter of your seating position: "<<endl;
cout<<"(wr = right window, wl = left window,"<<endl;
cout<<" ar = right aisle, al = left aisle)"<<endl;
cin>>seat;
if(seat=="wr")
{
j=0;
if(First[i][j]=='X')
{
continue;
}
elseif( (i == numOfRowF ) && ( j == numOfColumnF) )
{
cout<<"Seats are full ";
break;
}
else
{
First[i][j]='X';
}
}
if(seat=="wl")
{
j=3;
if(First[i][j]=='X')
{
continue;
}
elseif( (i == numOfRowF ) && ( j == numOfColumnF) )
{
cout<<"Seats are full ";
break;
}
else
{
First[i][j]='X';
}
}
if(seat=="ar")
{
j=1;
if(First[i][j]=='X')
{
continue;
}
elseif( (i == numOfRowF ) && ( j == numOfColumnF) )
{
cout<<"Seats are full ";
break;
}
else
{
First[i][j]='X';
}
}
if(seat=="al")
{
j=2;
if(First[i][j]=='X')
{
continue;
}
elseif( (i == numOfRowF ) && ( j == numOfColumnF) )
{
cout<<"Seats are full ";
break;
}
else
{
First[i][j]='X';
}
}
}
}
}
elseif(typeClass=='e')
{
cout<<"Enter number of passenger: ";
cin>>passenger;
for(s=0;s<passenger;s++)
{
cout<<"Enter of your seating position: "<<endl;
cout<<"(wr = right window, wl = left window,"<<endl;
cout<<" cr = right centre, cl = left centre"<<endl;
cout<<" ar = right aisle, al = left aisle)"<<endl;
cin>>seat;
for(i=0;i<numOfRowF;i++)
{
if(seat=="wr")
{
j=0;
Eco[i][j]='X';
}
if(seat=="wl")
{
j=5;
Eco[i][j]='X';
}
if(seat=="ar")
{
j=2;
Eco[i][j]='X';
}
if(seat=="al")
{
j=3;
Eco[i][j]='X';
}
if(seat=="cr")
{
j=1;
Eco[i][j]='X';
}
if(seat=="cl")
{
j=4;
Eco[i][j]='X';
}
}
}
}
cout<<"First Class";
cout<<endl<<endl<<endl;
for(i=0;i<numOfRowF;i++)
{
for(j=0;j<numOfColumnF;j++)
cout<<First[i][j]<<" ";
cout<<endl<<endl;
}
cout<<"Economy Class";
cout<<endl<<endl<<endl;
for(i=0;i<numOfRowE;i++)
{
for(j=0;j<numOfColumnE;j++)
cout<<Eco[i][j]<<" ";
cout<<endl<<endl;
}
cout<<"Press 'y' to continue this program, 'n' to quit the program";
cin>>quit;
}
}