Write a program that can be used to show available seats for a commercial airpla
ID: 3933721 • Letter: W
Question
Write a program that can be used to show available seats for a commercial airplane. The airplane has 13 rows with six seats in each row. Rows 1 and 2 are first class, rows 3 through 7 are business class, and rows 8 through 13 are economy class. Output the seating plan in the form shown in Table 0.1. In this table, * indicates that the seat is available; "F", "B", and "E" indicate that a first class, a business class, and an economy class seat is occupied, respectively. You should use a two dimensional character array with elements {*F, B, E}. You can assign hard coded values to this array. Extra Credit: Instead of "hard coding". your program can prompt the user to enter the following information: Ticket type (first class, business class, or economy class) Desired seat How to display data as a table in console: To display the table of airplane seating plan, you can use pipe ("|") to print vertical lines, dash ("-") to print horizontal lines and plus sign ('+') to print intersections between horizontal and vertical lines. For example to print the first lines of the mentioned table: #include //std:: setw//... const int nameWidth = 5; coutExplanation / Answer
#include<iostream>
#include<cctype>
#include<iomanip>
using namespace std;
void getdata(char& tickettype, int& row,char& column);
void printform(char form[][6], int row, char column);
int main()
{
char ch,tickettype,column;
int row;
char form[13][6];
cout<<"This Program for assigns seats for a plane... " <<"Do u want to start booking now? Y/y for yes , N/n for no."<<endl;
cin>>ch;
ch=static_cast<char>(toupper(ch));
while(ch=='Y')
{
getdata(tickettype,row,column);
printform(form,row,column);
cout<<"This Program for assigns seats for a plane... " <<"Do u want to start booking now? Y/y for yes , N/n for no."<<endl;
cin>>ch;
ch=static_cast<char>(toupper(ch));
if(ch=='N')
return 0;
}
system("PAUSE");
return 0;
}
void getdata(char& tickettype, int& row,char& column)
{
cout<<"The airpalne has 13 rows,with six seats in each row."<<endl;
cout<<"Enter ticket type, "<<"F for first class: "<<"B for business class: "<<"E for economy class:"<<endl;
cin>>tickettype;
tickettype=static_cast<char>(toupper(tickettype));
while(tickettype != 'F' && tickettype != 'B' && tickettype != 'E')
{
cout<<"Invlaid ticket type."<<endl;
cout<<"Enter ticket type: "<<"F/f for first class: "<<"B/b for business class: "<<"E/e for economy class:"<<endl;
cin>>tickettype;
tickettype=static_cast<char>(toupper(tickettype));
}
switch(tickettype)
{
case 'F':cout<< "Row 1 and 2 are first class: ";
break;
case 'B':cout<< "Row 3 through 7 are business class: ";
break;
case 'E':cout<< "Row 8 through 13 are economy class: ";
break;
}
cout<<"Enter the row number u want to sit: "<<endl;
cin>>row;
cout<<"Enter the seat number (from A to f). "<<endl;
cin>>column;
column=static_cast<char>(toupper(column));
}
void printform(char form[][6], int row, char column)
{
int i,j;
cout<< "* indicates that seat is available: "<<endl;
cout<< "X indicates that the seat is occupied. "<<endl;
cout<<setw(12)<<"A" <<setw(6)<<"B"<<setw(6)<<"C"<<setw(6)<<"D"<<setw(6)<<"E"<<setw(6)<<"F"<<endl;
for(i=0;i<13;i++)
{
cout<<left<<setw(3) << "Row" << setw(2)<<i+1;
for(j=0;j<6;j++)
{
if(i==row-1 && j==static_cast<int>(column)-65)
cout<<right<<setw(6)<<"X";
else
cout<<right<<setw(6)<<"*";
}
cout<<endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.