A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Write a program perform operations in method through inheritance.

#include<iostream>

using namespace std;
class A
{
  public:
        int a,b;
        void f1()
        {
          cout<<"Enter the nos."<<endl;
          cin>>a>>b;
        }
};

class B:public A
{
  public:
        int sum;
        void add()
        {
         sum = a+b;
         cout<<"The sum is "<<sum<<endl;
        }
};

class C: public A
{
  public:
        void subtract()
        {
         int diff;
         diff = a-b;
         cout<<"the difference is "<<diff<<endl;
        }
};

class D: public A
{
        public:
             void multiply()
             {
              int product;
               product=a*b;
               cout<<"The product is"<<product<<endl;
             }
};

int main()
{
        B obj1;
        obj1.f1();
        obj1.add();
        C obj2;
        obj2.f1();
        obj2.subtract();
        D obj;
        obj.f1();
        obj.multiply();

}

LEARN TUTORIALS

.

.