C++ program to illustrate Multiple Inheritance



//parent classes are IntegerNumber and FloatNumber
//child class is Total which adds those integer and float

#include <iostream>
using namespace std;
class IntegerNumber
{
    protected:
        int i;
    public:
        void getInt()
        {
            cout<<"Enter integer: ";
            cin>>i;
        }
};

class FloatNumber
{
    protected:
        float f;
    public:
        void getFloat()
        {
            cout<<"Enter float: ";
            cin>>f;
        }
};

class Total:public IntegerNumber,public FloatNumber
{
    protected:
        float t;
    public:
        void display()
        {
            t=i+f;
            cout<<t;
        }
};

int main()
{
    Total t1;
    t1.getInt();
    t1.getFloat();
    t1.display();
    return 0;
}

No comments:

Post a Comment