include iostream using namespace std union point int decimal double _f

 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
#include <iostream>
using namespace std;
union point {
int decimal;
double _float;
void init() {
cin >> _float;
if ((int) _float == _float) {
decimal = (int) _float;
}
}
double get() {
if (_float != NULL) return _float;
return decimal;
}
};
struct points {
point x;
point y;
point z;
};
int main() {
struct points point;
cout << "Enter value of x: ";
point.x.init();
cout << "Enter value of y: ";
point.y.init();
cout << "Enter value of z: ";
point.z.init();
cout << "x = " << point.x.get() << endl;
cout << "y = " << point.y.get() << endl;
cout << "z = " << point.z.get() << endl;
}