Airplane Problem

Hey guys, im currently working on this project for class and am really stuck.

Here is what the code should do:
Write a program to assign passengers seats in an airplane. Assume a small airplane with seat numbering as follows:

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

The program should display the seat pattern, with an 'X' marking the seats already assigned. For example,
after seats 1A, 2B, and 4C are taken, the display should look like this:

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

After displaying the seats available, the program prompts for the seat desired, the user types in a seat,
and then the display of available seats is updated. This continues until all seats are filled or until the user signlas that the program should end. If the user types in a seat that is already assigned, the program
should say that that seat is occupied and ask for another choice.

The code I have right now has a couple errors, mainly in the display seats method.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <array>

using namespace std;

void displaySeats(char array[]);



void displaySeats(char display[][]){
	for (int row = 0; row < display[row].length; row++){
		cout << "   " << (row + 1) << "  ";
		for (int col = 0; col < display[row].length; col++)
			{cout << "  " << display[row][col] << "  ";}
	}
}


int main( )
{
	char display[7][4] = { {'A', 'B', 'C', 'D'},
						   {'A', 'B', 'C', 'D'},
						   {'A', 'B', 'C', 'D'},
						   {'A', 'B', 'C', 'D'},
						   {'A', 'B', 'C', 'D'},
						   {'A', 'B', 'C', 'D'},
			  			   {'A', 'B', 'C', 'D'}};
	string seat;
	int one, two;
	char r, c;

	cout << "\n Enter Row (1-7) and Seat (A-D) or -1 to stop: ";
	cin >> seat;

	while(seat != ("-1")){
		r = seat[0];
		c = seat[1];
		one = r - '1';
		two = c - 'A';
		if (display[one][two] == 'X'){
			cout << " The Seat is not Available." << endl;
			cout << " Please Pick another Seat." << endl;
		}
		else{
			cout << " The Seat is Available." << endl;
			display[one][two] = 'X';
		}
		displaySeats(display);
	}
	system("pause");
    return 0;
}
Last edited on
Line 13: First dimension of display needs a size. i.e. 7
Line 14: char arrays don't have a length attribute. Use row < 7.
Line 16: Ditto. Here you want the max number of columns. Use col < 4.
Line 9 and 13 signatures don't agree.
Line 18 You're missing a cout << endl; to flush each row
Line 52 You don't prompt for input so you go back to the top of the loop. seat will never be -1 and your loop will continue forever.

Topic archived. No new replies allowed.