WAP of swap the two number.
#include<iostream.h>
#include<conio.h>
class abc;
class xyz
{
int a;
public:
void getdata()
{
cout<<”enter the value of a”;
cin>>a;
}
friend void compute (xyz,abc);
};
class abc
{
int b;
public:
void getdata()
{
cout<<”enter the value of b”;
cin>>b;
}
friend void compute(xyz,abc);
};
void compute (xyz m,abc n)
{
m.a=m.a-n.b;
n.b=m.a+n.b;
m.a=m.a-n.b;
cout<<”n After Swapping “;
cout<<”n Value of a : “<<m.a<<”n Value of b : “<<n.b;
}
main()
{
abc a2;
xyz a1;
clrscr();
a1.getdata();
a2.getdata();
compute(a1,a2);
getch();
}
Output
enter the value of a 15
enter the value of b 20
After Swapping
Value of a : 20
Value of b : 15










Why on earth did you wrap the two integers in two different classes to swap them??? This could really confuse a newbie as far as concepts are concerned. Sometimes, its not about what is doable by a specific way, but you should focus on the “why” part too.
Regards,
Anusha UV Associates