1.
class Car:public Vehicle
{
public:
Car(string no,int guest,int weight):Vehicle(no)
{
m_no=no;
m_guest=guest;
m_weight=weight;
}
virtual int fee()
{
return (m_guest*8+m_weight*2);
}
private:
string m_no;
int m_guest,m_weight;
};
class Truck:public Vehicle
{
public:
Truck(string no,int weight):Vehicle(no)
{
m_no=no;
m_weight=weight;
}
virtual int fee()
{
return (m_weight*5);
}
private:
string m_no;
int m_weight;
};
class Bus:public Vehicle
{
public:
Bus(string no,int guest):Vehicle(no)
{
m_no=no;
m_guest=guest;
}
virtual int fee()
{
return (m_guest*3);
}
private:string m_no;
int m_guest;
};
2.
class Person{
public:
virtual void bellRing(){}
virtual ~Person(){}
};
class Student:public Person{
public:
void bellRing(){
cout<<"I am a student learning in classroom."<<endl;
}
~Student(){
cout<<"A student object destroyed."<<endl;
}
};
class Teacher:public Person{
public:
void bellRing(){
cout<<"I am a teacher teaching in classroom."<<endl;
}
~Teacher(){
cout<<"A teacher object destroyed."<<endl;
}
};
class Principal:public Person{
public:
void bellRing(){
cout<<"I am the principal inspecting in campus."<<endl;
}
~Principal(){
cout<<"A principal object destroyed."<<endl;
}
};