include iostream include string using namespace std union weight int d

 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
#include <iostream>
#include <string>
using namespace std;
union weight {
int decim;
double floating;
void Init() {
cout << "Enter weight: ";
cin >> floating;
if ((int)floating == floating) {
decim = (int)floating;
}
}
double show() {
if (floating != NULL) return floating;
return decim;
}
};
struct foundation {
string name;
string city;
weight w;
};
bool compare(const weight &a, const weight &b) {
if (a.decim == b.decim && a.floating == b.floating) return true;
return false;
}
int main() {
foundation founds[2];
weight toFind;
for (auto &element : founds) {
cout << "Enter name / city" << endl;
cin >> element.name >> element.city;
element.w.Init();
}
for (auto &element : founds) {
cout << element.name << " - " << element.city << " - " << element.w.show() << endl;
}
cout << "Enter the weigth of the structure you want to delete." << endl;
toFind.Init();
for (int i = 0; i < 2; i++) {
if (compare(toFind, founds[i].w)) {
founds[i].name = "\0";
founds[i].city = "\0";
cout << "Structure with weight " << toFind.show() << " has been removed." << endl;
}
}
for (int i = 0; i < 2; i++) {
if (founds[i].name != "\0") {
cout << founds[i].name << " - " << founds[i].city << " - " << founds[i].w.show() << endl;
}
}
system("pause");
return 0;
}