how to apply array correctly?

Hi, I would like to ask something about multi-dimensional array. Recently i got an assignment that request me to write a program for airplane ticket reservation. The question is as follows:
This program assigns seats for a commercial airplane.
The current seat assignment is as follows.

	A	B	C	D	E	F
Row 1	*	*	*	*	*	*
Row 2	*	*	*	*	*	*
Row 3	*	*	*	*	*	*
Row 4	*	*	*	*	*	*
Row 5	*	*	*	*	*	*
Row 6	*	*	*	*	*	*
Row 7	*	*	*	*	*	*
Row 8	*	*	*	*	*	*
Row 9	*	*	*	*	*	*
Row 10	*	*	*	*	*	*
Row 11	*	*	*	*	*	*
Row 12	*	*	*	*	*	*
Row 13	*	*	*	*	*	*
* -- available seat
X -- occupied seat

Rows 1 and 2 are for first class passengers.
Rows 3 through 7 are for business class passengers.
Rows 8 through 13 are for economy class passengers.
To reserve a seat enter Y/y (Yes), N/n(No):
Y

Enter ticket type: F/f (first class); (B/b) (business class); E/e (economy class) : f

Enter Row number 1 – 2: 1

Enter seat number (A – F): A
 

This seat is reserved for you
	A	B	C	D	E	F
Row 1	X	*	*	*	*	*
Row 2	*	*	*	*	*	*
Row 3	*	*	*	*	*	*
Row 4	*	*	*	*	*	*
Row 5	*	*	*	*	*	*
Row 6	*	*	*	*	*	*
Row 7	*	*	*	*	*	*
Row 8	*	*	*	*	*	*
Row 9	*	*	*	*	*	*
Row 10	*	*	*	*	*	*
Row 11	*	*	*	*	*	*
Row 12	*	*	*	*	*	*
Row 13	*	*	*	*	*	*
* -- available seat
X -- occupied seat

This program assigns seats for a commercial airplane.
The current seat assignments is as follows.

	A	B	C	D	E	F
Row 1	X	*	*	*	*	*
Row 2	*	*	*	*	*	*
Row 3	*	*	*	*	*	*
Row 4	*	*	*	*	*	*
Row 5	*	*	*	*	*	*
Row 6	*	*	*	*	*	*
Row 7	*	*	*	*	*	*
Row 8	*	*	*	*	*	*
Row 9	*	*	*	*	*	*
Row 10	*	*	*	*	*	*
Row 11	*	*	*	*	*	*
Row 12	*	*	*	*	*	*
Row 13	*	*	*	*	*	*
* -- available seat
X -- occupied seat

Rows 1 and 2 are for first class passengers.
Rows 3 through 7 are for business class passengers.
Rows 8 through 13 are for economy class passengers.
Reserve another seat Y/y(yes), N/n(No): n


The bold is user input. I currently successful to make an output shown as above, but the problem I encountered is that I can't assign the asterisks and "X" in a character form, if I do so, it gives me something like hexadecimal or octal code, as shown below:
This program assigns seats for a commercial airplane.
The current seat assignment is as follows.

                A       B       C       D       E       F
Row 1           *       *       *       *       *       *
Row 2           *       *       *       *       *       *
Row 3           *       *       *       *       *       *
Row 4           *       *       *       *       *       *
Row 5           *       *       *       *       *       *
Row 6           *       *       *       *       *       *
Row 7           *       *       *       *       *       *
Row 8           *       *       *       *       *       *
Row 9           *       *       *       *       *       *
Row 10          *       *       *       *       *       *
Row 11          *       *       *       *       *       *
Row 12          *       *       *       *       *       *
Row 13          *       *       *       *       *       *

* -- available seat
X -- occupied seat

Rows 1 and 2 are for first class passengers.
Rows 3 through 7 are for business class passengers.
Rows 8 through 13 are for economy class passengers.
To reserve a seat enter Y/y (Yes), N/n(No):
y
Enter ticket type: F/f (first class); (B/b) (business class); E/e (economy class
) :f


Enter Row number 1 û 2: 1


Enter Seats A - F: a
The seats is reserved for you.

                A       B       C       D       E       F
Row 1           0012FEE0        0012FEE0        0012FEE0        0012FEE0
0012FEE0        0012FEE0
Row 2           0012FEE0        0012FEE0        0012FEE0        0012FEE0
0012FEE0        0012FEE0
Row 3           0012FEE0        0012FEE0        0012FEE0        0012FEE0
0012FEE0        0012FEE0
Row 4           0012FEE0        0012FEE0        0012FEE0        0012FEE0
0012FEE0        0012FEE0
Row 5           0012FEE0        0012FEE0        0012FEE0        0012FEE0
0012FEE0        0012FEE0
Row 6           0012FEE0        0012FEE0        0012FEE0        0012FEE0
0012FEE0        0012FEE0
Row 7           0012FEE0        0012FEE0        0012FEE0        0012FEE0
0012FEE0        0012FEE0
Row 8           0012FEE0        0012FEE0        0012FEE0        0012FEE0
0012FEE0        0012FEE0
Row 9           0012FEE0        0012FEE0        0012FEE0        0012FEE0
0012FEE0        0012FEE0
Row 10          0012FEE0        0012FEE0        0012FEE0        0012FEE0
0012FEE0        0012FEE0
Row 11          0012FEE0        0012FEE0        0012FEE0        0012FEE0
0012FEE0        0012FEE0
Row 12          0012FEE0        0012FEE0        0012FEE0        0012FEE0
0012FEE0        0012FEE0
Row 13          0012FEE0        0012FEE0        0012FEE0        0012FEE0
0012FEE0        0012FEE0
Press any key to continue . . .


Currently I just do for the first section. And can anyone help me to solve my problem out. My code are as follows:
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//header declaration
#include <iostream>
#include <cctype>
using namespace std;

//function declaration


//main function
int main()
{
	int i, j;
	char seat_resvr;
	char tic_type;
	char availability [13][6], reserved[2];
	int row_num, col_num;
	char seats;

	cout << "This program assigns seats for a commercial airplane." << endl << "The current seat assignment is as follows." << endl << endl << "\t\tA\tB\tC\tD\tE\tF" << endl;

	for (i=0; i<13; i++){
		cout << "Row " << i+1 << "\t\t";
		for (j=0; j<6; j++){
			cout << "*" << "\t";
		}
		cout << endl;
	}

	cout << endl << "* -- available seat" << endl 
		<< "X -- occupied seat" << endl << endl
		<< "Rows 1 and 2 are for first class passengers."<< endl
		<<"Rows 3 through 7 are for business class passengers."<< endl
		<<"Rows 8 through 13 are for economy class passengers."<< endl;
	cout << "To reserve a seat enter Y/y (Yes), N/n(No):" << endl;
	cin >> seat_resvr;
	reserved [2] = 'X';

	if(toupper(seat_resvr) == 'Y')
	{
		fflush (stdin);
		cout << "Enter ticket type: F/f (first class); (B/b) (business class); E/e (economy class) :";
		cin >> tic_type;

		if (toupper(tic_type)=='F')
		{
			cout << endl << endl 
				<< "Enter Row number 1 \– 2: ";
			cin >> row_num;
			i = row_num;
			cout << endl << endl
				<< "Enter Seats A - F: ";
			cin >> seats;
			switch (toupper(seats))
			{
			case 'A':
				col_num = 0;
				break;
			case 'B':
				col_num = 1;
				break;
			case 'C':
				col_num = 2;
				break;
			case 'D':
				col_num = 3;
				break;
			case 'E':
				col_num = 4;
				break;
			case 'F':
				col_num = 5;
				break;
			default:
				break;
			}
			j = col_num;
			availability [i][j] = reserved[2];

		}
	}
	cout << "The seats is reserved for you." << endl << endl 
		<< "\t\tA\tB\tC\tD\tE\tF" << endl;

	for (i=0; i<13; i++){
		cout << "Row " << i+1 << "\t\t";
		for (j=0; j<6; j++){
			cout << availability << "\t";
		}
		cout << endl;
	}






	return 0;
}


It also says that run-time check failure or the variable is being used with out determined and stacked around the variables.

Thanks for your kindness to help me out.

Kenneth
Last edited on

Your missing array subscripts in the following code, your printing out availability which is the address of the start of the array

1
2
3
4
5
6
7
for (i=0; i<13; i++){
		cout << "Row " << i+1 << "\t\t";
		for (j=0; j<6; j++){
			cout << availability[i][j] << "\t";
		}
		cout << endl;
	}
After putting the subscript in it, yet it still give me some of the error during debug time. such as variable being used without determined. How can I counter that problems?

This program assigns seats for a commercial airplane.
The current seat assignment is as follows.

                A       B       C       D       E       F
Row 1           *       *       *       *       *       *
Row 2           *       *       *       *       *       *
Row 3           *       *       *       *       *       *
Row 4           *       *       *       *       *       *
Row 5           *       *       *       *       *       *
Row 6           *       *       *       *       *       *
Row 7           *       *       *       *       *       *
Row 8           *       *       *       *       *       *
Row 9           *       *       *       *       *       *
Row 10          *       *       *       *       *       *
Row 11          *       *       *       *       *       *
Row 12          *       *       *       *       *       *
Row 13          *       *       *       *       *       *

* -- available seat
X -- occupied seat

Rows 1 and 2 are for first class passengers.
Rows 3 through 7 are for business class passengers.
Rows 8 through 13 are for economy class passengers.
To reserve a seat enter Y/y (Yes), N/n(No):
y
Enter ticket type: F/f (first class); (B/b) (business class); E/e (economy class
) :f


Enter Row number 1 û 2: 1


Enter Seats A - F: a
The seats is reserved for you.

                A       B       C       D       E       F
Row 1      ╠       ╠       ╠       ╠       ╠       ╠
Row 2      *       ╠       ╠       ╠       ╠       ╠
Row 3      ╠       ╠       ╠       ╠       ╠       ╠
Row 4      ╠       ╠       ╠       ╠       ╠       ╠
Row 5      ╠       ╠       ╠       ╠       ╠       ╠
Row 6      ╠       ╠       ╠       ╠       ╠       ╠
Row 7      ╠       ╠       ╠       ╠       ╠       ╠
Row 8      ╠       ╠       ╠       ╠       ╠       ╠
Row 9      ╠       ╠       ╠       ╠       ╠       ╠
Row 10    ╠       ╠       ╠       ╠       ╠       ╠
Row 11    ╠       ╠       ╠       ╠       ╠       ╠
Row 12    ╠       ╠       ╠       ╠       ╠       ╠
Row 13    ╠       ╠       ╠       ╠       ╠       ╠
Press any key to continue . . .


this is what i get after i edited in the subscript part. Can anyone tell me what is the solution for this?
You need to initialize each char in availability to '*' in your first loop.

1
2
3
4
5
6
7
8
9
10
for (i=0; i<13; i++)
{
  cout << "Row " << i+1 << "\t\t";
  for (j=0; j<6; j++)
  {
    cout << "*" << "\t";
    availability[i][j] = '*';
}
  cout << endl;
}


Also remove \ from following line, this is an invalid escape code, notice your output is 1 û 2: instead of 1 - 2:

<< "Enter Row number 1 \– 2: ";
to
<< "Enter Row number 1 – 2: ";

Also you are defining char reserved[2]; and assigning reserverd[2] = 'X', which is off the end of the array. Valid array entries are 0 and 1. You don't need this to be an array. Make it a single char.

1
2
char reserved;
reserved = 'X';

Topic archived. No new replies allowed.