Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Airline seating. Design and implement a program that assigns seats on an airplan

ID: 3541029 • Letter: A

Question

Airline seating. Design and implement a program that assigns seats
on an airplane. Assume the airplane has 20 seats in ?rst class (5 rows of 4 seats each, separated by an aisle) and 180 seats in economy class (30 rows of 6 seats each, sepa-
rated by an aisle). Your program should take three commands: add passengers,
show seating, and quit. When passengers are added, ask for the class (?rst or econ-
omy), the number of passengers traveling together (1 or 2 in ?rst class; 1 to 3 in
economy), and the seating preference (aisle or window in ?rst class; aisle, center, or
window in economy). Then try to ?nd a match and assign the seats. If no match
exists, print a message. Follow the design process that was described in this chapter.

Explanation / Answer

please rate - thanks


#include <iostream>
#include <string>
using namespace std;
int mainMenu();
int getclass();
int traveling(int);
int seating(int);
void addf(char[][4]);
void adde(char[][6]);
void draw(char[][4],char[][6]);
int main()
{int choice,i,j;
char first[5][4],eco[30][6];
for(i=0;i<5;i++)
    for(j=0;j<4;j++)
         first[i][j]='-';
for(i=0;i<30;i++)
    for(j=0;j<6;j++)
         eco[i][j]='-';        
choice=mainMenu();
while(choice!=3)
    {if(choice==1)
         {choice=getclass();
          if(choice==1)
               addf(first);
          else
               adde(eco);
               }
    else if(choice==2)
         {draw(first,eco );
          }
    else if(choice!=3)
         cout<<"Invalid entry ";
     choice=mainMenu();           
     }
}
int getclass()
{int choice;
cout<<"1 - first class 2 - economy >> ";
cin>>choice;
while(choice<1||choice>2)
    {cout<<"Invalid entry ";
     cout<<"1 - first class 2 - economy >> ";
     cin>>choice;
     }
return choice;
}
int traveling(int n)
{int choice;
cout<<"How many people are traveling together (max "<<n<<"): ";
cin>>choice;
while(choice<1||choice>n)
    {cout<<"Invalid entry ";
      cout<<"How many people are traveling together (max "<<n<<"): ";
      cin>>choice;
      }
return choice;                  
}
int mainMenu()
{int choice;
cout<<"Enter choice ";
cout<<"1 - add passengers ";
cout<<"2 - show seating ";
cout<<"3 - quit ";
cout<<">> ";
cin>>choice;
return choice;
}
void addf(char f[][4])
{int choice,num,i,j,k,s;
int aisle[2][2]={1,2,0,4};
bool found;
num=traveling(2);
      for(i=1;i<=num;i++)
          {cout<<"passenger "<<i<<" enter seating choice: ";
          s=seating(0);
      found=false;
          j=-1;
          while(!found&&j<4)
             {j++;
             for(k=0;k<2&&!found;k++)
              if(f[j][aisle[s][k]]=='-')
                 {f[j][aisle[s][k]]='X';
                 found=true;
                 }
                            }
if(found)
    cout<<"seat found row "<<j+1<<endl;
else
    cout<<"seat not found ";
}

}
void adde(char e[][6])
{int choice,num,i,j,k,s;
bool found;
int aisle[3][2]={2,3,1,4,0,5};
num=traveling(3);
      for(i=1;i<=num;i++)
          {cout<<"passenger "<<i<<" enter seating choice: ";
          s=seating(1);
          found=false;
          j=-1;
          while(!found&&j<29)
             {j++;
             for(k=0;k<2&&!found;k++)
              {
              if(e[j][aisle[s][k]]=='-')
                 {e[j][aisle[s][k]]='X';
                  found=true;
                 }
              }
            }
if(found)
    cout<<"seat found row "<<j+6<<endl;
else
    cout<<"seat not found ";
}
}
int seating(int n)
{int choice=0;
string mess[3]={"aisle","window","center"};
int order[2][3]={0,1,0,0,2,1};
int max[2]={2,3};
int i,j;
while(choice<1||choice>max[n])
   {cout<<"enter seat selection ";
   for(i=0;i<max[n];i++)
        cout<<i+1<<" - "<<mess[order[n][i]]<<endl;
   cout<<">> ";
    cin>>choice;
    if(choice<1||choice>max[n])
         cout<<"invalid entry ";
}
return choice-1;
}

void draw(char f[][4],char e[][6])
{int i,j;
cout <<"Seating X=assigned seat -=unassigned seat ";
for(i=0;i<5;i++)
    {cout<<" ";
     for(j=0;j<4;j++)
         {cout<<f[i][j]<<" ";
         if(j==1)
             cout<<"   ";
             }
      cout<<endl;
     }
for(i=0;i<30;i++)
    {for(j=0;j<6;j++)
         {cout<<e[i][j]<<" ";
         if(j==2)
             cout<<"   ";
             }
      cout<<endl;
     }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote