Adding space in-between seating array

Hello. I was given a C++ assignment about seating array. The codes below is retrieved from someone(not my original) and are modified according to my task requirement. The problem is, the seating display does not have spaces between them. It was supposed to be 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

But instead, it shows this:

1ABCD
2ABCD
3ABCD
4ABCD
5ABCD
6ABCD
7ABCD

My friends are all using different method. None of them do this type of coding. Can this code be modified to show the result that I want ? or do I have to use different 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
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>
#include <cmath>

const int MAX_ROW = 8;//this translates to 7 since row-1 is used for the printing of the table
const int MAX_SEAT = 4;

void display_seating(char a[][MAX_SEAT], int rows);
void seat_availability(char a[][MAX_SEAT], int rows);

bool assign_seat(char a[][MAX_SEAT], int rows, int row, int col);

int main()
{
using namespace std;

int row, col;
int input_row;

char input_seat;
char seat[MAX_ROW][MAX_SEAT], ans;

cout << "Welcome to my system..."
	 << "\nHere is all available seat to choose" << endl << endl;

for(row = 0; row < MAX_ROW; row++)
for(col = 0; col < MAX_SEAT; col++)seat[row][col] = static_cast<char>(toupper('A') + col);

display_seating(seat,MAX_ROW);

	cout << " \nInstruction: "
	<< "\n	Please press row number, press space bar and press seat number. "
	<< "\n\n	X mean the seat is not available " << endl;

do
{
	seat_availability(seat,MAX_SEAT);

	cout << "\nPlease choose your seat: ";
	cin >> input_row >> input_seat;

	col = toupper(input_seat) - toupper('A');
	input_seat = col;

	// Check to see if seat is taken
	if (seat[input_row-1][col] == 'X')
	cout << "\nSeat is not available" << endl;
	else
	{
	cout << "\nLatest available seat to choose " << endl << endl;
	seat[input_row-1][col]='X';

	//now input an 'X' for the seat taken
	display_seating(seat,MAX_ROW);

	}	

	cout << "\nBook another seat?(y/n): ";
	cin >> ans;
	}while (ans == 'Y' || ans == 'y');

return 0;

}

void display_seating(char a[] [MAX_SEAT], int rows)

{
using namespace std;

for(int row = 1; row < rows; row++)
{
cout << row;

for(int col = 0; col < MAX_SEAT; col++)
{
//I subtracted 1 from row to match row to the index
cout << a[row-1][col];
}
cout << endl;
}

}

void seat_availability(char a[][MAX_SEAT], int rows)

{
using namespace std;
for(int row = 1; row < rows; row++)
for(int col = 0; col < MAX_SEAT; col++)

// if my target array does not have an 'X' in it
if (a[row-1][MAX_SEAT] != 'X')
{
	// do nothing
	;
}else
	cout << "The seats are full! please try a different one";
}
Last edited on
For your final string, do this
1
2
3
4
5
6
7
8
9
10
11
12
vector<string> yournewstring;
for(int i = 0; i < yourstring.length(); i++)
{
     yournewstring.push_back(yourstring[i]);
     yournewstring.push_back(" ");
}
string finalString
for(int i = 0; i < yournewstring.size(); i++)
{
     finalString += yournewstring[i]
}
cout << finalString;
Okay. I've tried your solution Code Apperentice. But I've found an easier way to do it.

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
99
100

#include <iostream>
#include <cmath>

const int MAX_ROW = 8;//this translates to 7 since row-1 is used for the printing of the table
const int MAX_SEAT = 4;

void display_seating(char a[][MAX_SEAT], int rows);
void seat_availability(char a[][MAX_SEAT], int rows);

bool assign_seat(char a[][MAX_SEAT], int rows, int row, int col);

int main()
{
using namespace std;

int row, col;
int input_row;

char input_seat;
char seat[MAX_ROW][MAX_SEAT], ans;

cout << "Welcome to my system..."
	 << "\nHere is all available seat to choose" << endl << endl;

for(row = 0; row < MAX_ROW; row++)
for(col = 0; col < MAX_SEAT; col++)seat[row][col] = static_cast<char>(toupper('A') + col);

display_seating(seat,MAX_ROW);

	cout << " \nInstruction: "
	<< "\n	Please press row number, press space bar and press seat number. "
	<< "\n\n	X mean the seat is not available " << endl;

do
{
	seat_availability(seat,MAX_SEAT);

	cout << "\nPlease choose your seat: ";
	cin >> input_row >> input_seat;

	col = toupper(input_seat) - toupper('A');
	input_seat = col;

	// Check to see if seat is taken
	if (seat[input_row-1][col] == 'X')
	cout << "\nSeat is not available" << endl;
	else
	{
	cout << "\nLatest available seat to choose " << endl << endl;
	seat[input_row-1][col]='X';

	//now input an 'X' for the seat taken
	display_seating(seat,MAX_ROW);

	}	

	cout << "\nBook another seat?(y/n): ";
	cin >> ans;
	}while (ans == 'Y' || ans == 'y');

return 0;

}

void display_seating(char a[] [MAX_SEAT], int rows)

{
using namespace std;

for(int row = 1; row < rows; row++)
{
cout << row << " ";

for(int col = 0; col < MAX_SEAT; col++)
{
//I subtracted 1 from row to match row to the index
cout << a[row-1][col] << " ";
}
cout << endl;
}

}

void seat_availability(char a[][MAX_SEAT], int rows)

{
using namespace std;
for(int row = 1; row < rows; row++)
for(int col = 0; col < MAX_SEAT; col++)

// if my target array does not have an 'X' in it
if (a[row-1][MAX_SEAT] != 'X')
{
	// do nothing
	;
}else
	cout << "The seats are full! please try a different one";
}
Last edited on
Topic archived. No new replies allowed.