dimanche 24 octobre 2021

Converting UML to code c++. Problem with inheritence. Do constructors of all classes run when object of any one of them is created?

UML code -> C++ code

//Parent class Flight

class Flight
{
    private:
        int callNumber;
        Airplane plane;
        vector<Passenger> passengers;
    
    public:

//Constructor

        Flight();

//Functions

        int getCallNum();
        void setCallNum();
        Airplane getPlane();

//What parameters are taken in these functions.

//I know they are of type Airplane and passenger but are they vectors?

        void setPlane(Airplane);            
        void addPassenger(Passenger);
        void removePassenger(Passenger);    
};

//Airplane class, child of Flight

class Airplane : public Flight
{
    private:
        int firstClassSeats;
        int economySeats;

    public:

//Constructor

        Airplane();

//Functions;

        int getFirstClassSeats();
        int getEconomySeats();
        void setFirstClassSeats();
        void setEconomySeats();
};

//Passenger class, child of FLight

class Passenger : public Flight
{
    private:
        string name;
        int age;
        string address;

    public:

//Constructor

        Passenger();

//Functions

        string getName();
        int getAge();
        string getAddress();
        void setName(string);
        void setAge(int);
        void setAddress(string);    
};

Aucun commentaire:

Enregistrer un commentaire