// inherit4.cpp By: Aiman Hanna - ©1993-2006 Aiman Hanna /// This program will not work. why? Check inherit4.h // Key Points: 1) Access Rights. // - What is visible to an inherited class? What is not? #include "inherit4.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 result the program compilation Creating objects from the 4 classes will start Compiling... inherit4.cpp inherit4.cpp(74) : error C2248: 'price' : cannot access private member declared in class 'Vehicle' inherit4.cpp(75) : error C2248: 'maxSpeed' : cannot access private member declared in class 'Vehicle' inherit4.cpp(86) : error C2248: 'price' : cannot access private member declared in class 'Vehicle' inherit4.cpp(87) : error C2248: 'maxSpeed' : cannot access private member declared in class 'Vehicle' inherit4.cpp(108) : error C2248: 'price' : cannot access private member declared in class 'Vehicle' inherit4.cpp(108) : error C2248: 'maxSpeed' : cannot access private member declared in class 'Vehicle' inherit4.cpp(120) : error C2248: 'price' : cannot access private member declared in class 'Vehicle' inherit4.cpp(121) : error C2248: 'maxSpeed' : cannot access private member declared in class 'Vehicle' inherit4.cpp(132) : error C2248: 'price' : cannot access private member declared in class 'Vehicle' inherit4.cpp(133) : error C2248: 'maxSpeed' : cannot access private member declared in class 'Vehicle' inherit4.cpp(158) : error C2248: 'price' : cannot access private member declared in class 'Vehicle' inherit4.cpp(158) : error C2248: 'maxSpeed' : cannot access private member declared in class 'Vehicle' inherit4.cpp(176) : error C2248: 'price' : cannot access private member declared in class 'Vehicle' inherit4.cpp(177) : error C2248: 'maxSpeed' : cannot access private member declared in class 'Vehicle' inherit4.cpp(178) : error C2248: 'model' : cannot access private member declared in class 'Car' inherit4.cpp(188) : error C2248: 'price' : cannot access private member declared in class 'Vehicle' inherit4.cpp(189) : error C2248: 'maxSpeed' : cannot access private member declared in class 'Vehicle' inherit4.cpp(190) : error C2248: 'model' : cannot access private member declared in class 'Car' inherit4.cpp(216) : error C2248: 'price' : cannot access private member declared in class 'Vehicle' inherit4.cpp(216) : error C2248: 'maxSpeed' : cannot access private member declared in class 'Vehicle' inherit4.cpp(217) : error C2248: 'model' : cannot access private member declared in class 'Car' Error executing cl.exe. inherit1.exe - 21 error(s), 0 warning(s) */