Create a car class that includes name as its data member. Create another class Toyota that is derived from class and includes his model # (int type) and color (string type) as his data member. Write appropriate constructors (multiple constructors) and display method to create and display objects of Toyota class.
#include<iostream>
#include<conio.h>
#include<string.h>
using namespace std;
class car {
protected:
string name;
public:
car(){
name=" ";
}
};
class toyota : public car {
private:
string color;
int model;
public:
toyota(){
name="NULL";
color="NULL";
model=0;
}
toyota(int){
name=" ";
color=" ";
model=0;
}
void display(){
name="Toyota Corolla";
color="Grey";
model=2017;
cout<<"Name of car:"<<name<<endl<<"Model of Car:"<<model<<endl<<"Colour of the car:"<<color;
}
};
int main(){
toyota t1;
t1.display();
getch();
return 0;
}
See Also: User Defined Exception Class in C++

