Function Display Problem

closed account (o1pz6Up4)
I have a function that displays a seating chart for a flight reservation. Once a seat is booked, the seat is assigned a value of 1. I need the seating chart to display the booked seat in parentheses. I'm stuck on how to get it to do this.

Here is a link to what the output currently looks like:
https://i.imgur.com/xej2Smu.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 void displaySeatingChart(int index)

{
	int x, y;
	cout << "The seats enclosed in () are booked." << endl;

	for (y = 0; y < 16; y++)
	{
		for (x = 0; x < 4; x++)
		{
			cout << "" << y + 1 << seats[x] << " ";
			if (seatingChart[index][y][x] == 1)
			{
				cout << "(" << seatingChart[index][y][x] << ")";
			}
			cout << "\t";
		}
		cout << endl;
	}
}


Hello ImLovelyS2,

Your function looks like it should do the job, but I have some questions.

1. Where is the "display" function defined?

2. "seatingChart[index][y][x]" looks like a 3D array. Where is it defined and how does the function know about this array?

With out the rest of the code I can only guess at what there is to work with. I can put something together to test the function, but it may not be correct or what you have.

I will see what I can come up with.

Andy
closed account (o1pz6Up4)
I was trying to avoid pasting the entire code since it is about 300 lines long.

Here it is on google drive as a word doc.

https://drive.google.com/file/d/16hD7abkQSufNWMFs5d_Smo7YNo6u-RRW/view?usp=sharing
Hello ImLovelyS2,

Thank you. The link works for me.

What I set up to test the function is the same as what you have just not as big.
So, when I tested the function it worked showing reserved seats with "(1)".

Right now I am not finding anything wrong with the "displaySeatingChart" function unless it is from somewhere else in the program. I will check that in a little bit.

Just curious as to what the first dimension is for and why it is of size "8"?

Hope that helps,

Andy
closed account (o1pz6Up4)
The actual seat number itself like, 10C, is supposed to be in parentheses (10C). I'm not sure how to get the program to do that instead of what it is currently doing with the (1).

The first dimension is for the number of flights there are, and there is a total of 8 flights with different ID's.
Last edited on
Hello ImLovelyS2,

To get this output:


The seats enclosed in () are booked.
    (1A) (1)         1B              1C              1D
     2A             (2B) (1)         2C              2D
    (3A) (1)       (3B) (1)        3C              3D
     4A              4B               (4C) (1)      (4D) (1)


I used this code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void displaySeatingChart(int index)
{
	int x, y;
	std::cout << "The seats enclosed in () are booked." << std::endl;

	for (y = 0; y < 4; y++)
	{
		for (x = 0; x < 4; x++)
		{
			if (seatingChart[index][y][x] == 1)
			{
				std::cout << std::setw(5) << "(" << y + 1 << seats[x] << ") ";
				std::cout << "(" << seatingChart[index][y][x] << ")";
			}
			else
				std::cout << std::setw(5) << " " << y + 1 << seats[x] << " ";

			std::cout << "\t";
		}
		std::cout << std::endl;
	}
}

Is this what you are looking for?

Andy

P.S. Overlook the way it lines up. The output of the function looks better.
Last edited on
Hello ImLovelyS2,

Sorry for the extra message. Now the first dimension makes sense.

Andy
closed account (o1pz6Up4)
Well, this is and isn't what I was looking for. I need to have the seat display like it is in the original function. Otherwise, you did manage to get the parentheses around the seat ID, so thank you! I see now how it's done. :)
Hello ImLovelyS2,

Sorry for the delay, but some days some of the posts I work on get by me when I am away from the computer.

The only difference I see between your first output and mine is that mine is indented. Not that the indentation was my first intention. I was just trying to line up the numbers better.

If you do not like my version just remove the "std::setw(5)" from both lines and it will look like your original output.

Hope that helps,

Andy
Topic archived. No new replies allowed.