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.
Answers
Answer:
Create two classes named Mammals and MarineAnimals. Create another class named BlueWhale which inherits both the above classes. Now, create a function in each of these classes which prints "I am mammal", "I am a marine animal" and "I belong to both the categories: Mammals as well as Marine Animals" respectively. Now, create an object for each of the above class and try calling
1 - function of Mammals by the object of Mammal
2 - function of MarineAnimal by the object of MarineAnimal
3 - function of BlueWhale by the object of BlueWhale
4 - function of each of its parent by the object of BlueWhale
Answer:
Answer code in c++
Explanation:
#include <iostream>
#include <string>
using namespace std;
class veichle
{
protected:
int mileage;
int price;
public:
void getveichle(int x, int y)
{
mileage = x;
price = y;
}
};
class car : public veichle
{
protected:
int ownership_cost;
int warranty;
int seating_capacity;
public:
string fuel_type;
void getcar(int x, int y, int z)
{
ownership_cost = x;
warranty = y;
seating_capacity = z;
}
};
class bike : public veichle
{
protected:
int number_of_cylinder;
int number_of_gears;
string cooling_type;
string wheel_type;
int fuel_tank_size;
string fuel_type;
public:
void getbike(int x, int y, string z, string u, int v, string w)
{
number_of_cylinder = x;
number_of_gears = y;
cooling_type = z;
wheel_type = u;
fuel_tank_size = v;
fuel_type = w;
}
};
class Audi : public car
{
protected:
string audimodel_type;
public:
void getaudi(string s)
{
audimodel_type = s;
}
};
class Ford : public car
{
protected:
string fordmodel_type;
public:
void getford(string s)
{
fordmodel_type = s;
}
};
class bajaj : public bike
{
protected:
string bajajmodel_type;
public:
void getbajaj(string s)
{
bajajmodel_type = s;
}
};
class tvs : public bike
{
protected:
string tvsmodel_type;
public:
void gettvs(string s)
{
tvsmodel_type = s;
}
void getdata()
{
cout << "Price of the bike is " << price << endl;
cout << "Mileage of the bike is " << mileage << endl;
cout << "Number of cylinders in the bike is " << number_of_cylinder << endl;
cout << "Number of Gears in the bike is " << number_of_gears << endl;
cout << "Cooling type in the bike is " << cooling_type << endl;
cout << "Wheel type in the bike is " << wheel_type << endl;
cout << "Fuel tank size in the bike is " << fuel_tank_size << " liters. " << endl;
cout << "Fuel type in the bike is " << fuel_type << endl;
cout << "Model type of the bike is " << tvsmodel_type << endl
<< endl;
}
};
int main()
{
tvs t;
t.gettvs("Sport");
t.getbike(6, 4, "oil", "Eurogrip", 12, "Diseal");
t.getveichle(23, 120000);
t.getdata();
return 0;
}