-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.cpp
More file actions
511 lines (448 loc) · 16 KB
/
Copy pathcode.cpp
File metadata and controls
511 lines (448 loc) · 16 KB
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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
#include <iostream>
#include<windows.h>
#include <fstream>
#include <string>
using namespace std;
const int max_flights = 100;
void loadingBar();
void greeting();
class Flight {
private:
string flightNumber;
string source;
string destination;
string date;
string time;
int availableSeats;
double fare;
public:
Flight() : availableSeats(0), fare(0.0) {}
void setDetails(const string& fn, const string& src, const string& dest, const string& d, const string& t, int seats, double f) {
flightNumber = fn;
source = src;
destination = dest;
date = d;
time = t;
availableSeats = seats;
fare = f;
}
void displayDetails() const;
bool checkAvailability(int seats) const;
bool bookSeat(int seats);
bool cancelSeat(int seats);
string getFlightNumber() const { return flightNumber; }
string getSource() const { return source; }
string getDestination() const { return destination; }
string getDate() { return date; }
string getTime() { return time; }
int getSeats() { return availableSeats; }
};
class Admin {
private:
string username;
string password;
public:
Admin(const string& u, const string& p) : username(u), password(p) {}
void addFlight(Flight flights[], int& flightCount);
void removeFlight(Flight flights[], int& flightCount, const string& flightNumber);
void modifyFlight(Flight flights[], int flightCount, const string& flightNumber);
void viewAllFlights(const Flight flights[], int flightCount) const;
void setFlightDetails(Flight& flight);
void setTicketPrice(Flight& flight, double price);
string getUsername() { return username; }
string getPassword() { return password; }
};
class User {
private:
string userID;
string name;
string contactDetails;
public:
User(const string& id, const string& n, const string& contact) : userID(id), name(n), contactDetails(contact) {}
void searchFlight(const Flight flights[], int flightCount, const string& source, const string& destination) const;
void bookFlight(Flight flights[], int flightCount, const string& flightNumber, int seats);
void cancelBooking(Flight flights[], int flightCount, const string& flightNumber, int seats);
void viewBooking(const Flight flights[], int flightCount, const string& flightNumber) const;
};
class Booking {
private:
string bookingID;
string flightNumber;
string userID;
int seatsBooked;
public:
Booking(const string& bid, const string& fn, const string& uid, int seats) : bookingID(bid), flightNumber(fn), userID(uid), seatsBooked(seats) {}
void createBooking();
void cancelBooking();
void displayBookingDetails() const;
};
// Function definitions for Flight
void Flight::displayDetails() const {
cout << "Flight Number: " << flightNumber << endl;
cout << "Source: " << source << endl;
cout << "Destination: " << destination << endl;
cout << "Date: " << date << endl;
cout << "Time: " << time << endl;
cout << "Available Seats: " << availableSeats << endl;
cout << "Fare: $" << fare << endl;
}
bool Flight::checkAvailability(int seats) const {
return availableSeats >= seats;
}
bool Flight::bookSeat(int seats) {
if (checkAvailability(seats)) {
availableSeats -= seats;
return true;
}
return false;
}
bool Flight::cancelSeat(int seats) {
availableSeats += seats;
return true;
}
void Admin::addFlight(Flight flights[], int& flightCount) {
if (flightCount >= max_flights) {
cout << "Cannot add more flights. Maximum limit reached." << endl;
return;
}
string fn, src, dest, d, t;
int seats;
double fare;
cout << "Enter Flight Number: ";
cin >> fn;
cout << "Enter Source: ";
cin >> src;
cout << "Enter Destination: ";
cin >> dest;
cout << "Enter Date: ";
cin >> d;
cout << "Enter Time: ";
cin >> t;
cout << "Enter Available Seats: ";
cin >> seats;
cout << "Enter Fare: ";
cin >> fare;
flights[flightCount++].setDetails(fn, src, dest, d, t, seats, fare);
}
void Admin::removeFlight(Flight flights[], int& flightCount, const string& flightNumber) {
for (int i = 0; i < flightCount; ++i) {
if (flights[i].getFlightNumber() == flightNumber) {
for (int j = i; j < flightCount - 1; ++j) {
flights[j] = flights[j + 1];
}
--flightCount;
break;
}
}
}
void Admin::modifyFlight(Flight flights[], int flightCount, const string& flightNumber) {
for (int i = 0; i < flightCount; ++i) {
if (flights[i].getFlightNumber() == flightNumber) {
setFlightDetails(flights[i]);
break;
}
}
}
void Admin::viewAllFlights(const Flight flights[], int flightCount) const {
for (int i = 0; i < flightCount; ++i) {
flights[i].displayDetails();
cout << "--------------------------" << endl;
}
}
void Admin::setFlightDetails(Flight& flight) {
string fn, src, dest, d, t;
int seats;
double fare;
cout << "Enter new Flight Number: ";
cin >> fn;
cout << "Enter new Source: ";
cin >> src;
cout << "Enter new Destination: ";
cin >> dest;
cout << "Enter new Date: ";
cin >> d;
cout << "Enter new Time: ";
cin >> t;
cout << "Enter new Available Seats: ";
cin >> seats;
cout << "Enter new Fare: ";
cin >> fare;
flight.setDetails(fn, src, dest, d, t, seats, fare);
}
void Admin::setTicketPrice(Flight& flight, double price) {
string fn, src, dest, d, t;
int seats;
flight.setDetails(flight.getFlightNumber(), flight.getSource(), flight.getDestination(), flight.getDate(), flight.getTime(), flight.getSeats(), price);
}
void User::searchFlight(const Flight flights[], int flightCount, const string& source, const string& destination) const {
for (int i = 0; i < flightCount; ++i) {
if (flights[i].getSource() == source && flights[i].getDestination() == destination) {
flights[i].displayDetails();
}
}
}
void User::bookFlight(Flight flights[], int flightCount, const string& flightNumber, int seats) {
for (int i = 0; i < flightCount; ++i) {
if (flights[i].getFlightNumber() == flightNumber) {
if (flights[i].bookSeat(seats)) {
cout << "Booking successful!" << endl;
}
else {
cout << "Not enough seats available." << endl;
}
break;
}
}
}
void User::cancelBooking(Flight flights[], int flightCount, const string& flightNumber, int seats) {
for (int i = 0; i < flightCount; ++i) {
if (flights[i].getFlightNumber() == flightNumber) {
flights[i].cancelSeat(seats);
cout << "Booking cancelled." << endl;
break;
}
}
}
void User::viewBooking(const Flight flights[], int flightCount, const string& flightNumber) const {
for (int i = 0; i < flightCount; ++i) {
if (flights[i].getFlightNumber() == flightNumber) {
flights[i].displayDetails();
break;
}
}
}
void Booking::createBooking() {
ofstream outFile("bookings.txt", ios::app);
if (!outFile) {
cerr << "Error opening file for writing!" << endl;
return;
}
outFile << "Booking ID: " << bookingID << endl;
outFile << "Flight Number: " << flightNumber << endl;
outFile << "User ID: " << userID << endl;
outFile << "Seats Booked: " << seatsBooked << endl;
outFile << "--------------------------" << endl;
outFile.close();
cout << "Booking created successfully!" << endl;
}
void Booking::cancelBooking() {
ifstream inFile("bookings.txt");
ofstream outFile("temp.txt");
if (!inFile) {
cerr << "Error opening file for reading!" << endl;
return;
}
if (!outFile) {
cerr << "Error opening file for writing!" << endl;
inFile.close();
return;
}
string line;
bool found = false;
while (getline(inFile, line)) {
if (line.find("Booking ID: " + bookingID) != string::npos) {
for (int i = 0; i < 4; ++i) {
getline(inFile, line);
}
found = true;
}
else {
outFile << line << endl;
}
}
inFile.close();
outFile.close();
remove("bookings.txt");
rename("temp.txt", "bookings.txt");
if (found) {
cout << "Booking with ID " << bookingID << " cancelled successfully!" << endl;
}
else {
cout << "Booking with ID " << bookingID << " not found!" << endl;
}
}
void Booking::displayBookingDetails() const {
cout << "Booking ID: " << bookingID << endl;
cout << "Flight Number: " << flightNumber << endl;
cout << "User ID: " << userID << endl;
cout << "Seats Booked: " << seatsBooked << endl;
}
int main() {
system("color 3");
greeting();
Flight flights[max_flights];
int flightCount = 0;
Admin admin("admin", "admin123");
flights[flightCount++].setDetails("FN001", "New York", "London", "2024-07-10", "14:00", 200, 500.0);
flights[flightCount++].setDetails("FN002", "London", "Paris", "2024-07-11", "12:00", 150, 400.0);
flights[flightCount++].setDetails("FN003", "Paris", "Rome", "2024-07-12", "11:00", 180, 450.0);
int choice;
string username, password;
do {
cout << "\n===== Flight Management System =====" << endl;
cout << "1. Admin Login" << endl;
cout << "2. User Menu" << endl;
cout << "3. Exit" << endl;
cout << "Enter your choice: ";
cin >> choice;
switch (choice) {
case 1:
cout << "\nEnter Admin Username: ";
cin >> username;
cout << "Enter Admin Password: ";
cin >> password;
if (username == admin.getUsername() && password == admin.getPassword()) {
int adminChoice;
do {
cout << "\n===== Admin Menu =====" << endl;
cout << "1. Add Flight" << endl;
cout << "2. Remove Flight" << endl;
cout << "3. Modify Flight" << endl;
cout << "4. View All Flights" << endl;
cout << "5. Logout" << endl;
cout << "Enter your choice: ";
cin >> adminChoice;
switch (adminChoice) {
case 1:
admin.addFlight(flights, flightCount);
break;
case 2: {
string flightNumber;
cout << "Enter Flight Number to Remove: ";
cin >> flightNumber;
admin.removeFlight(flights, flightCount, flightNumber);
break;
}
case 3: {
string flightNumber;
cout << "Enter Flight Number to Modify: ";
cin >> flightNumber;
admin.modifyFlight(flights, flightCount, flightNumber);
break;
}
case 4:
admin.viewAllFlights(flights, flightCount);
break;
case 5:
cout << "Logging out from Admin..." << endl;
break;
default:
cout << "Invalid choice. Please try again." << endl;
}
} while (adminChoice != 5);
}
else {
cout << "Invalid username or password. Please try again." << endl;
}
break;
case 2:
{
string userID, name, contact;
cout << "Enter User ID: ";
cin >> userID;
cout << "Enter Name: ";
cin >> name;
cout << "Enter Contact Details: ";
cin >> contact;
User user(userID, name, contact);
int userChoice;
do {
cout << "\n===== User Menu =====" << endl;
cout << "1. Search Flight" << endl;
cout << "2. Book Flight" << endl;
cout << "3. Cancel Booking" << endl;
cout << "4. View Booking" << endl;
cout << "5. Logout" << endl;
cout << "Enter your choice: ";
cin >> userChoice;
switch (userChoice) {
case 1: {
string src, dest;
cout << "Enter Source: ";
cin >> src;
cout << "Enter Destination: ";
cin >> dest;
user.searchFlight(flights, flightCount, src, dest);
break;
}
case 2: {
string flightNumber;
int seats;
cout << "Enter Flight Number: ";
cin >> flightNumber;
cout << "Enter Number of Seats: ";
cin >> seats;
user.bookFlight(flights, flightCount, flightNumber, seats);
break;
}
case 3: {
string flightNumber;
int seats;
cout << "Enter Flight Number: ";
cin >> flightNumber;
cout << "Enter Number of Seats to Cancel: ";
cin >> seats;
user.cancelBooking(flights, flightCount, flightNumber, seats);
break;
}
case 4: {
string flightNumber;
cout << "Enter Flight Number: ";
cin >> flightNumber;
user.viewBooking(flights, flightCount, flightNumber);
break;
}
case 5:
cout << "Logging out from User..." << endl;
break;
default:
cout << "Invalid choice. Please try again." << endl;
}
} while (userChoice != 5);
break;
}
case 3:
cout << "Exiting the program..." << endl;
break;
default:
cout << "Invalid choice. Please try again." << endl;
}
} while (choice != 3);
return 0;
}
void loadingBar()
{
char a = 177, b = 219;
cout << "\n\n\t\t\t\t\t\t Loading...\n\n";
cout << "\t\t\t\t\t";
for (int i = 0; i < 26; i++) {
cout << char(a);
}
cout << "\r\t\t\t\t\t";
for (int i = 0; i < 26; i++) {
cout << char(b);
Sleep(200);
}
cout << endl;
cout << "\t\t\t\t";
system("pause");
system("cls");
}
void greeting()
{
cout << "\n\n\n\n\n";
cout << "\t\t\t _ __ ___ __ ____ ___ ___ ___ ____" << endl;
cout << "\t\t\t /\\ \\ /\\ \\ _ \\/\\ \\ /\\ __\\/\\ _ \\/\\ _ \\ _ \\/\\ __ \\" << endl;
cout << "\t\t\t \\ \\ \\ \\ \\ \\ \\ _/\\ \\ \\ \\ \\ \\_/\\ \\ \\/\\ \\ \\ \\ \\\\_\\\\ \\ \\ __/" << endl;
cout << "\t\t\t \\ \\ \\ \\ \\ \\ \\ \\_\\ \\ \\ \\ \\ \\ \\ \\ \\\\\\ \\ \\ \\ \\|_|\\ \\ \\ \\__" << endl;
cout << "\t\t\t \\ \\ \\ _ \\ \\ \\ \\ \\_\\ \\ \\ \\ \\ \\ \\ \\ \\\\\\ \\ \\ \\ \\ \\ \\ \\ \\___\\" << endl;
cout << "\t\t\t \\ \\ \\/|_\\\\ \\ \\ \\ \\/|\\ \\ \\__\\ \\ \\__\\ \\ \\\\\\ \\ \\ \\ \\ \\ \\ \\ \\__" << endl;
cout << "\t\t\t \\ \\____\\ \\__\\ \\___\\ \\___\\ \\__\\ \\_\\ \\ \\_\\ \\____|" << endl;
cout << "\t\t\t \\|____|\\|__\\|____|\\|___|\\___|\\|_| \\|_|\\|____|" << endl;
cout << "\n\n";
cout << "\t\t\t\t**************( " << char(3) << " TO ONESTAR AIRLINES " << char(3) << " )*************\n";
cout << "\n\n\n\n";
cout << "\t\tWelcome to our Airline sir....." << endl;
cout << "\t\twe are opening menu for you\n";
loadingBar();
}