Answer to Question #254124 in Databases | SQL | Oracle | MS Access for Mari

Question #254124
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), wheel type(alloys or spokes) and fuel tank size(in inches)
Make another two subclasses Audi and Ford of Car, each having a data member to store the model
type. Next, make two subclasses Bajaj and TVS, each having a data member to store the make-type.
Now, store and print the information of an Audi and a Ford car (i.e. model type, ownership cost,
warranty, seating capacity, fuel type, mileage and price.) Do the same for a Bajaj and a TVS bike.
1
Expert's answer
2021-10-20T16:37:18-0400
#include <iostream>
using namespace std;




class Vehicle {
    public:
        
        float mileage;
        float price;
        
        
        Vehicle(float m, float p) {
            mileage = m;
            price = p;
        }
};


class Car: public Vehicle {
    public:
        
        float ownership_cost;
        int warranty;
        int seating_capacity;
        string fuel_type;
        
        
        Car(float m, float p, float oc, int w, int sc, string ft) : Vehicle(m,p)  {
            ownership_cost = oc;
            warranty = w;
            seating_capacity = sc;
            fuel_type = ft;
        }
};




class Bike: public Vehicle {
    public:
        
        int num_of_cylinders;
        int num_of_gears;
        string cooling_type;
        string wheel_type;
        int fuel_tank_size;
        
        
        Bike(float m, float p, int noc, int nog, string ct, string wt, int s) :  Vehicle(m,p) {
            num_of_cylinders = noc;
            num_of_gears = nog;
            cooling_type = ct;
            wheel_type = wt;
            fuel_tank_size = s;
        }
};




class Audi: public Car {
    public:
        
        string model_type;
        
       
        Audi(float m, float p, float oc, int w, int sc, string ft, string mt) 
         :  Car(m, p, oc, w, sc, ft) {
            model_type= mt;
        }


        void display(){
            cout<<"\nModel type : "<<model_type;
            cout<<"\nOwnersip cost : "<<ownership_cost;
            cout<<"\nWarranty : "<<warranty;
            cout<<"\nSeating capacity : "<<seating_capacity;
            cout<<"\nFuel type : "<<fuel_type;
            cout<<"\nMileage : "<<mileage;
            cout<<"\nPrice : "<<price;
        }
};






class Ford: public Car {
    public:
        string model_type;
        
        
        Ford(float m, float p, float oc, int w, int sc, string ft, string mt) 
        : Car(m, p, oc, w, sc, ft) {
            model_type= mt;
        }


        void display(){
            cout<<"\nModel type : "<<model_type;
            cout<<"\nOwnersip cost : "<<ownership_cost;
            cout<<"\nWarranty : "<<warranty;
            cout<<"\nSeating capacity : "<<seating_capacity;
            cout<<"\nFuel type : "<<fuel_type;
            cout<<"\nMileage : "<<mileage;
            cout<<"\nPrice : "<<price;
        }
};




class Bajaj: public Bike {
    public:
        string make_type;
        
    
    Bajaj(float m, float p, int noc, int nog, string ct, string wt, int s, string mt)
       : Bike(m,p,noc,nog,ct,wt,s) {
             make_type = mt;
        }


        void display(){
            cout<<"\nMake type : "<<make_type;
            cout<<"\nMileage : "<<mileage;
            cout<<"\nPrice : "<<price;
            cout<<"\nno. of cyclinders : "<<num_of_cylinders;
            cout<<"\nNo. of gears  : "<<num_of_gears;
            cout<<"\nCooling type : "<<cooling_type;
            cout<<"\nWheel type : "<<wheel_type;
            cout<<"\nTank size  : "<<fuel_tank_size;
        }        
};




class TVS: public Bike {
    public:
        string make_type;
        
        TVS(float m, float p, int noc, int nog, string ct, string wt, int s, string mt)
        : Bike(m,p,noc,nog,ct,wt,s){
             make_type = mt;
        }


        void display(){
            cout<<"\nMake type : "<<make_type;
            cout<<"\nMileage : "<<mileage;
            cout<<"\nPrice : "<<price;
            cout<<"\nno. of cyclinders : "<<num_of_cylinders;
            cout<<"\nNo. of gears  : "<<num_of_gears;
            cout<<"\nCooling type : "<<cooling_type;
            cout<<"\nWheel type : "<<wheel_type;
            cout<<"\nTank size  : "<<fuel_tank_size;
        }    
};




int main()
{
      
      Ford f(25,670,790,3,5, "Diesel", "EcoSport");
     
      Audi a(20,500,600,5,7, "Petrol", "Q2");
      
      Bajaj b(15,200,3,4,"Air","Alloys",20.5,"Honda");
      
      TVS t(12,250,4,3,"Liquid","Spokes",10.5,"Activa");
      
      
      f.display();
      
      a.display();
      
      b.display();
     
      t.display();


    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
New on Blog
APPROVED BY CLIENTS