Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Name: Paiwand Abdulla Hamad - QU180137//
- // Program 3
- // 1) Debug the error
- // 2) Produce output as in the question given
- #include <iostream>
- #include <string>
- using namespace std;
- class Car
- { public:
- string name;
- Car(string s)
- { name = s;
- }
- virtual void show()
- { } //cout << "Name: " << name << endl; }
- };
- class NormalCar : public Car
- { public:
- int displacement;
- NormalCar(int d, string s = ""): Car(s)
- {
- displacement = d;
- cout << "Name: " << name << endl;
- cout << "Displacement:" << displacement<< endl;
- }
- void show()
- { cout << "Displacement: " << displacement << endl; }
- };
- class ElectricCar : public Car
- { public:
- int batteryLife;
- ElectricCar(int bl, string s = "") : Car(s)
- { batteryLife = bl;
- cout << "Battery Life:"<< batteryLife << endl;
- }
- void show() {
- cout << "Battery Life: " << batteryLife << endl;
- }
- };
- class HybridCar : public NormalCar, public ElectricCar
- { public:
- int price;
- HybridCar(int p = 50000, int bl = 2, int d = 200, string s = "mcar") : NormalCar(d,s) , ElectricCar(bl,s)
- {
- price = p;
- }
- void show()
- {
- cout << "Price: RM" << price << endl;
- }
- };
- int main()
- { HybridCar *test; //3
- HybridCar h(65000, 2, 2500, "mcar");
- test = &h;
- test->show();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement