-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut28b.cpp
More file actions
53 lines (47 loc) · 835 Bytes
/
tut28b.cpp
File metadata and controls
53 lines (47 loc) · 835 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
#include<iostream>
using namespace std;
class num2;
class num1
{
int a ;
friend void exchange(num1 &x,num2 &y);
public:
void setdata(int val1){
a = val1;
}
void printdata(void){
cout<<a<<endl;
}
};
class num2
{
int b ;
friend void exchange(num1 &x,num2 &y);
public:
void setdata(int val2){
b = val2;
}
void printdata(void){
cout<<b<<endl;
}
};
void exchange (num1 &x,num2 &y){
int temp = x.a;
x.a = y.b;
y.b = temp;
}
int main()
{
num1 c1;
c1.setdata(34);
c1.printdata();
num2 c2;
c2.setdata(91);
c2.printdata();
exchange (c1,c2);
cout<<"The number after swapping of a is : "<<endl;
c1.printdata();
cout<<"The number after swapping of b is :"<<endl;
c2.printdata();
return 0;
}