class a class vehicle with erg_no and cost as data members and define virtual functions start(),stop() show(). Write a complete program having derived classes such as heavy, Lightweight vehicle etc.
#include<bits/stdc++.h>
using namespace std;
class Vehicle
{
long int erg_no;
float cost;
public:
virtual void start()
{
}
virtual void stop()
{
}
virtual void show()
{
}
};
class Heavy : public Vehicle
{
public:
void start()
{
cout<<"\nStart function of Heavy ";
}
void stop()
{
cout<<"\nStop function of Heavy ";
}
void show()
{
cout<<"\nShow function of Heavy ";
}
};
class Lightweight : public Vehicle
{
public:
void start()
{
cout<<"\nStart function of Lightweight ";
}
void stop()
{
cout<<"\nStop function of Lightweight ";
}
void show()
{
cout<<"\nShow function of Lightweight ";
}
};
int main()
{
Vehicle* v1;
Heavy h1;
v1 = &h1;
Lightweight l1;
Vehicle* v2;
v2 = &l1;
v1->show();
v1->stop();
v1->start();
v2->show();
v2->stop();
v2->start();
}
Comments
Leave a comment