-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask1.cpp
37 lines (34 loc) · 1.12 KB
/
task1.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
#include <iostream>
#include "reading.cpp"
int main()
{
reading();
std::cout << "------------------------------------------------\nThe first task:\n";
std::set<std::string> set_animal;
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))
{ // динамическое приведение типов (dynamic_cast)
set_animal.insert("cat");
}
if (Dog *d = dynamic_cast<Dog *>(anim))
{
set_animal.insert("fish");
}
if (Fish *c = dynamic_cast<Fish *>(anim))
{
set_animal.insert("dog");
}
}
std::cout << "Owner " << owners[i].GetOwnerName() << "(" << owners[i].GetOwnerAge() << " years old) has " << set_animal.size() << " different animals\n";
animls.clear();
set_animal.clear();
}
for (Animal *anim : anims) // освобождение памяти
{
delete anim;
}
}