Check this C++ program?

returning objects t.a = x.a + x.a; t.b = y.b + y.b; why is it not adding x and x then y and y. It is simply showing the values of x and y please correct the program #include<iostream> using namespace std; class add { public: int a; int b; public: void getdata(); void disp(); add... show more returning objects

t.a = x.a + x.a;
t.b = y.b + y.b;
why is it not adding x and x
then
y and y.
It is simply showing the values of x and y
please correct the program



#include<iostream>
using namespace std;

class add
{
public:
int a;
int b;

public:
void getdata();
void disp();
add dd(add x, add y);

};



void add :: getdata()
{
cout <<"Enter the value of a ";
cin >>a;
cout <<"Enter the value of b ";
cin >>b;
}


add add :: dd(add x, add y)
{
add t;
t.a = x.a + x.a;
t.b = y.b + y.b;

return t;
}


void add :: disp()
{
cout <<"a = "<< a <<" b = "<< b;
}


int main()
{
add P,Q,R,S,T;
P.getdata();
Q.getdata();
R=P.dd(P,Q);

Q.disp();



}
1 answer 1