#include <iostream>
using namespace std;
class A
{
public :
int x;
void getx ()
{
cout <<"Enter the value of x: ";
cin >>x;
cout <<x<<endl;
}
};
class B :public virtual A
{
public :
int y;
void gety()
{
cout <<"Enter the value of y: ";
cin >>y;
cout <<y<<endl;
}
void sum ()
{
cout <<"sum x+y= "<<x+y<<endl;
}
};
class C :public virtual A
{
public :
int z;
void getz()
{
cout <<"Enter the value of z : ";
cin >>z;
cout <<z<<endl;
}
void sub ()
{
cout <<"sub x-z= "<<x-z<<endl;
}
};
class D :public B, public C
{
public :
void add1 ()
{
cout <<"sum y+z= "<<y+z<<endl;
}
};
int main() {
D obj;
obj. getx ();
obj. gety ();
obj. getz();
obj. sum ();
obj. sub();
obj. add1();
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: