You are given definitions of an Automobile class and a class Truck derived from Automobile. You are also given a driver program called AutoTest. The driver program creates a Truck and displays information about the truck. Derive another class called Car f

You are given definitions of an Automobile class and a class Truck derived from Automobile. You are also given a driver program called AutoTest. The driver program creates a Truck and displays information about the truck. Derive another class called Car from the Automobile class. The Car has an attribute called Doors (a 2-door or a 4-door car). We could have made doors an attribute of Automobile. We don’t refer to doors when we talk about Trucks. We mention doors only when we talk about a car. Define constructors and a get method for the Car. Update the AutoTest program to create a Car and display its attributes. 1. Automobile.h #ifndef AUTOMOBILE_H #define AUTOMOBILE_H #include using namespace std; class Automobile { private: string make; int model; int mileage; double price; public: Automobile() { make = “”; model = 0; mileage = 0; price = 0.0; } Automobile(string automake, int automodel, int automileage, double autoprice) { make = automake; model = automodel; mileage = automileage; price = autoprice; } string getMake() const { return make; } int getModel() const { return model; } int getMileage() const { return mileage; } double getPrice() const { return price; } }; #endif 2. Truck.h #ifndef TRUCK_H #define TRUCK_H #include “Automobile.h” #include using namespace std; /* Deriving the class Truck from the Automobile class (Base class) */ class Truck : public Automobile { private: string driveType; public: /* Default constructor for Truck. It calls the Automobile default constructor */ Truck() : Automobile() { driveType = “”; } /* Five paraameter constructor for Truck. It calls Automobile constructor, passing some of the Automobile parameters. */ Truck(string truckMake, int truckModel, int truckMileage, double truckPrice, string truckDriveType): Automobile(truckMake, truckModel, truckMileage, truckPrice) { driveType = truckDriveType; // Initialize the Truck data member } /* get methods */ string getDriveType() { return driveType; } }; #endif 3. AutoTest.cpp include #include #include “Car.h” #include “Truck.h” using namespace std;

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>