This is a C question which is almost complete Please help me
This is a C++ question which is almost complete. Please help me to complete it explain to me the process so I can try it over and over. Thanks. // // Airplane.cpp // // Program that displays the seat diagram for an airplane and allows the user // to select a seat. If the seat is available, the program marks it as taken // and displays a new diagram. If the seat is not available, the program says // so and asks for another selection. The program terminates when the user // asks to stop or all seats are taken. // // ************************************************************************** #include <iostream> using namespace std; const int NUMROWS = 7; const int NUMSEATS = 4; void initPlane(char plane[][NUMSEATS], int size1); // POSTCONDITION: // plane[x][0] == \'A\', 0<=x<=6 // plane[x][1] == \'B\', 0<=x<=6 // plane[x][2] == \'C\', 0<=x<=6 // plane[x][3] == \'D\', 0<=x<=6 void printPlane(char msg[], char plane[][NUMSEATS], int size1); // POSTCONDITION: The seating layout of the plane has been printed // to the standard output with an X displayed for each taken seat. void getSeat(char &row, char &seat); // POSTCONDITION: 1 <= row <= 7, \'A\' <= seat <= \'D\' // Note that getSeat does not check to see if the seat has been taken. int main() { int seatsTaken = 0; int seats = NUMROWS * NUMSEATS; char plane[NUMROWS][NUMSEATS]; char keepGoing = \'y\'; char row, seat; int rowIndex, seatIndex; initPlane(plane, NUMROWS); cout << \"Choose your seat!\" << endl; while (seatsTaken < seats && keepGoing == \'y\') { // // Show layout and get seat choice // printPlane(\"Plane layout; X designates taken seats\", plane, NUMROWS); cout << \"Enter the row(1-7) and seat(A-D) you would like (e.g., 3D): \"; getSeat(row, seat); // // Adjust input to use as indices // rowIndex = row - \'1\'; seatIndex = seat - \'A\'; // // Check to see if seat is taken // if (plane[rowIndex][seatIndex] == \'X\') cout << \"Sorry, \" << row << seat << \" is already taken.\" << endl; else { cout << \"OK, you\'ve got \" << row << seat << endl; plane[rowIndex][seatIndex] = \'X\'; seatsTaken++; } // // If there are seats left, see if we should keep going // if (seatsTaken < seats) { cout << \"Choose another seat? (y/n) \"; cin >> keepGoing; } else cout << \"Plane is now full!\" << endl; } printPlane(\"Final seating chart\", plane,NUMROWS); } // -------------------------------- // ----- ENTER YOUR CODE HERE ----- // -------------------------------- // -------------------------------- // --------- END USER CODE -------- // -------------------------------- Solution
Please find below the modified program with my comments which will help you to understand the program. The program is compiled and is bug free:
#include <iostream>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <string>
using namespace std;
const int NUMROWS = 14; //Max. no. of rows we can have is 14
const int NUMSEATS = 7; //Max. no. of seats we can have is 7
void initPlane(char plane[NUMROWS][NUMSEATS]) //Values are {A,B,C,D,E,F};
{
int x,y; //x for NUMROWS & y for NUMSEATS
plane[0][0] = \' \';
plane[0][1] = \'A\';
plane[0][2] = \'B\';
plane[0][3] = \'C\';
plane[0][4] = \'D\';
plane[0][5] = \'E\';
plane[0][6] = \'F\';
plane[1][0] = \'1\';
plane[2][0] = \'2\';
plane[3][0] = \'3\';
plane[4][0] = \'4\';
plane[5][0] = \'5\';
plane[6][0] = \'6\';
for (x = 1; x < NUMROWS ; x++)
{
for ( y = 1 ; y < NUMSEATS ; y++)
plane[x][y] = \'*\'; //* means the seats are available
}
}
// POSTCONDITION as per the question:
// plane[x][0] == \'A\', 0<=x<6
// plane[x][1] == \'B\', 0<=x<6
// plane[x][2] == \'C\', 0<=x<6
// plane[x][3] == \'D\', 0<=x<6
void printPlane(char msg[], char plane[NUMROWS][NUMSEATS])
{
cout << msg << endl;
int Row,col;
for ( Row = 0; Row < NUMROWS ; Row ++)
{
for (col = 0; col < NUMSEATS; col++)
cout << setw(7) << plane [Row][col] << \" \";
cout << endl;
}
}
// POSTCONDITION: The seating layout of the plane has been printed, where X displays taken seats.
int main()
{
int seatsTaken = 0;
int seats = NUMROWS * NUMSEATS;
char plane[NUMROWS][NUMSEATS];
char keepGoing = \'y\';
int row = 0;
char seat;
int rowIndex, seatIndex;
char ticketType[17];
initPlane(plane);
cout << \"Choose your seat!\" << endl;
while (seatsTaken < seats && keepGoing == \'y\')
{
//
// Show the current layout and get the seat choice
//
printPlane(\"Plane layout; X designates taken seats\", plane);
cout << \"Row 1 and 2 are First clss. \" << endl;
cout << \"Rows 3 through 7 are Business class. \" << endl;
cout << \"Rows 8 through 13 are Economy class. \" << endl;
cout << \"Enter ticket type (First class,Business class Or Economy class) :\" ;
cin >> row >> seat;
// Adjust input to use as indices
rowIndex = row;
seatIndex = seat - \'A\';
if ( seat == \'A\' || seat == \'a\' )
seatIndex = 1;
else if ( seat == \'B\' || seat == \'b\' )
seatIndex = 2;
else if ( seat == \'C\' || seat == \'c\' )
seatIndex = 3;
else if ( seat == \'D\' || seat == \'d\' )
seatIndex = 4;
else if ( seat == \'E\' || seat == \'e\' )
seatIndex = 5;
else if ( seat == \'F\' || seat == \'f\' )
seatIndex = 6;
//
// Check to see if seat is taken
//
if (plane[rowIndex][seatIndex] == \'X\')
cout << \"Sorry, \" << row << seat << \" is already taken.\" << endl;
else
{
cout << \"OK, you\'ve got \" << row << seat << endl;
plane[rowIndex][seatIndex] = \'X\';
seatsTaken++;
}
//
// If there are seats left, check we should keep going
//
if (seatsTaken < seats)
{
cout << \"Choose another seat? (y/n) \";
cin >> keepGoing;
}
else
cout << \"Plane is now full!\" << endl;
}
printPlane(\"Final seating chart\", plane);
return 0;
}


