#include <iostream>
using namespace std;
class A
{
public:
int x, y;
void getdata()
{
cout << "\nEnter value of x and y:\n";
cin >> x >> y;
}
};
class B : public A
{
public:
void product()
{
cout << "\nProduct= " << x * y;
}
};
class C : public A
{
public:
void sum()
{
cout << "\nSum= " << x + y;
}
};
int main()
{
B obj1;
C obj2;
obj1.getdata();
obj1.product();
obj2.getdata();
obj2.sum();
return 0;
}
Note: Need to be arranged in compiler after copied
OutPut:
Enter value of x and y:
10 20
Product= 200
Enter value of x and y:
10 30
Sum= 40
10 20
Product= 200
Enter value of x and y:
10 30
Sum= 40