← Back

C++ Header


#ifndef ENTITY_H
#define ENTITY_H

static const int MAX_JOBS = 3;
static const int MAX_CARS = 1000;
static const int MAX_EMPLOYEES = 1000;
static const int MAX_LOANS = 10000;

class Entity; class Bank; class Borrower; class Car; class Company; class Person; class Contract;

class Loan {

    private:

        Borrower& borrower;
        Bank& lender;
        float amount_remaining;
        Car* collateral;

    public:

        Loan(Borrower& borrower, Bank& lender, float amount);        
        void pay(float amount, Entity& payer);
        float get_amount() const;
        Car* get_car() const;
        void set_car(Car& car);

    friend class Bank;

};

class Car {

    private:

        const std::string number_plate;
        const int horsepower;
        float mileage; 
        Entity& owner;
        Loan* loan;
    
    public:

        Car(std::string number_plate, const int horsepower, Entity& owner);

        float get_price() const;
        Loan* get_loan() const;
        void assign_loan(Loan &l);

};

class Entity {

    private:
        const std::string name;
        const std::string address;
        Car* cars[MAX_CARS];

    public:
        Entity(const std::string name, const std::string address);
        virtual ~Entity() = default;

};

class Bank : public Entity {

    private:
        const float rate;
        Loan* loans[MAX_LOANS];
        Loan* init_loan(float amount);

    public:
        Bank(const std::string name, const std::string address, const float rate);
        bool grant_loan(Borrower &n, Car &c);
        const float get_rate() const;

};

class Borrower : public Entity {

    public:
        Borrower(const std::string name, const std::string address);
        virtual float get_income() const = 0;
        bool apply_for_loan(Bank &b, Car &c);
        bool send_letter(Loan &l, Bank &b);

};

class Company : public Borrower {

    private:
        Contract* contracts[MAX_EMPLOYEES];
        float turnover;

    public:

        Company(const std::string name, const std::string address, float turnover);
        float get_income() const override;
        void hire(Person &p, int salary);

};

class Person : public Borrower {

    private:
    int employer_count;
    Contract* contracts[MAX_JOBS];
    
    public:

        Person(const std::string name, const std::string address, Company& first_employer, float first_salary); 
        float get_income() const override;
        int get_employer_count() const;
        void get_hired(Company &c, int salary);

};

class Contract {

    private:
        Company& employer;
        Person& employee;
        const float salary;

    public:
        Contract(Company& employer, Person& person, const float salary);
        Company& get_employer() const;
        Person& get_employee() const;
        float get_salary() const;

};

#endif