#include <iostream>
using namespace std;

class vehicle
{
   public:
   string noofvehicle;
   string make;
   string model;

    vehicle() 
    {
        cout<<"I am the constructor of the vehicle "<<endl;
    }
    string tostring()
    {
      return make + "->" + model;
    }

     ~vehicle() 
    {
        cout<<"I am the destructor of the vehicle "<<endl;
    }
};

class car : public vehicle
{
    public:
     bool sunroof;
     int airbags;
    int enginecapacity;
     int topspeed;

car()
{
    cout<<"I am the constructor of the car "<<endl;
}

~car()
{
    cout<<"I am the destructor of the car "<<endl;
}

};


class truck : public vehicle
{
    public:
    bool covered;
    int volume;
    int weightcapacity;
    int currentweight;

truck()
{
    cout<<"I am the constructor of the truck "<<endl;
}

~truck()
{
    cout<<"I am the destructor of the truck "<<endl;
}
};


class bus : public vehicle
{
    public:
    bool AC;
    float rating;
    int noofseat;
    int currentseated;

bus()
{
   cout<<"I am the constructor of the bus "<<endl; 
}

~bus()
{
    cout<<"I am the destructor of the bus "<<endl;
}

};


int main() {
    //bus b;
    //car *c = new car;

    vehicle *ptr1 =  new car; // this is run time polymorphism, late binding, cz at the run time we get to know which address is gonna store on that vehicle class
    vehicle *ptr2 =  new bus;
    vehicle *ptr3 =  new truck;

    delete ptr1; // As the car pointer type is vehicle so the vehicle destructor is called not car
    delete ptr2;
    delete ptr3;
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: