Hierarchical Inheritance


The process of deriving more than one class from single base class is known as Hierarchical Inheritance. Thus in Hierarchical Inheritance there is one base class but more then one derived classes

Hierarchical Inheritance
     

#include<iostream.h>
class campus
{
char trustname[20];
char chairman[20];
public:
void inputcm()
{
cout<<"Enter Trust Name:";
cin>>trustname;
cout<<"Enter Chairman Name:";
cin>>chairman;
}
void outputcm()
{
cout<<"Trust Name:"<<trustname<<endl;
cout<<"Chairman:"<<chairman<<endl;
}
};
class diploma: public campus
{
char principal[20];
public:
void inputdip()
{
cout<<"Enter Principal Name:";
cin>>principal;
}
void display()
{
      outputcm();
cout<<"Diploma Principal:"<<principal<<endl;
}
};
class degree:public campus
{
char principal[20];
public:
void inputdeg()
{
cout<<"Enter Principal Name:";
cin>>principal;
}
void display()
{
      outputcm () ;
cout<<"Degree Principal:"<<principal<<endl;
}
};
int main()
{
Diploma D1;
D1.inputcm();
D1.inputdip();
D1.display();
Degree D2;
D2.inputcm();
D2.inputdeg();
D2.Display();
return 0;
}

Download Projects


Download Programs