Answer to Question #241633 in C++ for prakriti

Question #241633
  1. Write a C++ program for the class vehicle and its drive class water transport, road transport and air transport vehicles. Make suitable data variables and member functions. When you create an object must be count and display total no of object created also create every class objects and access member through the member functions.
1
Expert's answer
2021-09-24T18:57:46-0400
#include <iostream>
using namespace std;


class vehicle {
    int a;
   public:
      static int count_obj;
      vehicle(int x) {
          a=x;
         count_obj++;
      }
      double disp() {
         cout<<"\n"<<a;
      }
};
class water_transport:public vehicle {
    int a;
   public:
      water_transport(int x) {
          a=x;
          count_obj++;
      }
      double disp() {
         cout<<"\n"<<a;
      }
};
class road_transport {
    int a;
   public:
      road_transport(int x) {
          a=x;
         count_obj++;
      }
      double disp() {
         cout<<"\n"<<a;
      }
};
class air_transport {
    int a;
   public:
      air_transport(int x) {
          a=x;
         count_obj++;
      }
      double disp() {
         cout<<"\n"<<a;
      }
};
int vehicle::count_obj = 0;


int main(void) {
   vehicle v(7);
   v.disp();
   water_transport w(13);
   w.disp();
   road_transport r(5);
   r.disp();
   air_transport a(5);
   a.disp();
   cout << "Total objects: " << vehicle::count_obj << endl;


   return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS