-
Notifications
You must be signed in to change notification settings - Fork 0
/
NCP7.BAK
74 lines (62 loc) · 923 Bytes
/
NCP7.BAK
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
// wirte a cpp program to swap the vale of private data member from 2 diffrent classes
#include<iostream.h>
#include<conio.h>
class two;
class one
{
int a;
public:
one(int x)
{
a=x;
}
void disp()
{
cout<<a;
}
friend void swap(one &,two &);
};
class two
{
int b;
public:
two(int y)
{
b=y;
}
void disp()
{
cout<<b;
}
friend void swap(one &,two &)
};
void swap(one &o1,two &o2)
{
int temp=0;
temp=o1.a;
o1.a=o2.b;
o2.b=temp;
cout<<"\n1:"<<o1.a;
cout<<"\n2:"<<o2.b;
}
void main()
{
int a,b;
clrscr();
cout<<"enter the number 1:";
cin>>a;
one o1(a);
cout<<"enter the number 2:";
cin>>b;
two o2(b);
cout<<"before swapping:";
cout<<"\n1 :";o1.disp();
cout<<"\n2 :";o2.disp();
cout<<"\n after swapping :";
swap(o1,o2);
cout<<"\n after swapping:";
cout<<"\n1:";o1.disp();
cout<<"\n2:";o2.disp();
getch();
} x
xxx