how to develop an arline seating program?

Mar 9, 2010 at 11:54am
hello,i'm yuri and i'm new here..
i have to make program about airline seating..
but up till now..we still have some problems with the program..
it's not working as we expect it to be..
so,i'm asking anybody that can help me..please..
i'm quite desperate now..we've been work on this program for 3 weeks...*_*

this is the question:

Airline seating:write a program that assigns seats on airplane.assume that airplane has 20 seats in first class(5 rows of 4 seats each,separated by an aisle) and 180 seats in economy class(30 rows of 6 seats each,separated by an aisle). Your program should take three commands, add passengers, show seating(use ‘*’ to indicates that the seat is available; ‘X’ to indicates that the seat is occupied), and quit. When passengers are added, ask for the class(first or economy), the number of passengers traveling together(1 or 2 in first class;1 to 3 in economy), and the seating preference(aisle or window in first class; aisle, center, or window in economy). Then try to match and assign the seats. If no match exists,print a message.

please help me anyone...
Mar 9, 2010 at 1:11pm
what do you have so far?
Mar 11, 2010 at 3:35pm
this is what we've done so far...

#include<iostream>
#include<string>
using namespace std;

const int numOfRowF=5;
const int numOfColumnF=4;
const int numOfRowE=30;
const int numOfColumnE=6;
const char SENTINEL='N';
char quit='Y';

char First[numOfRowF][numOfColumnF];
char Eco[numOfRowE][numOfColumnE];
int i,j,s;
char typeClass;
int passenger;
string seat;

void main()
{
cout<<"######## WELCOME TO AIRLINE SEATING BOOKING TICKET ########"<<endl;
cout<<endl;
cout<<"This company have 2 types of class seating: "<<endl;
cout<<"A) FIRST CLASS"<<endl;
cout<<"B) ECONOMY CLASS"<<endl;
cout<<endl;
cout<<"Below are condition before choosing a seat for those class: "<<endl;
cout<<"A) FIRST CLASS: maximum passenger = 2. "<<endl;
cout<<"If more than 2 please re-enter this program for the passenger that over the maximum passenger"<<endl;
cout<<endl;
cout<<"B) ECONOMY CLASS: maximum passenger = 3. "<<endl;
cout<<"If more than 3 please re-enter this program for the passenger that over the maximum passenger"<<endl;
cout<<endl;
cout<<"This sign'*' is for available seat and this sign 'X' is for not available seat"<<endl;
cout<<" This is the seat arrangement: ";
cout<<endl<<endl;



for(i=0;i<numOfRowF;i++)
{
for(j=0;j<numOfColumnF;j++)
First[i][j]='*';
}

for(i=0;i<numOfRowE;i++)
{
for(j=0;j<numOfColumnE;j++)
Eco[i][j]='*';
}

cout<<"First Class";
cout<<endl<<endl<<endl;

for(i=0;i<numOfRowF;i++)
{
for(j=0;j<numOfColumnF;j++)
cout<<First[i][j]<<" ";
cout<<endl<<endl;
}


cout<<"Economy Class";
cout<<endl<<endl<<endl;

for(i=0;i<numOfRowE;i++)
{
for(j=0;j<numOfColumnE;j++)
cout<<Eco[i][j]<<" ";
cout<<endl<<endl;

}

cout<<"Press 'Y' to continue this program, 'N' to quit the program: ";

cin>>quit;

while (quit=!SENTINEL)
{
cout<<"Enter your class choice (F=FIRST CLASS, E=ECONOMY CLASS): ";
cin>>typeClass;

if(typeClass=='F')
{
if(First[i][j]=='*')
{
cout<<"Enter number of passenger: ";
cin>>passenger;
}

for(s=0;s<passenger++;s++)
{
cout<<"Enter of your seating position: "<<endl;
cout<<"(WR = right window, WL = left window,"<<endl;
cout<<"AR = right aisle, AL = left aisle)"<<endl;
cin>>seat;
}
for(i=0;i<numOfRowF;i++)
{
if(seat=="WR")
{
j=0;
First[i][j]='X';
}

if(seat=="WL")
{
j=3;
First[i][j]='X';
}
if(seat=="AR")
{
j=1;
First[i][j]='X';
}
if(seat=="AL")
{
j=2;
First[i][j]='X';
}
}
}
else if(typeClass=='E')
{
if(Eco[i][j]=='*')
{
cout<<"Enter number of passenger: ";
cin>>passenger;
}

for(s=0;s<passenger++;s++)
{
cout<<"Enter of your seating position: "<<endl;
cout<<"(WR = right window, WL = left window,"<<endl;
cout<<"CR = right centre, CL = Left Centre"<<endl;
cout<<"AR = right aisle, AL = left aisle)"<<endl;
cin>>seat;
}
for(i=0;i<numOfRowF;i++)
{
if(seat=="WR")
{
j=0;
Eco[i][j]='X';
}
if(seat=="WL")
{
j=5;
Eco[i][j]='X';
}
if(seat=="AR")
{
j=2;
Eco[i][j]='X';
}
if(seat=="AL")
{
j=3;
Eco[i][j]='X';
}
if(seat=="CR")
{
j=1;
Eco[i][j]='X';
}
if(seat=="CL")
{
j=4;
Eco[i][j]='X';
}
else cout<<"INVALID CODE"<<endl;
}
}



cout<<"First Class";
cout<<endl<<endl<<endl;

for(i=0;i<numOfRowF;i++)
{
for(j=0;j<numOfColumnF;j++)
cout<<First[i][j]<<" ";
cout<<endl<<endl;
}


cout<<"Economy Class";
cout<<endl<<endl<<endl;

for(i=0;i<numOfRowE;i++)
{
for(j=0;j<numOfColumnE;j++)
cout<<Eco[i][j]<<" ";
cout<<endl<<endl;
}

cout<<"Press 'Y' to continue this program, 'N' to quit the program: ";
cin>>quit;
}

}
Mar 11, 2010 at 3:40pm
code tags...
Mar 12, 2010 at 2:54am
what incubbus???
Mar 12, 2010 at 2:58am
Look it up. It's a forum thing on this website.
Mar 12, 2010 at 10:00am
I recommend you to use the following code as a basis. I left the most difficult part (implementing addPassengers) to you. But like this the code becomes much more readable than yours. (in fact i just reorganized yours).

Feel free to adjust the code to your needs.

Do you have more specific questions?

Yours, Maikel

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
#include <iostream> // cout, cin
#include <cstring>  // memset

using namespace std;

// function declaration for menu options
void addPassengers();
void showSeating();
void showMenu();

// some global variables we need in different functions
const int numOfRowF=5;
const int numOfColumnF=4;
const int numOfRowE=30;
const int numOfColumnE=6;

const char Available = '*';
const char Occupied  = 'X';

char First[numOfRowF][numOfColumnF];
char Economy[numOfRowE][numOfColumnE];


int main()
{
	// symbolic constants (menu options)
	const char Quit = 'q';
	const char Add  = 'a';
	const char Show = 's';

	// input variable
	char cmd;

	// set default values of global seating vars
	memset(First, Available, sizeof First);
	memset(Economy, Available, sizeof Economy);

	// program loop and show menu
	showMenu();
	while ((cmd = cin.get()) != Quit) {
		switch (cmd) {
		case Show:
			showSeating();
			showMenu();
			break;
		case Add:
			addPassengers();
			showMenu();
			break;
		default:
			cout << "Please type only 'a', 's' or 'q': ";
			break;
		}
		// now get rid of unpleasent input
		while (cin.get() != '\n');
	}
}

void showMenu()
{
	cout << "Airline Booking Application\n\n"
		 << "a) Add Passengers                        q) Quit\n"
		 << "s) Show Seating\n\n"
		 << "Type 'a', 's' or 'q': ";
}

// Print Seating on screen.
void showSeating()
{
	cout << "First Class Seatings\n\n";
	for (int i = 0; i < numOfRowF; i++) {
		for (int j = 0; j < numOfColumnF; j++)
			cout << First[i][j] << ' ';
		cout << endl;
	}

	cout << "\nEconomy Class Seatings\n\n";
	for (int i = 0; i < numOfRowE; i++) {
		for (int j = 0; j < numOfColumnE; j++)
			cout << Economy[i][j] << ' ';
		cout << endl;
	}
	cout << endl;
}

void addPassengers()
{
	// Now do some more code here!
	cout << endl;
}
Last edited on Mar 12, 2010 at 10:02am
Mar 15, 2010 at 4:39am
thanx for helping me...
but that's my big problem...the addPassenger function...
i don't know how to do it...*_*
Mar 15, 2010 at 4:48am
just wanna try using the code tag...

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
#include<iostream>
#include<string>
using namespace std;

const int numOfRowF=5;
const int numOfColumnF=4;
const int numOfRowE=30;
const int numOfColumnE=6;
const char SENTINEL='N';
char quit='Y';

char First[numOfRowF][numOfColumnF];
char Eco[numOfRowE][numOfColumnE];
int i,j,s;
char typeClass;
int passenger;
string seat;

void main()
{
cout<<"######## WELCOME TO AIRLINE SEATING BOOKING TICKET ########"<<endl;
cout<<endl;
cout<<"This company have 2 types of class seating: "<<endl;
cout<<"A) FIRST CLASS"<<endl;
cout<<"B) ECONOMY CLASS"<<endl;
cout<<endl;
cout<<"Below are condition before choosing a seat for those class: "<<endl;
cout<<"A) FIRST CLASS: maximum passenger = 2. "<<endl;
cout<<"If more than 2 please re-enter this program for the passenger that over the maximum passenger"<<endl;
cout<<endl;
cout<<"B) ECONOMY CLASS: maximum passenger = 3. "<<endl;
cout<<"If more than 3 please re-enter this program for the passenger that over the maximum passenger"<<endl;
cout<<endl;
cout<<"This sign'*' is for available seat and this sign 'X' is for not available seat"<<endl;
cout<<" This is the seat arrangement: ";
cout<<endl<<endl;



for(i=0;i<numOfRowF;i++)
{
for(j=0;j<numOfColumnF;j++)
First[i][j]='*';
}

for(i=0;i<numOfRowE;i++)
{
for(j=0;j<numOfColumnE;j++)
Eco[i][j]='*';
}

cout<<"First Class";
cout<<endl<<endl<<endl;

for(i=0;i<numOfRowF;i++)
{
for(j=0;j<numOfColumnF;j++)
cout<<First[i][j]<<" ";
cout<<endl<<endl;
}


cout<<"Economy Class";
cout<<endl<<endl<<endl;

for(i=0;i<numOfRowE;i++)
{
for(j=0;j<numOfColumnE;j++)
cout<<Eco[i][j]<<" ";
cout<<endl<<endl;

}

cout<<"Press 'Y' to continue this program, 'N' to quit the program: ";

cin>>quit;

while (quit=!SENTINEL)
{
cout<<"Enter your class choice (F=FIRST CLASS, E=ECONOMY CLASS): ";
cin>>typeClass;

if(typeClass=='F')
{
if(First[i][j]=='*')
{
cout<<"Enter number of passenger: ";
cin>>passenger;
}

for(s=0;s<passenger++;s++)
{
cout<<"Enter of your seating position: "<<endl;
cout<<"(WR = right window, WL = left window,"<<endl;
cout<<"AR = right aisle, AL = left aisle)"<<endl;
cin>>seat;
}
for(i=0;i<numOfRowF;i++)
{
if(seat=="WR")
{
j=0;
First[i][j]='X';
}

if(seat=="WL")
{
j=3;
First[i][j]='X';
}
if(seat=="AR")
{
j=1;
First[i][j]='X';
}
if(seat=="AL")
{
j=2;
First[i][j]='X';
}
}
}
else if(typeClass=='E')
{
if(Eco[i][j]=='*')
{
cout<<"Enter number of passenger: ";
cin>>passenger;
} 

for(s=0;s<passenger++;s++)
{
cout<<"Enter of your seating position: "<<endl;
cout<<"(WR = right window, WL = left window,"<<endl;
cout<<"CR = right centre, CL = Left Centre"<<endl;
cout<<"AR = right aisle, AL = left aisle)"<<endl;
cin>>seat;
}
for(i=0;i<numOfRowF;i++)
{
if(seat=="WR")
{
j=0;
Eco[i][j]='X';
}
if(seat=="WL") 
{ 
j=5;
Eco[i][j]='X';
}
if(seat=="AR")
{
j=2;
Eco[i][j]='X';
}
if(seat=="AL")
{
j=3;
Eco[i][j]='X';
} 
if(seat=="CR")
{
j=1;
Eco[i][j]='X';
}
if(seat=="CL")
{
j=4;
Eco[i][j]='X';
}
else cout<<"INVALID CODE"<<endl;
}
}



cout<<"First Class";
cout<<endl<<endl<<endl;

for(i=0;i<numOfRowF;i++)
{ 
for(j=0;j<numOfColumnF;j++)
cout<<First[i][j]<<" ";
cout<<endl<<endl;
}


cout<<"Economy Class";
cout<<endl<<endl<<endl;

for(i=0;i<numOfRowE;i++)
{
for(j=0;j<numOfColumnE;j++)
cout<<Eco[i][j]<<" ";
cout<<endl<<endl;
}

cout<<"Press 'Y' to continue this program, 'N' to quit the program: ";
cin>>quit;
}

}
Mar 22, 2010 at 8:14am
please...anyone can help me???
i'm really desperate..
Mar 22, 2010 at 10:03am
hi , this is addpassenger() function for the first class similarly you can add the content for the economy class .

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
void addPassengers()
{
	cout<<"Enter your class choice (F=FIRST CLASS, E=ECONOMY CLASS): ";
	cin>>typeClass;

	if(typeClass=='F')
	{
			cout<<"Enter number of passenger: ";
			cin>>passenger;
			for(i=0;i<numOfRowF;i++)
			{
				for(j=0;j<numOfColumnF;j++)
				{
					if(First[i][j]=='X')
					{
						continue;				
					}
					else if( (i == numOfRowF )  && ( j == numOfColumnF) )
						{
							cout<<"Seats are full ";
							break;
						}
						else
						{
							First[i][j]='X';
						}

				}
			}

		
		}
	
}


hope this helps
Mar 23, 2010 at 4:25am
hi bluecoder...
thank you very much for your help...
really appreciate it...^_^
Mar 30, 2010 at 3:39am
this is what we've done so far..but it's still didn't work out...
please help us...we're really deperate...need to submit this A.S.A.P...T_T

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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include<iostream>
#include<string>
using namespace std;

const int numOfRowF=5;
const int numOfColumnF=4;
const int numOfRowE=30;
const int numOfColumnE=6;
const char SENTINEL='n';
char quit;


char First[numOfRowF][numOfColumnF];
char Eco[numOfRowE][numOfColumnE];
int i,j,s;
char typeClass;
int passenger;
string seat;

void main()
{
	cout<<"######## WELCOME TO AIRLINE SEATING BOOKING TICKET ########"<<endl;
	cout<<endl;
	cout<<"This company have 2 types of class seating: "<<endl;
	cout<<"A) FIRST CLASS"<<endl;
	cout<<"B) ECONOMY CLASS"<<endl;
	cout<<endl;
	cout<<"Below are condition before choosing a seat for those class: "<<endl;
	cout<<"A) FIRST CLASS: maximum passenger = 2. "<<endl;
	cout<<"If more than 2 please re-enter this program for the passenger that over the maximum passenger"<<endl;
	cout<<endl;
	cout<<"B) ECONOMY CLASS: maximum passenger = 3. "<<endl;
	cout<<"If more than 3 please re-enter this program for the passenger that over the maximum passenger"<<endl;
	cout<<endl;
	cout<<"This sign'*' is for available seat and this sign 'X' is for not available seat"<<endl;
	cout<<" This is the seat arrangement: ";
	cout<<endl<<endl;



	for(i=0;i<numOfRowF;i++)
	{
		for(j=0;j<numOfColumnF;j++)
			First[i][j]='*';
	}
	
	for(i=0;i<numOfRowE;i++)
	{
		for(j=0;j<numOfColumnE;j++)
			Eco[i][j]='*';
	}

	cout<<"First Class";
	cout<<endl<<endl<<endl;

	for(i=0;i<numOfRowF;i++)
	{


		for(j=0;j<numOfColumnF;j++)
			cout<<First[i][j]<<" ";
		cout<<endl<<endl;
	}
	

	cout<<"Economy Class";
	cout<<endl<<endl<<endl;

	for(i=0;i<numOfRowE;i++)
	{
		for(j=0;j<numOfColumnE;j++)
			cout<<Eco[i][j]<<" ";
		cout<<endl<<endl;
		
	}
		cout<<"Press 'y' to continue this program, 'n' to quit the program: ";
		    cin>>quit;

	while (quit!=SENTINEL)
	{
		cout<<"Enter your class choice (f=FIRST CLASS, e=ECONOMY CLASS): ";
		cin>>typeClass;
		
		if(typeClass=='F')
		{
			cout<<"Enter number of passenger: ";
			cin>>passenger;
			for(i=0;i<numOfRowF;i++)
			{
				for(j=0;j<numOfColumnF;j++)
					for(s=0;s<passenger;s++)
					{
	        			cout<<"Enter of your seating position: "<<endl;
						cout<<"(wr = right window,  wl = left window,"<<endl;
						cout<<" ar = right aisle,   al = left aisle)"<<endl;
	        			cin>>seat;
				
				
			    		if(seat=="wr")
						{
							j=0;
							if(First[i][j]=='X')
							{
								continue;				
							}
							else if( (i == numOfRowF )  && ( j == numOfColumnF) )
							{
								cout<<"Seats are full ";
								break;
							}
							else
							{
								First[i][j]='X';
							}
					

						}
			
						if(seat=="wl")
						{
			        		j=3;
							if(First[i][j]=='X')
							{
								continue;				
							}
							else if( (i == numOfRowF )  && ( j == numOfColumnF) )
							{	
								cout<<"Seats are full ";
								break;
							}
							else
							{
								First[i][j]='X';
							}
						}
			        
						if(seat=="ar")

						{
							j=1;
							if(First[i][j]=='X')
							{
								continue;				
							}
							else if( (i == numOfRowF )  && ( j == numOfColumnF) )
							{
								cout<<"Seats are full ";
								break;
							}
							else
							{
								First[i][j]='X';
							}
						}
						if(seat=="al")
						{
							j=2;
							if(First[i][j]=='X')
							{
								continue;				
							}
							else if( (i == numOfRowF )  && ( j == numOfColumnF) )
							{
								cout<<"Seats are full ";
								break;
							}
							else
							{
								First[i][j]='X';
							}
						}
					}
			}
		}
		
	
						
			
			
		   
		   else if(typeClass=='e')
		   {
			   cout<<"Enter number of passenger: ";
	           cin>>passenger;
			 

	         for(s=0;s<passenger;s++)
			 {
			 
				 cout<<"Enter of your seating position: "<<endl;
                 cout<<"(wr = right window,  wl = left window,"<<endl;
                 cout<<" cr = right centre,  cl = left centre"<<endl;
                 cout<<" ar = right aisle,   al = left aisle)"<<endl;
	             cin>>seat;
				 
				 for(i=0;i<numOfRowF;i++)
				 {
			    	 if(seat=="wr")
					 {
				    	 j=0;
			             Eco[i][j]='X';
					 }
			        if(seat=="wl")	
					{ 
				         j=5;
			             Eco[i][j]='X';
					}
			        if(seat=="ar")
					{
				         j=2;
			             Eco[i][j]='X';
					}
	                if(seat=="al")
					{
			            j=3;
			   	        Eco[i][j]='X';
					}   
			        if(seat=="cr")
					{
				        j=1;
				        Eco[i][j]='X';
					}
			        if(seat=="cl")
					{
				        j=4;
				        Eco[i][j]='X';
					}
				
				 }
			 }
		 }
		 
		 cout<<"First Class";
         cout<<endl<<endl<<endl;

         for(i=0;i<numOfRowF;i++)
		 {	
			for(j=0;j<numOfColumnF;j++)
				cout<<First[i][j]<<" ";
	            cout<<endl<<endl;
		 }
	 

            cout<<"Economy Class";
	        cout<<endl<<endl<<endl;
 
	        for(i=0;i<numOfRowE;i++)
			{
				for(j=0;j<numOfColumnE;j++)
					cout<<Eco[i][j]<<" ";
	                cout<<endl<<endl;
			}

			cout<<"Press 'y' to continue this program, 'n' to quit the program";
		    cin>>quit;
	}
}
Apr 9, 2010 at 2:02am
can anyone tell me how to make the output be like this:

first class
** **
** **
** **

economy class
*** ***
*** ***
*** ***
Topic archived. No new replies allowed.