-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask2.cpp
80 lines (77 loc) · 2.5 KB
/
task2.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
#include <iostream>
#include "reading.cpp"
int main(){
reading();
std::cout << "------------------------------------------------\nThe second task:\n";
std::set<Animal*> animal_set;
std::map<std::string, std::set<Animal*>> animal_map;
std::cout << "Enter type of animal(cat,dog,fish):\n";
std::string check = "";
std::cin >> check;
check = ToLower(check);
bool it_check = 1;
if (check != "cat" && check != "dog" && check != "fish")
{
it_check = 0;
}
if (it_check)
{
std::cout << check << ":\n";
for (int i = 0; i < owners.size(); ++i)
{
std::vector<Animal *> animls = owners[i].GetVectorAnimal();
for (Animal *anim : animls)
{
if (Cat *c = dynamic_cast<Cat *>(anim))
{
if (check == "cat")
{
animal_set.insert(anim);
std::pair<std::string, std::set<Animal*>> anm(owners[i].GetOwnerName(), animal_set);
animal_map.insert(anm);
animal_set.clear();
}
}
if (Dog *d = dynamic_cast<Dog *>(anim))
{
if (check == "dog")
{
animal_set.insert(anim);
std::pair<std::string, std::set<Animal*>> anm(owners[i].GetOwnerName(), animal_set);
animal_map.insert(anm);
animal_set.clear();
}
}
if (Fish *c = dynamic_cast<Fish *>(anim))
{
if (check == "fish")
{
animal_set.insert(anim);
std::pair<std::string, std::set<Animal*>> anm(owners[i].GetOwnerName(), animal_set);
animal_map.insert(anm);
animal_set.clear();
}
}
}
animls.clear();
}
for (auto &item : animal_map)
{
std::cout << item.first << " ";
for (auto &it : item.second)
{
std::cout << *it << " ";
}
std::cout << "\n";
}
animal_map.clear();
}
else
{
std::cout << "We don't know this animal(" << check << ")\n";
}
for (Animal *anim : anims) // освобождение памяти
{
delete anim;
}
}