// inherit5.cpp By: Aiman Hanna - ©1993-2006 Aiman Hanna /// This program fixes the problem of inherit4.cpp. However, the changes are only // in the .h file. See inherit5.h // Key Points: 1) The 'protected' access right. #include "inherit5.h" // The Vehicle class Vehicle::Vehicle() { cout << "\n Veh...Executing the default constructor of the base class. " << "\n"; price = 0; maxSpeed = 0; } Vehicle::Vehicle(double pr, int ms) { cout << "\n Veh...Executing the 'parameterized' constructor of the base class. " << "\n"; price = pr; maxSpeed = ms; } void Vehicle::setPrice(double pr) { price = pr; } double Vehicle::getPrice( ) { return price; } void Vehicle::setMaxSpeed(int ms) { maxSpeed = ms; } int Vehicle::getMaxSpeed() { return maxSpeed; } void Vehicle::showInfo() { cout << " The vehicle price is " << price << "$, and its maximum speed is " << maxSpeed << "km." << endl << endl; } // The Bus class Bus::Bus() { cout << "\n BS...Executing the default constructor of the Bus class. " << "\n"; price = 0; maxSpeed = 0; cargoCapacity = 0; } Bus::Bus(double pr, int ms, double cc): Vehicle(pr, ms) { cout << "\n BS...Executing the 'parameterized' constructor of the Bus class. " << "\n"; price = pr; maxSpeed = ms; cargoCapacity = cc; } void Bus::setCargoCapacity(double cc) { cargoCapacity = cc; } double Bus::getCargoCapacity() { return cargoCapacity; } void Bus::showInfo() // This functions overrides the showInfo function from the base class { cout << " The bus price is " << price << "$, and its maximum speed is " << maxSpeed << "km. The bus has a cargo capacity of " << cargoCapacity << "." << endl << endl; } // The Car class Car::Car() { cout << "\n CR...Executing the default constructor of the Car class. " << "\n"; price = 0; maxSpeed = 0; model = new char [20]; strcpy(model, "Not Yet Known"); } Car::Car(double pr, int ms, char* md) : Vehicle(pr, ms) { cout << "\n CR...Executing the 'parameterized' constructor of the Car class. " << "\n"; price = pr; maxSpeed = ms; model = new char [20]; strcpy(model, md); } void Car::setModel(char* md) { strcpy(model, md); } char* Car::getModel() { return model; } void Car::showInfo() // This functions overrides the showInfo function from the base class { cout << " The car price is " << price << "$, and its maximum speed is " << maxSpeed << "km. The car model is " << model << "." << endl << endl; } Car::~Car() { delete [] model; } // The Convertible car class Convertible ::Convertible() { cout << "\n CV...Executing the default constructor of the Convertible class." << "\n"; price = 0; maxSpeed = 0; strcpy(model, "Not Yet Known"); top = softtop; } Convertible::Convertible(double pr, int ms, char* md, toptype tt): Car(pr, ms, md) { cout << "\n CV...Executing the 'parameterized' constructor of the Convertible class." << "\n"; price = pr; maxSpeed = ms; strcpy(model, md); top = tt; } void Convertible::setTopType(toptype tt) { top = tt; } char* Convertible::getTopType() { if (top == softtop) return "soft top"; else return "hard top"; } void Convertible::showInfo() // This functions overrides both showInfo functions from the parent classes { cout << " The price of the convertible car is " << price << "$, and its maximum speed is " << maxSpeed << "km. The convertible car model is " << model << ". The car has a " << getTopType() << "." << endl << endl; } int main() { cout << " Creating objects from the 4 classes will start" << "\n"; Vehicle v1(10000, 100); cout << endl; Bus b1(20000, 200, 8); cout << endl; Car c1(30000, 300, "BMW"); cout << endl; Convertible cv1(40000, 400, "Benz", softtop); cout << endl; cout << "\n Finished Creating objects from the 4 classes. Will start modifying then showing" << " their information." << "\n\n"; v1.showInfo(); b1.showInfo(); c1.showInfo(); cv1.showInfo(); return 0; } /* The output of the program Creating objects from the 4 classes will start Veh...Executing the 'parameterized' constructor of the base class. Veh...Executing the 'parameterized' constructor of the base class. BS...Executing the 'parameterized' constructor of the Bus class. Veh...Executing the 'parameterized' constructor of the base class. CR...Executing the 'parameterized' constructor of the Car class. Veh...Executing the 'parameterized' constructor of the base class. CR...Executing the 'parameterized' constructor of the Car class. CV...Executing the 'parameterized' constructor of the Convertible class. Finished Creating objects from the 4 classes. Will start modifying then showing their information. The vehicle price is 10000$, and its maximum speed is 100km. The bus price is 20000$, and its maximum speed is 200km. The bus has a cargo capacity of 8. The car price is 30000$, and its maximum speed is 300km. The car model is BMW. The price of the convertible car is 40000$, and its maximum speed is 400km. The convertible car model is Benz. The car has a soft top. */