#ifndef CAR_H #define CAR_H #include "Automobile.h" using namespace std; //subclass Car has a special attribute for number of doors which can be 2 or 4 class Car : public Automobile { protected: int doors; public: // Default constructor inherits all of the base class attributes (data and fcns) // if sets doors to a standard 4 Car() : Automobile() { doors = 4; //default } // Constructor #2 with initializer list Car(string carMake, int carModel, int carMileage, double carPrice, int carDoors) : Automobile(carMake, carModel, carMileage, carPrice) { if (carDoors == 2) doors = carDoors; else doors = 4; //default } // Accessor for doors attribute int getDoors() { return doors; } //All overridden functions are virtual by default but it is OK to say so //virtual means dynamic address resolution is possible so the correct fcn //is called for the object virtual void displayVehicleInfo() const override { //remember that protected data is accessible by the derived class! cout << fixed << showpoint << setprecision(2); cout << "Model year " << model << endl; cout << "Make " << make << endl; cout << "with " << doors << " doors" << endl; cout << "mileage " << mileage << " miles " << endl; cout << "Price: $" << price << endl; } }; //end class CAR #endif // CAR_H