-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInteger Data Swapper.cpp
More file actions
80 lines (60 loc) · 949 Bytes
/
Integer Data Swapper.cpp
File metadata and controls
80 lines (60 loc) · 949 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*WAP to swap two integer data of different class using
friend function.*/
#include <iostream>
using namespace std;
class B;
class A
{
int x;
public:
A(int p)
{
x = p;
}
friend void swap(A *i, B *j);
void display()
{
cout << x;
}
};
class B
{
int y;
public:
B(int q)
{
y = q;
}
friend void swap(A *i, B *j);
void display()
{
cout << y;
}
};
void swap(A *i, B *j)
{
i->x = i->x + j->y;
j->y = i->x - j->y;
i->x = i->x - j->y;
}
int main()
{
int m, n;
cout << "Enter the value of the first integer- ";
cin >> m;
cout << "Enter the value of the second integer- ";
cin >> n;
A a(m);
B b(n);
cout << "\nThe initial values of the entered integers are:-";
cout << "\nx = "<<m;
cout << "\ny = "<<n;
swap(&a, &b);
cout << "\n\nThe final values of the integers after swapping are:-";
cout << "\nx = ";
a.display();
cout << "\ny = ";
b.display();
cout << endl;
return 0;
}