#include <iostream>
#include <string>
#include <vector>
#include <memory> // for smart pointers

using namespace std;

class Flight;

// Structure to store information about a passenger
class Passenger {
string name;
string email;
string phone;

public:
Passenger(string name, string email, string phone) {
this->name = name;
this->email = email;
this->phone = phone;
}

void bookFlight(Flight* flight) {
flight->passengers.push_back(*this);
}

string getName() const {
return name;
}

string getEmail() const {
return email;
}

string getPhone() const {
return phone;
}
};

// Base class for airlines
class Airline {
protected:
string name;

public:
Airline(string name) {
this->name = name;
}

virtual double getTicketPrice() const = 0; // pure virtual function

string getName() const {
return name;
}
};

// Derived class for economy airlines
class EconomyAirline : public Airline {
public:
EconomyAirline() : Airline(“Economy”) {}

double getTicketPrice() const {
return 100.00; // arbitrary ticket price for example purposes
}
};

// Derived class for business airlines
class BusinessAirline : public Airline {
public:
BusinessAirline() : Airline(“Business”) {}

double getTicketPrice() const {
return 200.00; // arbitrary ticket price for example purposes
}
};

// Derived class for first class airlines
class FirstClassAirline : public Airline {
public:
FirstClassAirline() : Airline(“First Class”) {}

double getTicketPrice() const {
return 300.00; // arbitrary ticket price for example purposes
}
};

// Structure to store information about a flight
struct Flight {
string flightNumber;
string source;
string destination;
string date;
string time;
shared_ptr<Airline> airline; // using smart pointers
vector<Passenger> passengers;

Flight(string flightNumber, string source, string destination, string date, string time, shared_ptr<Airline> airline) {
this->flightNumber = flightNumber;
this->source = source;
this->destination = destination;
this->date = date;
this->time = time;
this->airline = airline;
}

string getSource() const { // making this a const member function
return source;
}
};

// Class for the airport system
class AirportSystem {
public:
vector<Flight> flights;

public:
void bookFlight(string flightNumber, string destination, string date, string time, shared_ptr<Airline> airline, Passenger passenger) {
vector<Passenger> passengers = { passenger };
Flight flight(flightNumber, “”, destination, date, time, airline);
flight.passengers = passengers;
flights.push_back(flight); // add the new flight object to the flights vector
cout << “Flight " << flightNumber << " booked successfully!” << endl;
}

void displayFlights() const { // making this a const member function
for (int i = 0; i < flights.size(); i++) {
Flight flight = flights[i];

cout << "Flight Number: " << flight.flightNumber << endl;
cout << "Source: " << flight.getSource() << endl;
cout << "Destination: " << flight.destination << endl;
cout << "Date: " << flight.date << endl;
cout << "Time: " << flight.time << endl;
cout << "Airline: " << flight.airline->getName() << endl;
cout << “Ticket Price: $” << flight.airline->getTicketPrice() << endl;
cout << "Passengers: " << endl;

for (int j = 0; j < flight.passengers.size(); j++) {
Passenger passenger = flight.passengers[j];
cout << "Name: " << passenger.getName() << ", Email: " << passenger.getEmail() << ", Phone: " << passenger.getPhone() << endl;
}
cout << endl;
}
}
};

int main() {
AirportSystem airportSystem;

// Create passengers
Passenger passenger1(“John Smith”, “johnsmith@example.com”, “1234567890”);
Passenger passenger2(“Sarah Johnson”, “sarahjohnson@example.com”, “0987654321”);

// Create airlines using smart pointers
shared_ptr<Airline> economyAirline = make_shared<EconomyAirline>();
shared_ptr<Airline> businessAirline = make_shared<BusinessAirline>();
shared_ptr<Airline> firstClassAirline = make_shared<FirstClassAirline>();

// Create flights using smart pointers
shared_ptr<Flight> flight1 = make_shared<Flight>(“ABC123”, “New York”, “London”, “2023-05-01”, “10:00”, economyAirline);
shared_ptr<Flight> flight2 = make_shared<Flight>(“DEF456”, “London”, “Paris”, “2023-05-01”, “11:30”, businessAirline);
shared_ptr<Flight> flight3 = make_shared<Flight>(“GHI789”, “Paris”, “Tokyo”, “2023-05-02”, “01:00”, firstClassAirline);

// Book flights for passengers
airportSystem.bookFlight(flight1->flightNumber, flight1->destination, flight1->date, flight1->time, flight1->airline, passenger1);
airportSystem.bookFlight(flight2->flightNumber, flight2->destination, flight2->date, flight2->time, flight2->airline, passenger2);
airportSystem.bookFlight(flight3->flightNumber, flight3->destination, flight3->date, flight3->time, flight3->airline, passenger1);

// Display flight details
airportSystem.displayFlights();

// Clean up memory using smart pointers
// No need to manually delete objects

return 0;
}
main.cpp: In member function ‘void Passenger::bookFlight(Flight*)’:
main.cpp:25:7: error: invalid use of incomplete type ‘class Flight’
25 | flight->passengers.push_back(*this);
| ^~
main.cpp:9:7: note: forward declaration of ‘class Flight’
9 | class Flight;
| ^~~~~~