forked from ashishps1/awesome-low-level-design
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAirlineManagementSystem.cpp
More file actions
89 lines (74 loc) · 2.72 KB
/
AirlineManagementSystem.cpp
File metadata and controls
89 lines (74 loc) · 2.72 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
#include "AirlineManagementSystem.hpp"
#include <iostream>
AirlineManagementSystem::AirlineManagementSystem() : bookingIdCounter(1) {}
AirlineManagementSystem::~AirlineManagementSystem() {
for (auto flight : flights) delete flight;
for (auto passenger : passengers) delete passenger;
for (auto booking : bookings) delete booking;
}
void AirlineManagementSystem::addFlight(Flight* flight) {
flights.push_back(flight);
}
void AirlineManagementSystem::addPassenger(Passenger* passenger) {
passengers.push_back(passenger);
}
std::string AirlineManagementSystem::createBooking(Flight* flight, Passenger* passenger, int seatNumber) {
if (!flight->bookSeat(seatNumber)) {
return "";
}
std::string bookingId = "B" + std::to_string(bookingIdCounter++);
Booking* booking = new Booking(bookingId, flight, passenger, seatNumber);
bookings.push_back(booking);
return bookingId;
}
bool AirlineManagementSystem::cancelBooking(std::string bookingId) {
Booking* booking = findBooking(bookingId);
if (!booking) return false;
booking->getFlight()->cancelSeat(booking->getSeatNumber());
auto it = std::find(bookings.begin(), bookings.end(), booking);
if (it != bookings.end()) {
bookings.erase(it);
delete booking;
return true;
}
return false;
}
void AirlineManagementSystem::displayAllFlights() const {
std::cout << "\nAll Flights:" << std::endl;
for (const auto& flight : flights) {
flight->displayFlightInfo();
std::cout << "------------------------" << std::endl;
}
}
void AirlineManagementSystem::displayAllPassengers() const {
std::cout << "\nAll Passengers:" << std::endl;
for (const auto& passenger : passengers) {
passenger->displayInfo();
std::cout << "------------------------" << std::endl;
}
}
void AirlineManagementSystem::displayAllBookings() const {
std::cout << "\nAll Bookings:" << std::endl;
for (const auto& booking : bookings) {
booking->displayBookingInfo();
std::cout << "------------------------" << std::endl;
}
}
Flight* AirlineManagementSystem::findFlight(std::string flightNumber) const {
for (auto flight : flights) {
if (flight->getFlightNumber() == flightNumber) return flight;
}
return nullptr;
}
Passenger* AirlineManagementSystem::findPassenger(std::string passportNumber) const {
for (auto passenger : passengers) {
if (passenger->getPassportNumber() == passportNumber) return passenger;
}
return nullptr;
}
Booking* AirlineManagementSystem::findBooking(std::string bookingId) const {
for (auto booking : bookings) {
if (booking->getBookingId() == bookingId) return booking;
}
return nullptr;
}