/
Final 2019 4th Question.cpp
81 lines (55 loc) · 1.17 KB
/
Final 2019 4th Question.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
76
77
78
79
80
81
#include <iostream>
using namespace std;
struct v1 {
double x, y, z;
void set(double a, double b, double c) {
x = a;
y = b;
z = c;
};
void show() {
cout << "X= " << x << " Y= " << y << " Z= " << z << endl;
};
v1(double a, double b, double c) {
x = a;
y = b;
z = c;
};
v1() {
x = 3;
y = 5;
z = 7;
};
};
template <class X> void swapargs(X &a, X &b) {
X temp;
temp = a;
a = b;
b = temp;
}
void swapargs(double &a, double &b) {
cout << "this is inside swapargs(double, double)" << endl;
}
int main() {
v1 xx(1, 3, 5), yy(2, 4, 6), a;
int x, y;
double c, d;
x = 8;
y = 10;
c = 12;
d = 14;
cout << "Original x = " << x << ", y=" << y << endl;
swapargs(x, y);
cout << "swapped x = " << x << ", y=" << y << endl;
cout << "Original c = " << c << ", d=" << d << endl;
swapargs(c, d);
cout << "swapped c = " << c << ", d=" << d << endl;
xx.set(5, 10, 15);
cout << "Original xx: "; xx.show();
cout << "Original yy: "; yy.show();
swapargs(xx, yy);
cout << "swapped xx: "; xx.show();
cout << "swapped yy: "; yy.show();
system("pause>null");
return 0;
}