C++ Airplane Seating Code Design and implement a program that assigns seats on a
ID: 3672130 • Letter: C
Question
C++ Airplane Seating Code
Design and implement a program that assigns seats on an airplane. Assume the airplane has 20 seats in the first class (5 rows of 4 seats each, separated by an isle) and 180 seats in the economy class (30 rows of 6 seats each, separated by an isle). Your program should take three commands: add passengers, show seating, and quit. When passengers are added, ask for the class (first or the economy), the number of passengers traveling together (1 to 2 in the first class, 1 to 3 in the economy), and the seating preference (aisle or a window in the first class; aisle, center or window in economy). Then try to find a match and assign the seats. If no match exits, print a message. Follow the object printed design process.
Explanation / Answer
#include <iostream>
#include <string>
#include <stdio.h>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
int airplane[5][4];(first class)
char airchar[5][4];
int air plane[30][6];(economy)
char air char[30][6];
string ticket;
int row[2];
char seat;
for(int i = 0; i < 5; i++)
{
for(int j = 0; j < 4; j++)
{
airchar[i][j] = '*';
airplane[i][j] = 0;
}
}
for(;;)
{
cout<<"Rows 1 and 2 are first class (FC)"<<endl;
cout<<"Rows 1 through 3 are economy class (EC)"<<endl;
cout<<endl;
cout<<"* - Available"<<endl;
cout<<"X - Occupied"<<endl;
cout<<endl;
cout<<" A B C D E F"<<endl;
cout<<"Row 1 "<<airchar[0][0]<<" "<<airchar[0][1]<<" "
<<airchar[0][2]<<" "<<airchar[0][3]<<" "<<airchar[0][4]<<" "
<<airchar[0][5]<<endl;
cout<<"Row 2 "<<airchar[1][0]<<" "<<airchar[1][1]<<" "
<<airchar[1][2]<<" "<<airchar[1][3]<<" "<<airchar[1][4]<<" "
<<airchar[1][5]<<endl;
cout<<"Row 3 "<<airchar[2][0]<<" "<<airchar[2][1]<<" "
<<airchar[2][2]<<" "<<airchar[2][3]<<" "<<airchar[2][4]<<" "
<<airchar[2][5]<<endl;
cout<<endl;
cout<<"Enter Ticket type (FC, EC): ";
cin>>ticket;
cout<<"Desired Row: ";
cin>>row[0];
cout<<"Desired seat (A,B,C,D,E or F): ";
cin>>seat;
switch(seat)
{
case 'A':case 'a':
row[0] = row[0] - 1; row[1] = 1;
row[1] = row[1] - 1;
break;
case 'B':
case 'b':
row[0] = row[0] - 1;
row[1] = 2;
row[1] = row[1] - 1;
break;
case 'C':
case 'c':
row[0] = row[0] - 1;
row[1] = 3;
row[1] = row[1] - 1;
break;
case 'D':
case 'd':
row[0] = row[0] - 1;
row[1] = 4;
row[1] = row[1] - 1;
break;
case 'E':
case 'e':
row[0] = row[0] - 1;
row[1] = 5;
row[1] = row[1] - 1;
break;
case 'F':
case 'f':
row[0] = row[0] - 1;
row[1] = 6;
row[1] = row[1] - 1;
break;
}
if(ticket == "FC")
{
if(row[0]+1 == 1 || row[0]+1 == 2)
{
if(airplane[row[0]][row[1]] == 0)
{
airplane[row[0]][row[1]] = 1;
airchar[row[0]][row[1]] = 'X';
}
else if(airplane[row[0]][row[1]] == 1)
{
cout<<"Message: Seat "<<row[0] + 1<<seat<<" is already occupied"<<endl;
system("Pause");
}
}
else
{
cout<<"Wrong Class"<<endl;
system("Pause"); system("cls");continue;
}
}
else if(ticket == "EC")
{
if(row[0]+1 == 1|| row[0]+1 == 2 || row[0]+1 == 3
{
if(airplane[row[0]][row[1]] == 0)
{
airplane[row[0]][row[1]] = 1;
airchar[row[0]][row[1]] = 'X';
}
else if(airplane[row[0]][row[1]] == 1)
{
cout<<"Message: Seat "<<row[0] + 1<<seat<<" is already occupied"<<endl;
system("Pause");
}
}
else
{
cout<<"Wrong Class"<<endl;
system("Pause");
system("cls");
continue;
}
}
row[0] = 0;
row[1] = 0;
system("cls");
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.