forked from Pr8862/pr_hacktoberfest-2k22
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswap.cpp
53 lines (52 loc) · 1008 Bytes
/
swap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include<iostream>
using namespace std;
class class2;
class class1
{
int a;
public:
void input(int m)
{
a=m;
}
void display()
{
cout<<"value 1 is"<<a;
}
friend void swap(class1 &x, class2 &y);
};
class class2
{
int b;
public:
void input(int p)
{
b=p;
}
void display()
{
cout<<"value 2 is"<<b;
}
friend void swap(class1 &x, class2 &y);
};
void swap (class1 &x, class2 &y)
{
int temp = x.a;
x.a = y.b;
y.b = temp;
}
int main()
{
class1 c1;
class2 c2;
c1.input(10);
c2.input(20);
cout<<"\nbefore swapping\n";
c1.display();
c2.display();
swap(c1,c2);
cout<<"\nafter swapping\n";
c1.display();
c2.display();
return 0;
}