-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathb42.cpp
75 lines (44 loc) · 980 Bytes
/
b42.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<iostream>
using namespace std; // PROGRAM TO SWAP VALUES USING FRIEND FUNCTIONS
class c2; // CLASS DECLARATION
class c1{
int value1;
public:
void indata(int a ){
value1 =a;
}
void display(){
cout<<value1<<endl;
}
friend void exchange(c1 &, c2 &); // C1 KA ADDRESS AND C2 KA ADDRESS
};
class c2{
int value2;
public:
void indata(int a){
value2 =a;
}
void dislapy(){
cout<<value2<<endl;
}
friend void exchange(c1 &, c2 &);
};
void exchange(c1 & x, c2 &y){
int temp=x.value1;
x.value1=y.value2;
y.value2=temp;
}
int main(){
c1 yash;
c2 harry;
yash.indata(100);
harry.indata(200);
cout<<"the values before swapping the values are "<<endl;
yash.display();
harry.dislapy();
cout<<"the values after exchange are "<<endl;
exchange(yash,harry);
yash.display();
harry.dislapy();
return 0;
}