Answer to Question #193695 in C++ for Aditi

Question #193695

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.


1
Expert's answer
2021-05-17T03:35:27-0400
#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();
}

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
New on Blog