Hi, I got a program and I am finished except for the last portion of the program. It is where I print the final seating chart. Can you help? Here is my code:

#include <iostream>
using namespace std;

const int NUMROWS = 7;
const int NUMSEATS = 4;

void initPlane(char plane[NUMROWS][NUMSEATS]);
// 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[NUMROWS][NUMSEATS]);
// 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);

  cout << "Choose your seat!" << endl;
  while (seatsTaken < seats && keepGoing == 'y')
    {
      //
      // Show layout and get seat choice
      // 
      printPlane("Plane layout; X designates taken seats", plane);
      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);
}

<< moderator edit: added [code][/code] tags >>

?????????????????

Recommended Answers

All 6 Replies

These are just prototypes.

void initPlane(char plane[NUMROWS][NUMSEATS]);
// 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[NUMROWS][NUMSEATS]);
// 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.

The don't get magically filled with 'Do What Is Right' instructions. You need to supply the source code. What have you tried?

The output suppose to look like this:

1 A B C D
2 A B C D
3 A B C D
4 A B C D
5 A B C D
6 A B C D
7 A B C D

an X suppose to take the place of one of the letter designations if the seat is taken. The aisle is between B and C but when I save this message it puts them together as if it had no space.

The only thing I am missing is the output of the above grid.
I have tried doing setw(n) and doing it that way with cout statements.
That seems to be the long way of doing it. Is there a shorter way?

This is the code that I added for my program:

void initPlane(char plane[NUMROWS][NUMSEATS]);

for (int y = 0; y<1; y++);
for (y = 1; y<6; y++);
{
	for (int x = 0; x<1; x++);
	plane [y][x] = 'A';
	for (int v = 0; v<1; v++);
	plane [y][v] = 'B';
	for (int w = 0; w<1; w++);
	plane [y][w] = 'C';
	for (int z = 0; z<1; z++);
	plane [y][z] = 'D';
}

void printPlane(char msg[], char plane[NUMROWS][NUMSEATS]);

for (r = 0; r<7; r++)
{
	cout << setw(2) << r+1<< endl;
	for (int s = 0; s<4; s++)
	{
		cout << plane[r][s] << endl;
	}
}


void getSeat(char &row, char &seat);

{

}

<< moderator edit: added code tags: [code][/code] >>

Prototypes end in a semicolon. Function definitions do not -- the code therein goes between { and }.

Empty for loops end in a semicolon. If you want the loop to do something, again place that code between { and }.

You have both syntax as well as logic errors in your code. I have commented as to the syntax errors and I think you'll be able to see the logic errors as you read the comments.

void initPlane(char plane[NUMROWS][NUMSEATS]); //remove ;
                                                                     //place { here
for (int y = 0; y<1; y++);                                  //erase entire line
                                                                    //not needed

for (y = 1; y<6; y++);                                      //do the following 5 times.  This represents one row of plane per loop.
{
            	for (int x = 0; x<1; x++); //one loop is all, x will only be 0
	plane [y][x] = 'A';   //put A in the first seat of this row

	for (int v = 0; v<1; v++);//one loop is all, v will only be 0
	plane [y][v] = 'B';  //put B in first seat of this row

	for (int w = 0; w<1; w++);//one loop is all, w will only be 0
	plane [y][w] = 'C'; //put C in first seat of this row

	for (int z = 0; z<1; z++);//one loop is all, z will only be 0
	plane [y][z] = 'D'; //put D in first seat of this row
}
//need closing } to end function here.

Rather than the single loops overwriting seat with index 0 each time it would be more logical to just hardcode which seat you want to have which letter.

plane[y][0] = 'A';
plane[y][1] = 'B';
//etc.

This way y indicates which row and seat with index 0 will always be set to A in each row, seat with index 1 will always be set to B, etc. If you feel comfortable with arrays starting with index 0 and routine representation starting with 1 you can adjust output for internal representation and switch the external for loop to run from 0 and < 5 rather than 1 to < 6. Eventually it's just easier to do that, than to remember you have to avoid calling row with index 0 as you try to do
here (note: same syntax errors as above exist here, too).

void printPlane(char msg[], char plane[NUMROWS][NUMSEATS]);

for (r = 0; r<7; r++)
{
	cout << setw(2) << r+1<< endl;
	for (int s = 0; s<4; s++)
	{
		cout << plane[r][s] << endl;

Thanks for the tip. I solved my problem.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.