-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut28b.cpp
More file actions
55 lines (47 loc) · 948 Bytes
/
tut28b.cpp
File metadata and controls
55 lines (47 loc) · 948 Bytes
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
54
55
#include<iostream>
using namespace std;
class c2;
class c1{
int val;
friend void exchange(c1&, c2&);
public:
void intdata(int a){
val = a;
}
void display(void){
cout<<val<<endl;
}
};
class c2{
int val2;
friend void exchange(c1&, c2&);
public:
void intdata(int a){
val2 = a;
}
void display(void){
cout<<val2<<endl;
}
};
/*Trick to swap two numbers a and b
int temp = a;
a = b;
b = temp;
*/
void exchange(c1 &x, c2 &y){
int temp = x.val;
x.val = y.val2;
y.val2 = temp;
}
int main(){
c1 og1;
c2 og2;
og1.intdata(5);
og2.intdata(10);
exchange(og1, og2);
cout<<"The value after swapping og1 occurs like: ";
og1.display();
cout<<"The value after swapping og2 occurs like: ";
og2.display();
return 0;
}