fork download
  1. #include<iostream>
  2. using namespace std;
  3. class Vehicle{
  4. protected:
  5. string model;
  6. int year;
  7. double engineSize;
  8.  
  9. public:
  10. Vehicle(string m, int y, double e){
  11. model=m; year=y; engineSize=e;
  12. }
  13. string getModel(){
  14. return model;
  15. }
  16. int getYear(){
  17. return year;
  18. }
  19. double getEngineSize(){
  20. return engineSize;
  21. }
  22. void display(){
  23. cout << "Model: " << model << endl;
  24. cout << "Year: " << year << endl;
  25. cout << "Engine Size: " << engineSize << " L" << endl;
  26. }
  27.  
  28. };
  29.  
  30. class Car: public Vehicle{
  31. protected:
  32. int trunk;
  33.  
  34. public:
  35. Car(string m, int y, double e, int t):Vehicle(m,y,e){
  36. trunk=t;
  37. }
  38.  
  39. int getTrunk(){
  40. return trunk;
  41. }
  42.  
  43. void display(){
  44. Vehicle::display();
  45. cout << "Trunk Capacity: " << trunk << endl;
  46. }
  47. };
  48.  
  49. class Bus: public Vehicle{
  50. protected:
  51. int sitting, standing;
  52.  
  53. public:
  54. Bus(int st, int sd, string m, int y, double e): Vehicle(m,y,e){
  55. sitting=st; standing=sd;
  56. }
  57.  
  58. int getSitting(){
  59. return sitting;
  60. }
  61.  
  62. int getStanding(){
  63. return standing;
  64. }
  65.  
  66. void display(){
  67. Vehicle::display();
  68. cout<<"No. of sitting passengers: "<<sitting<<endl;
  69. cout<<"No. of standing passengers: "<<standing<<endl;
  70. }
  71. };
  72. int main(){
  73.  
  74. return 0;
  75. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty