Arrays and changing an int into a symbol

Good Morning,
I have two questions, the first is is it possible to have a user defined array reference an array for changing its data.

The second one is I need to output if a seat is assigned with the characters * and X. I have it loaded into the array as 1 and 2 with 1 being for available (or *). How do I make it so the character output matches required.


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

#include <iostream> //allows use of cout and endl commands
#include <iomanip>  // allows use of manipulation commands (setprecision, ect)


using namespace std; //This line allows you to use cin, cout and endl without the std:: prefix
// function declaration so function can be put after main
void menu(); 
void openSeats(int seats[13][6]);
//int firstClassSeat(int &seats[13][6]);
//int businessClassSeats(int &seats[13][6]);
//int economySeats(int &seats[13][6]);
//static variables to avoid global variables
static int choice;
static int seats[13][6] = { {1, 1, 2, 1, 2, 2},//Row 1
							{1, 2, 1, 2, 1, 2},//Row 2
							{1, 1, 2, 2, 1, 2},//Row 3
							{2, 1, 2, 1, 2, 2},//Row 4
							{1, 2, 1, 2, 1, 1},//Row 5
							{1, 2, 1, 1, 1, 2},//Row 6
							{2, 1, 1, 1, 2, 2},//Row 7
							{1, 2, 1, 2, 2, 1},//Row 8
							{2, 1, 2, 2, 1, 2},//Row 9
							{1, 2, 1, 2, 2, 2},//Row 10
							{1, 1, 2, 1, 2, 1},//Row 11
							{1, 1, 2, 2, 1, 2},//Row 12
							{1, 1, 1, 1, 2, 1} };//Row 13

//menu choices
static const int DISPLAYSEATS = 1, FIRSTCLASS = 2, BUSINESSCLASS = 3, ECONOMY = 4, QUIT = 9;
int main()//heading of the function main, every program must have a main function
{
	//info line
	cout << "This program allows you to pick a seat for your upcoming flight. " << endl;
	cout << endl;

	//start of loop
	do
	{
		menu(); //show menu function
		switch (choice) //switch start
		{
		//cases to execute functions
		case DISPLAYSEATS: 
			openSeats(seats);
			break;

		case FIRSTCLASS:
			//firstClassSeat(seats);
			break;

		case BUSINESSCLASS:
			//businessClassSeats(seats);
			break; 

		case ECONOMY:
			//economySeats(seats);
			break;
		}
	} while (choice != QUIT); //if 8 is entered quits the program
	system("pause"); //pauses the command window to see program running
	return 0; //ends the program
}

void menu()// sets function type as one that is not returning data to the program, only displays the menu choices, all text
{
	cout << endl;
	cout << "Menu Choices: " << endl;
	cout << endl;
	cout << "Press 1 to display all open seats: " << endl;
	cout << "Press 2 to reserve a first class seat: " << endl;
	cout << "Press 3 to reserve a business class seat: " << endl;
	cout << "Press 4 to reserve an economy class seat: " << endl;
	cout << "Press 9 to exit the program: " << endl;
	cout << "Please enter a selection: ";
	cin >> choice; //variable for selection from menu function
}
void openSeats(int seats[13] [6])//shows seat menu
{
	cout << endl << "The current status of the seats on this flight are: . " << endl; 
	
	cout << setw(10) << "A" << setw(5) << "B" << setw(5) << "C" << setw(5) << "D" << setw(5) << "E" << setw(5) << "F" << endl;
	cout << "Row 1" << setw(5) << seats[0][0] << setw(5) << seats[0][1] << setw(5) << seats[0][2] << setw(5) << seats[0][3] << setw(5) << seats[0][4] << setw(5) << seats[0][5] << setw(5) << endl;

	cout << endl << "Seats available for occupancy are indicated by a *. " << endl;
}
//int firstClassSeat(int &seats[13][6])
//{
//	return seats[13][6];
//}
//int businessClassSeats(int &seats[13][6])
//{
//	return seats[13][6];
//}
//int economySeats(int &seats[13][6])
//{
//	return seats[13][6];
//} 
1
2
3
4
5
6
7
for ( size_t row=0; row < 13; ++row ) {
  std::cout << "Row " << row+1;
  for ( size_t col=0; col < 6; ++col ) {
    std::cout << setw(5) << (seats[row][col] == 2 ? 'X' : '*');
  }
  std::cout << '\n';
}

That uses the ternary operator ? :.

However, why the array has integers? What if I put other than 1 or 2 into it? How about array of bool, where taken and free are true and false, respectively?
Thank you very much, that helped alot!
Topic archived. No new replies allowed.