Airplane seating Functions

Hello,
In the function Reserve, it should automatically update the seating chart text file with an X, when the user enters a seat they would like to reserve. Also, the reserve function isn't working properly it won't let the user know if the seat is already reserved or not!

I'm having trouble with my statistics function the functions need to find these things from the program:

The program displays the following statistics:
o Number of available seats
o Number reserved seats
o Percentage of seats that are reserved
o Percentage of seats that are available
o List of window seats that are available
o List of aisle seats that are available
o List of center seats that are available
o Number of seats available in the aisle
o Number of seats available in the window
o Number of seats available in the center
• By clicking on this option, your program should automatically save all statistics into a file. Remember to specify what information is being displayed. The file name format should follow the given structure YearMonthDay_Statistics.txt;
o Use as many functions do you want for this option;

This is the seating chart:

A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F
A B C D E F


Thank You,



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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226

#include <iostream> 
#include <string>
#include <fstream>

using namespace std;
const int ROWS = 30;
const int COLS = 6;


void SeatChart(ifstream& eds, string seatChart[][COLS])
{

	for (int i = 0; i < ROWS; i++)
	{
		for (int j = 0; j < COLS; j++)
		{
			if (eds.eof()) //if eof, break out of loop 
				break;
			eds >> seatChart[i][j]; //fills array with data from file
			cout << seatChart[i][j] << " ";
			if (seatChart[i][j] == "F")  //endline everytime the letter d is in the array
				cout << endl;
		}
	}
}


void Reserve(string seatChart[][COLS], char row, char column)
{
	cout << "Enter a the row (1-30) and seat (A-F) [Example: 5B]:";
	cin >> row >> column;

	for (int x = 0; x < ROWS; x++)			// int x = 0
		for (int y = 0; y < COLS; y++)
			if (x == row)
			{
				if (seatChart[x][y][0] == toupper(column))
				{
					seatChart[x][y] = 'X';
					cout << "Seat was successfully reserved!" << endl;
				}
				else
					cout << "Seat was already reseverd pick another seat" << endl;
			}
}

void Cancel(string seat[][COLS])
{
	int     row;
	char    col;

	while(true)
	{
		cout << "Enter row of seat to cancel: ";
		cin >> row;
		if (row < 1 || row > 30)
		{
			cout << "That is not a valid row" << endl;
			continue;
		}
		row--;  // Adjust for 0 based array
		cout << "Enter col (A-F) of seat to cancel: ";
		cin >> col;
		col = toupper(col);
		if (col <  'A' || col > 'F')
		{
			cout << "That is not a valid col" << endl;
			continue;
		}
		col -= 'A';
		if (seat[row][col] != "X")
		{
			cout << "That seat has not been reserved" << endl;
			continue;
		}
		seat[row][col] = " ";   //  Mark seat as empty
		return;
	}
}


void SeatChartFile(ofstream& pds, string seatChart[][COLS])
{
	for (int i = 0; i < ROWS; i++)
	{
		for (int j = 0; j < COLS; j++)  //simple function to put data in array to the file 
		{
			pds << seatChart[i][j];
			pds << " ";
			if (j == 6) //everytime theres a new row, its a new line
				pds << endl;
		}
	}
}


void Stats()
{




	ofstream  pds;
	pds.open("YearMonthDay_Statistics.txt");




	pds << "Number of available seats:" << << endl;
	pds << "Number reserved seats:" << << endl;
	pds << "Percentage of seats that are reserved:" << << endl;
	pds << "Percentage of seats that are available:" << << endl;
	pds << "Window seats that are available:" << << endl;
	pds << "aisle seats that are available:" << << endl;
	pds << "center seats that are available:" << << endl;
	pds << "Number of seats available in the aisle:" << << endl;
	pds << "Number of seats available in the window:" << << endl;
	pds << "Number of seats available in the center" << << endl;






}


void Help()
{
	cout << "Hello, seems like youre having trouble with you program." << endl;
	cout << "Pressing the letter (A) or a will give you a look at all the seats on the plane thats arer reserved and unreserved." << endl;
	cout << "Want to reserve a seat! press (B) and first input the coulumn number 1-30 and a letter A-F for the row seat." << endl;
	cout << "Option (C) will let you cancel a reservation by just inputting the seat you initially reserved." << endl;
	cout << "Option (D) will save the seating chart to a file you input." << endl;
	cout << "Option (E) will list all the statistics to the user." << endl;
	cout << "This option (F) will help you understand the program and how to work the program." << endl;
	cout << "Lastly Option (G) will the quit the program" << endl;

}


void Quit()
{
	cout << "Thank You!" << endl;
	cout << "Enjoy your Flight" << endl;
	system("pause");
	exit(0); //Exit the program
}


int main()
{
	string seatChart[ROWS][COLS];
	char row = 0;
	char col = NULL;
	char choice;

	ifstream eds;
	ofstream pds;
	string outputfile;
	eds.open("planeSeats.txt");

	bool repeat = true;

	while (repeat = true)
	{

		cout << "------------------------ Menu ---------------------------" << endl;
		cout << "A.Display Seat Chart" << endl;
		cout << "B.Reserve Seat" << endl;
		cout << "C.Cancel Reservation" << endl;
		cout << "D.Save Seat Chart to File" << endl;
		cout << "E.Statistics" << endl;
		cout << "F.Help" << endl;
		cout << "G.Quit" << endl;
		cout << "------------------------------------------------------------" << endl;
		cout << "Please Enter Your Choice (A-G):";
		cin >> choice;

		switch (toupper(choice))
		{
		case 'A':
			SeatChart(eds, seatChart);
			system("pause");
			break;

		case 'B':
			Reserve(seatChart, col, row);
			system("pause");
			break;

		case 'C':
			Cancel(seatChart);
			system("pause");
			break;

		case 'D':
			cout << "What is the name of the file you want to save the data to:";
			cin >> outputfile;
			pds.open(outputfile);
			SeatChartFile(pds, seatChart);
			pds.close();
			system("pause");
			break;

		case 'E':
			Stats();
			system("pause");
			break;

		case 'F':
			Help();
			system("pause");
			break;

		case 'G':
			Quit();

			break;

		}
		eds.close();
	}

}
Last edited on
You've ignored much of the advice given in your previous thread.

Ignored advice:
Line 18: Do not loop on eof(). See my comments in previous thread.

Line 22: You're comparing the contents of a seat with "F". You're confusing the column with the value of a seat which is " " or "X".

Line 29: You're inconsistent with your use of column. Here it's a char. Elsewhere it's an int.

Line 34-35: A double for loop is not needed here.

Line 189: Why are you passing row and column? They're meaningless here.

New advice:
Line 20: The >> operator is going to ignore spaces which is your indication that a seat is not reserved.

Line 104: You open the input file once (162). If A is selected more than once, you will be positioned at the end of the file and won't read anything the second time. You need to position the file back to the beginning or open and close the file each time.

the reserve function isn't working properly it won't let the user know if the seat is already reserved or not!

Line 32: You're inputting a char for row ('1'). That won't match your loop index. I already pointed out your inconsistent use of types here.

I'm having trouble with my statistics function the functions need to find these things from the program:

I already explained how to determine these statistics in your previous thread.

Last edited on
Topic archived. No new replies allowed.