Hybrid inheritance is a
combination of two or more types of inheritance. In some applications user may
need to combine the features available in multilevel inheritance, hierarchical
inheritance and multiple inheritance.
Illustrates the implementation of hybrid inheritance.
#include<iostream>
using namespace std;
class student
{
private:
char name[20];
char roll[8];
protected:
int age;
public:
void getstudent()
{
cout<<"Name:";
cin>>name;
cout<<"Roll:";
cin>>roll;
cout<<"Age";
cin>>age;
}
void showstudent()
{
cout<<endl<<"Name:"<<name<<endl<<"Roll:"<<roll<<endl;
cout<<"Age:"<<age<<endl;
}
};
class academic:public student
{
private:
int rank;
public:
void inputdata()
{
getstudent();
cout<<"Rank:";
cin>>rank;
}
void outputdata()
{
showstudent();
cout<<"Rank:"<<rank;
}
};
class sports
{
private:
int score;
public:
void getscore()
{
cout<<"Score:";
cin>>score;
}
void putscore()
{
cout<<"score:"<<score;
}
};
class final:public academic,public sports
{
private:
char bloodgp[4];
public:
void fininputdata()
{
coiut<<"Blood Group:";
cin>>bloodgp;
}
void finoutputdata()
{
cout<<endl<<"Blood Group:"<<bloodgp<<endl;
}
};
int main()
{
final m;
cout<<"Enter student Deatails:"<<"\n;
m.inputdata();
m.getscore();
m.fininputdata();
cout<<"Student Details:"<<"\n";
m.outputdata();
m.putscore();
m.finoutputdata();
}
OUTPUT:
Enter student Details:
Name: Stroustrup
Roll:11
Age:18
Rank:10
Score:55
Blood Group:A+
Student Details:
Name: Stroustrup
Roll:11
Age:18
Rank:10
Score:55
Blood Group:A+
ReplyDeleteVery informative article.Thank you author for posting this kind of article .
http://www.wikitechy.com/view-article/hybrid-inheritance-program-in-cpp-with-example-and-explanation
Both are really good,
Cheers,
Venkat