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.
#include <iostream>
#include <string>
using namespace std;
class Vehicle{
private:
float mileage;
float price;
public:
Vehicle(){}
Vehicle(float mileage,float price){
this->mileage=mileage;
this->price=price;
}
float getMileage(){
return this->mileage;
}
float getPrice(){
return this->price;
}
virtual void display(){
cout<<"Mileage: "<<mileage<<"\n";
cout<<"Price: "<<price<<"\n";
}
};
class Car:public Vehicle{
private:
float ownershipCost;
int warranty;
int seatingCapacity;
string fuelType;
public:
Car(){}
Car(float mileage,float price,float ownershipCost,int warranty,int seatingCapacity,string fuelType):Vehicle(mileage,price){
this->ownershipCost=ownershipCost;
this->warranty=warranty;
this->seatingCapacity=seatingCapacity;
this->fuelType=fuelType;
}
float getOwnershipCost(){
return this->ownershipCost;
}
int getWarranty(){
return this->warranty;
}
int getSeatingCapacity(){
return this->seatingCapacity;
}
string getFuelType(){
return this->fuelType;
}
void display(){
cout<<"Car\n";
Vehicle::display();
cout<<"Ownership Cost: "<<ownershipCost<<"\n";
cout<<"Warranty: "<<warranty<<"\n";
cout<<"Seating capacity: "<<seatingCapacity<<"\n";
cout<<"Fuel type: "<<fuelType<<"\n";
}
};
class Bike:public Vehicle{
private:
int numberCylinders;
int numberGears;
string coolingType;
public:
Bike(){}
Bike(float mileage,float price,int numberCylinders,int numberGears,string coolingType):Vehicle(mileage,price){
this->numberCylinders=numberCylinders;
this->numberGears=numberGears;
this->coolingType=coolingType;
}
int getNumberCylinders(){
return this->numberCylinders;
}
int getNumberGears(){
return this->numberGears;
}
string getCoolingType(){
return this->coolingType;
}
void display(){
cout<<"Bike\n";
Vehicle::display();
cout<<"Number cylinders: "<<numberCylinders<<"\n";
cout<<"Number gears: "<<numberGears<<"\n";
cout<<"Cooling type: "<<coolingType<<"\n";
}
};
class Audi:public Car{
private:
string modelType;
public:
Audi(float mileage,float price,float ownershipCost,int warranty,int seatingCapacity,string fuelType):
Car(mileage,price,ownershipCost,warranty,seatingCapacity,fuelType){
this->modelType="Audi";
}
void display(){
Car::display();
cout<<"Model type: "<<modelType<<"\n";
}
};
class Ford:public Car{
private:
string modelType;
public:
Ford(float mileage,float price,float ownershipCost,int warranty,int seatingCapacity,string fuelType):
Car(mileage,price,ownershipCost,warranty,seatingCapacity,fuelType){
this->modelType="Ford";
}
void display(){
Car::display();
cout<<"Model type: "<<modelType<<"\n";
}
};
class Bajaj:public Bike{
private:
string makeType;
public:
Bajaj(float mileage,float price,int numberCylinders,int numberGears,string coolingType):
Bike(mileage,price,numberCylinders,numberGears,coolingType){
this->makeType="Bajaj";
}
void display(){
Bike::display();
cout<<"The make-type: "<<makeType<<"\n";
}
};
class TVS:public Bike{
private:
string makeType;
public:
TVS(float mileage,float price,int numberCylinders,int numberGears,string coolingType):
Bike(mileage,price,numberCylinders,numberGears,coolingType){
this->makeType="TVS";
}
void display(){
Bike::display();
cout<<"The make-type: "<<makeType<<"\n";
}
};
int main(){
Audi ca(50000,26500,89000,15,1,"diesel");
Audi cf(15000,16500,25000,2,2,"petrol");
Bajaj bb(15000,188000,2,2,"diesel");
TVS bt(16000,12000,1,5,"liquid");
ca.display();
cout<<"\n";
cf.display();
cout<<"\n";
bb.display();
cout<<"\n";
bt.display();
return 0;
}
Comments
Leave a comment