Answer to Question #188894 in C++ for akash

Question #188894

We want to store the information of different vehicles. Create a class named Vehicle with two data member named mileage and price. Create its two subclasses *Car with data members to store ownership cost, warranty (by years), seating capacity and fuel type (diesel or petrol). *Bike with data members to store the number of cylinders, number of gears, cooling type (air, liquid or oil)


1
Expert's answer
2021-05-04T02:15:30-0400
#include <iostream>
using namespace std;
class Vehicle{
    protected:
        int mileage, price;
    public:
        Vehicle(int m, int p): mileage(m), price(p){}
};
class Car:public Vehicle{
    int cost, warranty, capacity;
    string fuel;
    public:
        Car(int m, int p, int c, int w, int cap, string f):
            Vehicle(m, p), cost(c), warranty(w), capacity(cap), fuel(f){}
};
class Bike:public Vehicle{
    int cylinders, gears;
    string cooling;
    public:
        Bike(int m, int p, int c, int g, string s):Vehicle(m, p), cylinders(c), gears(g), cooling(s){}
};

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
APPROVED BY CLIENTS