Sunday, 1 February 2015

Hybrid Inheritance in C++

Structure of the Problem Requirements

Hybrid inheritance is combination of two or more inheritances such as single,multiple,multilevel or Hierarchical inheritances. Here is the complete example of this inheritance.

Source Code

#include <iostream> 
using namespace std;
class score
{
protected:
int cms;
public:

void set_cms(int a)
{
cms = a;
}
void display_cms()
{
cout<<"CSM : "<<cms<<endl;
}
};
class Subject : public score
{
protected:
int subject1;
int subject2;
public:
void set_marks(int a,int b)
{
subject1 = a;
subject2 = b;
}
void marks(void)
{
cout << "\n Subject 1 : " << subject1 << "";
cout << "\n Subject 2 : " << subject2 << "";
}
};
class extra
{
protected:
float ext;
public:
void get_extra(float f)
{
ext=f;
}
void get_extra()
{
cout << "\n Extra Marks : " << ext << "";
}
};
class hybrid : public Subject, public extra{
protected:
float total;
public:
void display(void)
{
total = subject1+subject2+ext;
display_cms();
marks();
get_extra();
cout << "\n Total Score : "<< total;
}
};
int main()
{
hybrid hyb;
cout<<"\n\n\t ***** HYBIRD INHERITANCE ********\n\n";
hyb.set_cms(8651);
hyb.set_marks(30,30);
hyb.get_extra(35.35);
hyb.display();
return 0;
}

Output of the Program


Share it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment