#include <iostream>
#include <string>
using namespace std;
// Base class Vehicle
class Vehicle {
protected :
double mileage;
double price;
public :
Vehicle( double m, double p) : mileage( m) , price( p) { }
virtual void display( ) const {
cout << "Mileage: " << mileage << " km/l, Price: $" << price << endl;
}
} ;
// Subclass Car
class Car : public Vehicle {
protected :
double ownershipCost;
int warranty;
int seatingCapacity;
string fuelType;
public :
Car( double m, double p, double oc, int w, int sc, const string& ft)
: Vehicle( m, p) , ownershipCost( oc) , warranty( w) , seatingCapacity( sc) , fuelType( ft) { }
void display( ) const override {
Vehicle:: display ( ) ;
cout << "Ownership Cost: $" << ownershipCost << ", Warranty: " << warranty
<< " years, Seating Capacity: " << seatingCapacity << ", Fuel Type: " << fuelType << endl;
}
} ;
// Subclass Bike
class Bike : public Vehicle {
protected :
int numCylinders;
int numGears;
string coolingType;
string wheelType;
double fuelTankSize;
public :
Bike( double m, double p, int nc, int ng, const string& ct, const string& wt, double fts)
: Vehicle( m, p) , numCylinders( nc) , numGears( ng) , coolingType( ct) , wheelType( wt) , fuelTankSize( fts) { }
void display( ) const override {
Vehicle:: display ( ) ;
cout << "Number of Cylinders: " << numCylinders << ", Number of Gears: " << numGears
<< ", Cooling Type: " << coolingType << ", Wheel Type: " << wheelType
<< ", Fuel Tank Size: " << fuelTankSize << " inches" << endl;
}
} ;
// Subclass Audi of Car
class Audi : public Car {
string modelType;
public :
Audi( double m, double p, double oc, int w, int sc, const string& ft, const string& mt)
: Car( m, p, oc, w, sc, ft) , modelType( mt) { }
void display( ) const override {
Car:: display ( ) ;
cout << "Model Type: " << modelType << endl;
}
} ;
// Subclass Ford of Car
class Ford : public Car {
string modelType;
public :
Ford( double m, double p, double oc, int w, int sc, const string& ft, const string& mt)
: Car( m, p, oc, w, sc, ft) , modelType( mt) { }
void display( ) const override {
Car:: display ( ) ;
cout << "Model Type: " << modelType << endl;
}
} ;
// Subclass Bajaj of Bike
class Bajaj : public Bike {
string makeType;
public :
Bajaj( double m, double p, int nc, int ng, const string& ct, const string& wt, double fts, const string& mt)
: Bike( m, p, nc, ng, ct, wt, fts) , makeType( mt) { }
void display( ) const override {
Bike:: display ( ) ;
cout << "Make Type: " << makeType << endl;
}
} ;
// Subclass TVS of Bike
class TVS : public Bike {
string makeType;
public :
TVS( double m, double p, int nc, int ng, const string& ct, const string& wt, double fts, const string& mt)
: Bike( m, p, nc, ng, ct, wt, fts) , makeType( mt) { }
void display( ) const override {
Bike:: display ( ) ;
cout << "Make Type: " << makeType << endl;
}
} ;
int main( ) {
// Create instances of Audi and Ford
Audi myAudi( 15.0 , 50000 , 2000 , 5 , 5 , "Petrol" , "Audi A4" ) ;
Ford myFord( 12.0 , 30000 , 1500 , 3 , 5 , "Diesel" , "Ford Mustang" ) ;
// Create instances of Bajaj and TVS
Bajaj myBajaj( 50.0 , 1500 , 1 , 5 , "Air" , "Alloys" , 13.0 , "Bajaj Pulsar" ) ;
TVS myTVS( 55.0 , 1200 , 1 , 4 , "Oil" , "Spokes" , 12.5 , "TVS Apache" ) ;
// Display details
cout << "Audi Car Details:" << endl;
myAudi.display ( ) ;
cout << endl;
cout << "Ford Car Details:" << endl;
myFord.display ( ) ;
cout << endl;
cout << "Bajaj Bike Details:" << endl;
myBajaj.display ( ) ;
cout << endl;
cout << "TVS Bike Details:" << endl;
myTVS.display ( ) ;
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCi8vIEJhc2UgY2xhc3MgVmVoaWNsZQpjbGFzcyBWZWhpY2xlIHsKcHJvdGVjdGVkOgogICAgZG91YmxlIG1pbGVhZ2U7CiAgICBkb3VibGUgcHJpY2U7CgpwdWJsaWM6CiAgICBWZWhpY2xlKGRvdWJsZSBtLCBkb3VibGUgcCkgOiBtaWxlYWdlKG0pLCBwcmljZShwKSB7fQoKICAgIHZpcnR1YWwgdm9pZCBkaXNwbGF5KCkgY29uc3QgewogICAgICAgIGNvdXQgPDwgIk1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