Subscribe Us

Program on Multiple Inheritance

Multiple Inheritance


#include <iostream>

using namespace std;
class A
{
    protected:
    int a;
    public:
        void get_a()
        {
            cin>>a;
        }
};
class B
{
    protected:
    int b;
    public:
        void get_b()
        {
            cin>>b;
        }
};
class C :public A, public B
{
    protected:
    int c;
    public:
        void display()
        {
            cout<<"\nThe value of A's Data member: "<<a;
            cout<<"\nThe value of B's Data member: "<<b;
            cout<<"\nThe Product: ";
            c=a*b;
            cout<<c;
        }
};

int main()
{
   C ob;
   ob.get_a();
   ob.get_b();
   ob.display();
}

Scope Resolution Operator:

#include <iostream>

using namespace std;
class A
{
    protected:
    int a;
    public:
        void get_a()
        {
            cin>>a;
        }
        void show()
        {
            cout<<"\nThe value of A's Data member: "<<a;
        }
};
class B
{
    protected:
    int b;
    public:
        void get_b()
        {
            cin>>b;
        }
        void show()
        {
            cout<<"\nThe value of B's Data member: "<<b;
        }
};
class C :public A, public B
{
    protected:
    int c;
    public:
        void display()
        {
            A::show();
            B::show();
            cout<<"\nThe Product: ";
            c=a*b;
            cout<<c;
        }
};

int main()
{
   C ob;
   ob.get_a();
   ob.get_b();
   ob.display();
}

Heircharcal inheritnace:

#include <iostream>

using namespace std;
class A
{
    protected:
    int x,y;
    public:
        void get_data()
        {
            cout<<"\nEnter the value of X and Y: ";
            cin>>x>>y;
        }
};
class B :public A
{
    protected:
    int c;
    public:
        void product()
        {
            c=x*y;
            cout<<"\nThe product resut is :"<<c;
        }
};
class C :public A
{
    protected:
    int s;
    public:
        void sum()
        {
            s=x+y;
            cout<<"\nThe sum result is :"<<s;
        }
};

int main()
{
   B ob;
   ob.get_data();
   ob.product();
   C ob1;
   ob1.get_data();
   ob1.sum();

}


Post a Comment

0 Comments