Aiport Ticketing

Hi, I have a problem with the Personal Information Part. It always skips the FIRST NAME and goes directly to LAST NAME. And also, if I enter long contact numbers, It'll appear differently in the receipt. And can you suggest ways to improve the codes. Thanks. I'm new to classes, by the way.

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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
#include<iostream>
#include<iomanip>
#include<windows.h>
#include<string>

using namespace std;

class Flight
{
public:
	void getInfo()
{
		cout<<setw(40)<<"\n\nPASSENGER INFORMATION";
		cout<<"\n\n\nEnter FIRST NAME: ";
		cin.getline(firstname,60);
		cout<<"\nEnter LAST NAME: ";

		cin.getline(lastname,60);
		cout<<endl;

		cout<<"Enter CONTACT NUMBER: ";
		cin>>contact;
		cout<<endl<<endl;
		system("CLS");

};

	int num;
	char firstname[60];
	char lastname[60];
	int contact;

};


class booking: public Flight
{
public:
	void chooseAirlineInternational()
	{
		cout<<"\nIn which AIRLINE you want to travel"<<endl<<endl;
		cout<<"(1) - Philippine Airlines"<<endl;
		cout<<"(2) - Cebu Pacific"<<endl;
		
		cout<<"\nEnter your choice: ";
		cin>>airline;

		system ("cls");

	  switch(airline)
	  {
	  case 1:

		cout<<"\n\n"<<setw(55)<<"WELCOME TO PHILIPPINE AIRLINES"<<endl;
		chooseInternationalDestination();
	   break;
	  case 2:
	   if(airline==2)
		cout<<"\n\n"<<setw(55)<<"WELCOME TO CEBU PACIFIC AIR"<<endl;
	   chooseInternationalDestination();
	   break;
	  default:
		  cout<<"\n\nInvalid Choice! Try Again.";
	  }
	};
	
	void chooseAirlineLocal()
	{
		cout<<"\nIn which AIRLINE you want to travel"<<endl<<endl;
		cout<<"(1) - Philippine Airlines"<<endl;
		cout<<"(2) - Cebu Pacific"<<endl;
		cout<<"\nEnter your choice: ";
		cin>>airline;

		system ("cls");

	  switch(airline)
	  {
	  case 1:

		cout<<"\n\n"<<setw(55)<<"WELCOME TO PHILIPPINE AIRLINES"<<endl;
		chooseLocalDestination();
	   break;
	  case 2:
	   if(airline==2)
		cout<<"\n\n"<<setw(55)<<"WELCOME TO CEBU PACIFIC AIR"<<endl;
	   	chooseLocalDestination();
	  
	   break;
	  default:
		  cout<<"\n\nInvalid Choice! Try Again.";
	  }
	};

	void chooseLocalDestination()
	{
		cout<<"Here are the available LOCAL flights:"<<endl<<endl;
		cout<<"---------------"<<endl;
		cout<<"(1) - CATICLAN"<<endl;
		cout<<"(2) - CEBU"<<endl;
		cout<<"(3) - CLARK"<<endl;
		cout<<"(4) - DAVAO"<<endl;
		cout<<"(5) - LAOAG"<<endl;
		cout<<"(6) - LEGAZPI"<<endl;
		cout<<"(7) - PUERTO PRINCESA"<<endl;
		cout<<"\n(0) - Go Back"<<endl;
		cout<<"---------------"<<endl;
		cout<<"\nEnter your choice: ";
		cin>>destinationChoice;
		cout<<endl<<endl;

		switch(destinationChoice)
		{
		case 1:
			destination="CATICLAN";
			price=3000;
			break;
		case 2:
			destination="CEBU";
			price=2500;
			break;
		case 3:
			destination="CLARK";
			price=1500;
			break;
		case 4:
			destination="DAVAO";
			price=3000;
			break;
		case 5:
			destination="LAOAG";
			price=2500;
			break;
		case 6:
			destination="LEGAZPI";
			price=2000;
			break;
		case 7:
			destination="PUERTO PRINCESA";
			price=3500;
			break;
		case 0:
			system("cls");
			chooseAirlineLocal();
			break;
		default: 
			cout<<"\nInvalid Choice! Sorry, the program will exit now.\n\n";
			system("cls");
			exit(0);

		}

		chooseTrip();
	};

	void chooseInternationalDestination()
	{
		booking b;

		cout<<"Here are the available INTERNATIONAL flights:"<<endl<<endl;
		cout<<"---------------"<<endl;
		cout<<"(1) - BANGKOK"<<endl;
		cout<<"(2) - BEIJING"<<endl;
		cout<<"(3) - DUBAI"<<endl;
		cout<<"(4) - HONGKONG"<<endl;
		cout<<"(5) - SEOUL"<<endl;
		cout<<"(6) - MACAU"<<endl;
		cout<<"(7) - OSAKA"<<endl;

		cout<<"\n(0) - Go Back"<<endl;
		cout<<"---------------"<<endl;
		cout<<"\nEnter your choice: ";
		cin>>destinationChoice;

		switch(destinationChoice)
		{
		case 1:
			destination="BANGKOK";
			price=6500;
			break;
		case 2:
			destination="BEIJING";
			price=10000;
			break;
		case 3:
			destination="DUBAI";
			price=8500;
			break;
		case 4:
			destination="HONGKONG";
			price=4500;
			break;
		case 5:
			destination="SEOUL";
			price=12000;
			break;
		case 6:
			destination="MACAU";
			price=3800;
			break;
		case 7:
			destination="OSAKA";
			price=9500;
			break;
		case 0:
			system("cls");
			chooseAirlineInternational();
			break;
		default: 
			cout<<"\nInvalid Choice! Sorry, the program will exit now.\n\n";
			system("cls");
			exit(0);


		}
			
		chooseTrip();
	
		
	};

	void chooseTrip()
	{
		cout<<"\nOne-way or Round Trip?"<<endl;
		cout<<"----------------------"<<endl;
		cout<<"(1) - One-way Trip"<<endl;
		cout<<"(2) - Round Trip"<<endl;
		cout<<"----------------------"<<endl;
		cout<<"\nEnter your choice: ";
		cin>>tripChoice;

		switch(tripChoice)
		{
		case 1:
			trip="ONE WAY";
			break;
		case 2:
			trip="ROUND TRIP";
			price=price*2;
			break;
		case 0:

			system("cls");
			break;
		default: 
			cout<<"\nInvalid Choice! Sorry, the program will exit now.\n\n";
			system("cls");
			exit(0);

		}
		chooseDate();
	};


	void chooseDate()
	{
		cout<<"\nCHOOSE THE DATE OF YOUR DEPARTURE"<<endl;
		cout<<"----------------------"<<endl;
		cout<<"(1) - September 23"<<endl;
		cout<<"(2) - September 24"<<endl;
		cout<<"(3) - September 25"<<endl;

		cout<<"\n(0) - Go Back"<<endl;
		cout<<"----------------------"<<endl;
		cout<<"\nEnter your choice: ";
		cin>>dateChoice;

		switch(dateChoice)
		{
		case 1:
			date="23/Sept/2013";
			system("cls");
			cout<<"\nFlight available!\n";
			break;
		case 2:
			date="24/Sept/2013";
			system("cls");
			cout<<"\nSorry, Flight not available! Please choose another date.\n";
			chooseDate();
			break;
		case 3:
			date="25/Sept/2013";
			system("cls");
			cout<<"\nFlight available!\n";
			break;
		default: 
			cout<<"\nInvalid Choice! Sorry, the program will exit now.\n\n";
			system("cls");
			exit(0);

			
		}

		chooseTime();
	};

		void chooseTime()
		{
			cout<<"\nAVAILABLE TIMES FOR DEPARTURE"<<endl;
			cout<<"----------------------"<<endl;
			cout<<"(1) - 5:00 AM"<<endl;
			cout<<"(2) - 8:45 AM"<<endl;
			cout<<"(3) - 3:00 PM"<<endl;
			cout<<"(4) - 9:45 PM"<<endl;

			cout<<"\n(0) - Go Back"<<endl;
			cout<<"----------------------"<<endl;
			cout<<"\nEnter your choice: ";
			cin>>timeChoice;

			switch(timeChoice)
			{
			case 1:
				time="5:00 AM";
				break;
			case 2:
				time="8:45 AM";
				break;
			case 3:
				time="3:00 PM";
				break;
			case 4:
				time="9:45 PM";
				break;
			case 0:
				system("cls");
				chooseDate();
				break;
			default: 
				cout<<"\nInvalid Choice! Sorry, the program will exit now.\n\n";
				system("cls");
			exit(0);

			}
			chooseClass();
		};
		
		void chooseClass()
		{

			cout<<"\nIn which class you want to travel?"<<endl;
			cout<<"\n---------------"<<endl;
			cout<<"(1) - BUSINESS CLASS"<<endl;
			cout<<"(2) - ECONOMY CLASS"<<endl;
			cout<<"\n(0) - Go Back"<<endl;
			cout<<"---------------"<<endl;
			cout<<"\nEnter your choice: ";
			cin>>classChoice;

			switch(classChoice)
			{
			case 1:
				classType="BUSINESS CLASS";
				price=price*3;
				break;
			case 2:
				classType="ECONOMY CLASS";
				break;
			case 0:
				system("cls");
				chooseTime();
				break;
			default: 
				cout<<"\nInvalid Choice! Sorry, the program will exit now.\n\n";
				system("cls");
			exit(0);

			}

			enterSeats();
		};

	void enterSeats()
	{
		cout<<"\nEnter number of seats to be booked: "<<endl;
		cin>>seats;
		price=price*seats;

		getInfo();

	};

	/*CONTINUATION OF CODES IS IN THE NEXT COMMENT, THANKS*/
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

//CONTINUATION:

void show()
	{
		int t = 1;
int r = 1;

cout<<setw(50)<<"NAIA 123 TICKETING"<<endl;
cout<<setw(45)<<"AIRLINE TICKET DETAILS"<<endl<<endl;
cout<<"|Ticket No: "<<t<<"\t\t\tReference No: "<<r
    <<endl<<"|_________________________________________________________________________"
    <<endl<<" PASSENGER INFORMATION"
    <<endl<<" Name: "<<lastname<<"/"<<firstname
    <<endl<<" Contact Number: "<<contact

<<endl<<"|_________________________________________________________________________"
    <<endl<<" FLIGHT INFORMATION"
    <<endl<<" Origin: MANILA"
    <<endl<<" Destination: "<<destination
    <<endl<<" BOEING 747"
    <<endl<<" Date: "<<date
    <<endl<<" Time: "<<time

    <<endl<<endl<<" "<<trip
    <<endl<<" "<<classType
    <<endl<<" Number of seat/s: "<<seats

<<endl<<"_________________________________________________________________________"
    <<endl<<" PRICE: "<<price;
 

cout<<"\n\nPLEASE DOUBLE CHECK";
cout<<"\n(1) - Confirm";
cout<<"\n(2) - Go Back";
cout<<"\n\nEnter choice: ";
	};

protected:
	int airline;
	int destinationChoice;
	string destination;
	
	int tripChoice;
	string trip;

	int dateChoice;
	string date;

	int timeChoice;
	string time;

	int classChoice;
	string classType;

	double price;
	
	int seats;
	
};



int main()
{
	booking b;
	int menu_choice;

	SetConsoleTitle("NAIA 123 TICKETING");
	cout<<"\n\n\n\n\n\n\n\n\n\n\t\t           WELCOME TO NAIA 123 TICKETING";
	Sleep(1500);
	system ("cls");

	cout<<"\n\n\n\n\n\n";
   cout<<setw(60)<<"*************************************"<<endl;
   cout<<setw(60)<<"*        NAIA 123 TICKETING         *"<<endl;
   cout<<setw(60)<<"*             MAIN MENU             *"<<endl;
   cout<<setw(60)<<"*        ENTER YOUR CHOICE          *"<<endl;
   cout<<setw(60)<<"*   PRESS 1 FOR LOCAL BOOKING       *"<<endl;
   cout<<setw(60)<<"* PRESS 2 FOR INTERNATIONAL BOOKING *"<<endl;
   cout<<setw(60)<<"*   PRESS 3 FOR SEARCH OF FLIGHTS   *"<<endl;
   cout<<setw(60)<<"*************************************"<<endl<<endl<<endl;
   cout<<setw(60)<<"    ENTER YOUR CHOICE: ";
   cin>>menu_choice;
   system("cls");

   switch(menu_choice)
   {
   case 1:
	   b.chooseAirlineLocal();
	   break;
  
   case 2:
	   b.chooseAirlineInternational();
	   break;
   
}


b.show();
system("pause");


   return 0;

}
For all user input before asking First Name you use cin>> then when you ask for first name you use cin.getline.

After using cin>> a '\n' is left in the stream. Now this is not a problem if you use another cin>> because cin>> will ignore it and wait for input.

But cin.getline will not ignore it. It will return all the characters before the '\n' which in this case will be none and then discard the '\n' so the next cin.getline will wait for input because the stream is empty.
You need to remove the '\n' from the stream to wait for input for first name so just use cin.getline twice to do it.

1
2
3
cout<<"\n\n\nEnter FIRST NAME: ";
cin.getline(firstname,60);
cin.getline(firstname,60);


You declare Flight::contact as an int.
So you cannot have a contact number bigger/longer than the max value for an int.
The max value for a 32 bit int is 2147483647

Last edited on
Topic archived. No new replies allowed.