Screen Capture of this program |
#include <iostream>
#include<conio.h>
using namespace std;
class Y;
class X
{
int a;
public:
void Setvalues()
{
a=10;
}
friend void swap(X&,Y&);
void display();
};
void X:: display()
{
cout<<"First Number="<<a<<endl;
}
class Y
{
int b;
public:
void Setvalues()
{
b=20;
}
friend void swap (X&,Y&);
void display();
};
void Y:: display()
{
cout<<"Second Number="<<b<<endl;
}
void swap (X&x,Y&y)
{
int temp = x.a;
x.a =y.b;
y.b= temp;
}
int main()
{
X xobj;
Y yobj;
xobj.Setvalues();
yobj.Setvalues();
cout<<"Before Swaping"<<endl;
xobj.display();
yobj.display();
cout<<"*********************"<<endl;
cout<<"*********************"<<endl;
cout<<"After Swaping"<<endl;
swap(xobj,yobj);
xobj.display();
yobj.display();
cout<<"!!!!!Thank you!!!!!"<<endl;
getch();
}
0 comments:
Post a Comment