Wednesday, 14 August 2013

Hybrid Inheritance :)

#include<iostream.h>
#include<conio.h>
class parent
{
    protected:
        char f_name[20],m_name[20];
    public:
        void getdata()
        {
            cout<<"\n Enter Father Name: ";
            cin>>f_name;
            cout<<"\n Enter Mother Name: ";
            cin>>m_name;
        }
};
class child1:public parent
{
    protected:
        char ch_name1[20];
    public:
        void getdata()
        {
            parent::getdata();
            cout<<"\n Enter First Childs' Name: ";
            cin>>ch_name1;
        }
};
class child2
{
    protected:
        char ch_name2[20];
        char f1_name[20],m1_name[20];
    public:
        void getdata()
        {
            cout<<"\n Enter Father Name: ";
            cin>>f1_name;
            cout<<"\n Enter Mother Name: ";
            cin>>m1_name;
            cout<<"\n Enter Second Child Name: ";
            cin>>ch_name2;
        }
};
class son:public child1,public child2
{
    protected:
        char son_name[20];
    public:
        void getdata()
        {
            child1::getdata();
            child2::getdata();
            cout<<"\n Enter The Son's Name: ";
            cin>>son_name;
        }
        void display()
        {
            cout<<"\n Father's Name: "<<f_name;
            cout<<"\n Mother's Name: "<<m_name;
            cout<<"\n Child1's Name:  "<<ch_name1;
            cout<<"\n Father1's Name: "<<f1_name;
            cout<<"\n Mother1's Name: "<<m1_name;
            cout<<"\n Child2's Name: "<<ch_name2;
            cout<<"\n Son's Name:  "<<son_name;
        }
};
void main()
{
    clrscr();
    son m;
    m.getdata();
    m.display();
    getch();
}

Here Is The Output :)


No comments:

Post a Comment