Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. // Name: Paiwand Abdulla Hamad - QU180137//
  2. // Program 3
  3. // 1) Debug the error
  4. // 2) Produce output as in the question given
  5. #include <iostream>
  6. #include <string>
  7. using namespace std;
  8.  
  9. class Car
  10. { public:
  11. string name;
  12. Car(string s)
  13. { name = s;
  14.  
  15. }
  16. virtual void show()
  17. { } //cout << "Name: " << name << endl; }
  18. };
  19.  
  20. class NormalCar : public Car
  21. { public:
  22. int displacement;
  23. NormalCar(int d, string s = ""): Car(s)
  24. {
  25. displacement = d;
  26. cout << "Name: " << name << endl;
  27. cout << "Displacement:" << displacement<< endl;
  28. }
  29. void show()
  30. { cout << "Displacement: " << displacement << endl; }
  31. };
  32.  
  33. class ElectricCar : public Car
  34. { public:
  35. int batteryLife;
  36. ElectricCar(int bl, string s = "") : Car(s)
  37. { batteryLife = bl;
  38. cout << "Battery Life:"<< batteryLife << endl;
  39. }
  40. void show() {
  41. cout << "Battery Life: " << batteryLife << endl;
  42. }
  43. };
  44.  
  45. class HybridCar : public NormalCar, public ElectricCar
  46. { public:
  47. int price;
  48. HybridCar(int p = 50000, int bl = 2, int d = 200, string s = "mcar") : NormalCar(d,s) , ElectricCar(bl,s)
  49. {
  50. price = p;
  51. }
  52. void show()
  53. {
  54.  
  55. cout << "Price: RM" << price << endl;
  56.  
  57.  
  58. }
  59. };
  60.  
  61. int main()
  62. { HybridCar *test; //3
  63. HybridCar h(65000, 2, 2500, "mcar");
  64. test = &h;
  65.  
  66. test->show();
  67.  
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement