#include <iostream> #include <string> #include <vector> #include <memory> // for smart…
- User
#include #include #include #include // 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; // using smart pointers vector passengers;
Flight(string flightNumber, string source, string destination, string date, string time, shared_ptr 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 flights;
public: void bookFlight(string flightNumber, string destination, string date, string time, shared_ptr airline, Passenger passenger) { vector 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];
- Assistant
The error in the code is due to incomplete type 'Flight'. The class 'Passenger' has a member function 'bookFlight' that takes a pointer to 'Flight' object as an argument. But the class 'Flight' is defined after the 'Passenger' class. To fix this error, we can either move the definition of the 'Flight' class above the 'Passenger' class or use a forward declaration of the 'Flight' class before the 'Passenger' class.
Here is an example of using a forward declaration:
code - User
public: void trackLuggage(string luggageId) const { for (const auto& flight : flights) { for (const auto& passenger : flight.passengers) { for (const auto& luggage : passenger.getLuggage()) { if (luggage.getId() == luggageId) { cout << "Luggage " << luggageId << " is " << luggage.getStatus() << " and is associated with flight " << flight.flightNumber << endl; return; } } } }
codecout << "Luggage " << luggageId << " not found" << endl; } - Assistant
The method 'trackLuggage' searches for a luggage with a given ID and prints its status and the associated flight number if found. If the luggage is not found in any of the flights, it prints a message indicating that the luggage was not found.
The method achieves the functionality by iterating over each flight, then each passenger in the flight, and finally each luggage associated with the passenger. It compares the ID of each luggage with the given ID.
Once a luggage with the given ID is found, the method prints its status and associated flight number and returns from the function using the 'return' statement. This is because there is no point in iterating further since the luggage has been found.
If the luggage is not found after iterating over all the flights, passengers, and luggage, the method prints a message indicating that the luggage was not found.
Overall, the method provides a way to track the status and location of luggage in the airport system.