-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAIRLINE MANAGEMENT.CPP
414 lines (396 loc) · 12 KB
/
AIRLINE MANAGEMENT.CPP
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
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
//**************** AIR TICKET BOOKING SYSTEM ******************
//********************************************************************
// INCLUDING HEADER FILES
//********************************************************************
#include<fstream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<ctype.h>
#include<iomanip.h>
#include<graphics.h>
#include<dos.h>
#include<process.h>
//********************************************************************
// CLASS DECLARATION FOR BOOKING FLIGHT
//********************************************************************
class ticket; // forward declaration of class
class booking
{
private :
int booking_no;
char name[30];
int adults,kids,old;
public :
booking()
{
booking_no=0;
}
int ret_book()
{
return(booking_no);
}
void get_booking(int book)
{
booking_no=book;
}
int auto_booking();
void input();
friend void cal_fare(booking &,ticket &);
void output();
};
//********************************************************************
// FUNCTION TO INPUT BOOKING DETAILS
//********************************************************************
void booking::input() // All Details Entered by the User
{
cout<<"\t Name : " ;
cin>>name;
cout<<"\t No Of Adults : ";
cin>>adults;
cout<<"\t No Of Kids : ";
cin>>kids ;
cout<<"\t No Of Senior Citizen : ";
cin>>old;
}
//********************************************************************
// FUNCTION TO OUTPUT BOOKING DETAILS
//********************************************************************
void booking::output() // Displaying the details
{
cout<<setw(5)<<booking_no<<setw(15)<<name<<setw(8)<<adults;
cout<<setw(14)<<kids<<setw(12)<<old<<endl;
}
//********************************************************************
// FUNCTION USED TO AUTOGENERATE BOOKING NUMBER
//********************************************************************
int booking::auto_booking() // To assign booking number
{
booking b ;
int book=0;
ifstream if1("booking.txt",ios::in);
if1.seekg(0,ios::beg) ;
while(if1.read((char *)this,sizeof(b) ))
{
book=this->ret_book();
}
if1.close();
return(book);
}
//********************************************************************
// CLASS TICKECT USED TO INPUT/OUTPUT TICKET DETAILS
//********************************************************************
class ticket
{
private:
int booking_no;
char boarding[20],destination[20],date2[10];
char time[7],clss[2];
int flight_no;
float fare,fare1;
public :
void getvalue(int);
void putvalue();
void cal_fare1(int,char[]);
friend void cal_fare(booking &,ticket &);
int ret_booking()
{
return(booking_no);
}
};
//********************************************************************
// FUNCTION TO DISPLAY FLIGHT DETAILS
//********************************************************************
void flight_details()
{
cout<<" Flights Economy Business Timings \n";
cout<<" ------- ------- -------- ------- \n";
cout<<" hrs:min \n";
cout<<" 1. Jet Airways Rs 22000 Rs 34000 03:00 \n";
cout<<" 13:30 \n";
cout<<" 23:30 \n\n";
cout<<" 2. Indigo Rs 12899 Rs 21000 06:00 \n";
cout<<" 21:45 \n";
cout<<" 14:35 \n\n";
cout<<" 3. Spice Jet Rs 19499 Rs 20999 03:00 \n";
cout<<" 09:30 \n";
cout<<" 22:50 \n\n";
cout<<" 4. Air India Rs 23000 Rs 34000 08:45 \n";
cout<<" 12:45 \n";
cout<<" 15:20 \n\n";
cout<<" 5. Deccan Rs 22000 Rs 34578 00:10 \n";
cout<<" 14:15 \n";
cout<<" 17:10 \n\n";
}
//********************************************************************
// FUNCTION TO CALCULATE FARE ACCORDING TO CLASS
//********************************************************************
void ticket::cal_fare1(int flight_no,char clss[])
{
switch(flight_no)
{
case 1 :
if ( strcmp(clss,"E")== 0)
fare1 = 22000 ;
else if( strcmp(clss,"B")== 0)
fare1 = 34000 ;
else
fare1 = 0 ;
break ;
case 2 :
if (strcmp(clss,"E")== 0 )
fare1 = 12899 ;
else if ( strcmp(clss,"B") == 0)
fare1 = 21000 ;
else
fare1 = 0 ;
break ;
case 3 :
if ( strcmp(clss, "E" ) == 0 )
fare1 = 19499 ;
else if ( strcmp(clss,"B"))
fare1 = 20999 ;
else
fare1 = 0 ;
break ;
case 4 :
if (strcmp(clss ,"E" ) == 0 )
fare1 = 23000 ;
else if ( strcmp(clss,"B") == 0 )
fare1 = 34000 ;
else
fare1 = 0 ;
break ;
case 5 :
if (strcmp(clss, "E" ) == 0 )
fare1 = 22000 ;
else if ( strcmp( clss ,"B") == 0 )
fare1 = 34578 ;
else
fare1 = 0 ;
break ;
default :
cout<<"\n\n OOPS !! TRY AGAIN !!!! :) \t\t\t" <<endl ;
}
}
//********************************************************************
// FUNCTION TO INPUT TICKET DETAILS
//********************************************************************
void ticket::getvalue(int book)
{
booking_no=book;
cout<<"\tBoarding Place - " ;
cin>>boarding;
dest:
cout<<"\tDestination Place - " ;
cin>>destination;
//----------- checking destination --------------
if(strcmp(boarding,destination)==0)
{
cout<<"\tError!! Enter Another Destination "<<endl;
goto dest;
}
//------------------------------------------------
cout<<"\tDate of Departure ( dd-mm-yy) - ";
cin>>date2;
//--------------callin flight details --------------
flight_details();
flight:
cout<<"\n\tEnter Your Prefered Flight No ( 1 - 5 ) - " ;
cin>>flight_no;
if(!(flight_no>=1 &&flight_no<=5))
goto flight;
cl:
cout<<"\n\nEnter the Class ( B for Business / E for Economy ) - ";
cin>>clss;
//----------- checking class --------------------------
if(!(strcmp(clss,"E")==0||strcmp(clss,"B")==0))
{
cout<<"\tError!! Enter class again";
goto cl;
}
cal_fare1(flight_no,clss);
cout<<"\n\tEnter Your Timings Prefered in hh:mm format \t" ;
cin>>time;
}
//********************************************************************
// FUNCTION TO INPUT TICKET DETAILS
//********************************************************************
void ticket::putvalue()
{
cout<<setw(8)<<boarding<<setw(10)<<destination<<setw(12)<<date2;
cout<<setw(5)<<flight_no;
cout<<setw(11)<<clss<<setw(12)<<time<<setw(12)<<fare<<endl;
}
//********************************************************************
// FRIEND FUNCTION TO CALCULATE BOOKING FARE
//********************************************************************
void cal_fare(booking &b,ticket&t) // To Calculate Total Fare
{
t.booking_no=b.booking_no;
int total ;
total = b.adults + (b.kids * 0.75) + (b.old * 0.50) ;
t.fare = t.fare1 * total ;
}
//********************************************************************
// ADDING DETAILS IN FILE -BOOKING
//********************************************************************
void add() // Booking of ticket
{
int bookingno;
booking b ;
bookingno=b.auto_booking(); // generate booking no
b.get_booking(bookingno);
ofstream of1("booking.txt",ios::out|ios::app);
ofstream of2("tickets.txt",ios::out|ios::app);
ticket tc;
char ans;
do
{
bookingno++;
b.get_booking(bookingno);
b.input();
of1.write((char *)&b,sizeof(b));
tc.getvalue(bookingno);
//-------------------------------------------
cal_fare(b,tc); // calling friend function
of2.write((char *)&tc,sizeof(tc));
cout<<"\n\n\tWant to add more records? ( y/n)";
cin>>ans;
}while(ans=='y'||ans=='Y');
of1.close();
of2.close();
}
//********************************************************************
// DISPLAYING CONTENTS OF BOOKING FILE
//********************************************************************
void display() // Displaying the ticket
{
booking b ;
ticket tc;
ifstream if1("booking.txt",ios::in);
ifstream if2("tickets.txt",ios::in);
cout<<"\n*********************************************************"<<endl;
cout<<"\nBooking_no\t Name\t Adults \tKids\t S.Citizen "<<endl;
cout<<"\n*********************************************************"<<endl;
while(if1.read((char* )&b,sizeof(b)))
{
b.output();
}
cout<<"\n\n************************************************************"<<endl;
cout<<"\n Boarding Destination Dt_Dept";
cout<<" Flight No. Class Timings Fare"<<endl;
cout<<"\n********************************************************"<<endl<<endl;
while(if2.read((char* )&tc,sizeof(tc)))
{
tc.putvalue();
}
if1.close();
if2.close();
}
//********************************************************************
// FUNCTION DEL USED TO DELETE RECORDS FROM FILE -CANCEL
//********************************************************************
void del(int bookingno)
{
booking b;
ifstream if1("booking.txt") ;
ofstream temp("temp.txt"); // create temporary file
while (if1.read(( char *)&b,sizeof(b)))
{
if(bookingno!=b.ret_book())
{
temp.write(( char * )&b,sizeof(b));
}
}
if1.close();
temp.close();
remove("booking.txt");
rename("temp.txt","booking.txt") ;
}
void del1(int bookingno)
{
ticket tc;
ifstream if2("tickets.txt" ) ;
ofstream tmp("temp1.txt");// create temporary file
while(if2.read(( char *)&tc,sizeof(tc)))
{
if(bookingno!=tc.ret_booking())
{
tmp.write(( char * )&tc,sizeof(tc));
}
}
if2.close();
tmp.close();
remove("tickets.txt");
rename("temp1.txt","tickets.txt") ;
}
void menu()
{
cout<<"\t\t***********************************************"<<endl<<endl;
cout<<"\t\t Welcome To Air Ticket Booking System "<<endl<<endl;
cout<<"\t\t***********************************************"<<endl<<endl;
cout<<"\t\t\t 1. Booking The Ticket \n\n";
cout<<"\t\t\t 2. Booking Details \n\n";
cout<<"\t\t\t 3. Cancellation Of Ticket \n\n";
cout<<"\t\t\t 4. exit \n\n";
cout<<"\t\t***********************************************"<<endl;
}
void welcome_screen()
{
clrscr();
char ch;
gotoxy(15,10);
cout<<"******************* W E L C O M E ********************* ";
gotoxy(25,12);
cout<<"*** *** " ;
gotoxy(15,14);
textcolor(WHITE);
cout<<" AIRLINE M A N A G E M E N T S O F T W A R E ";
gotoxy(33,16);
textcolor(WHITE);
cout<<" D O N E B Y : ";
gotoxy(45,18);
cout<<" GAURAV NARULA ";
gotoxy(25,20);
cout<<"";
textcolor(WHITE);
gotoxy(35,30);
cout<<" *** PRESS ANY KEY TO CONTINUE ***";
getch();
}
//********************************************************************
// MAIN PROGRAM
//********************************************************************
void main ()
{
int choose,book;
textcolor(WHITE);
welcome_screen();
char ans ;
clrscr () ;
do
{
clrscr();
menu();
cout<<"\n\t\t\t Enter Your Choice - ";
cin>> choose;
switch(choose)
{
case 1: add();
break ;
case 2: display() ;
break ;
case 3:cout<<"\t\t Enter The Booking Number You Want To Cancel = ";
cin>>book;
del(book);
del1(book);
break ;
case 4:exit(0);
default :cout<<"\n\t\t Oops Try Again !! \n";
}
cout<<"\n\t\t Do You Want To Continue ( Y / N ) - ";
cin>>ans;
}while(ans=='Y'||ans=='y');
getch();
}