1 Answers
Code:
#include <iostream>
using namespace std;
class integer
{
int *x;
int *y;
int *z;
public:
integer(int z1)
{
z = new int;
*z = z1;
}
integer(int x1, int y1)
{
x = new int;
*x = x1;
y = new int;
*y = y1;
}
void add()
{
int sum;
sum = *x + *y;
cout<<“Sum of 2 nos”<<“\t”<<sum;
}
void sum()
{
cout<<“Z is”<<“\t”<<*z;
}
};
int main()
{
integer j(10, 20);
integer k(40);
k.sum();
j.add();
return 0;
}
Output:
Z is : 40
Sum of 2 nos : 30