-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter2.cpp
60 lines (53 loc) · 1.53 KB
/
filter2.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
#include <iostream>
#include "Model.h"
PersonVector getPeopleOldThan18(const CityVector &cityVector);
PersonVector getPeopleEarnMoreThan15000(const CityVector &cityVector);
int main()
{
const CityVector cities = initData();
PersonVector personVector = getPeopleOldThan18(cities);
std::cout << "----------------------------" << std::endl;
std::cout << "People larger than 18:" << std::endl;
for (auto person : personVector)
{
std::cout << person->getName() << ", Age: " << person->getAge() << std::endl;
}
std::cout << "----------------------------" << std::endl;
personVector = getPeopleEarnMoreThan15000(cities);
std::cout << "People has income greather than 15000:" << std::endl;
for (auto person : personVector)
{
std::cout << person->getName() << ", Income: " << person->getIncome() << std::endl;
}
std::cout << "----------------------------" << std::endl;
}
PersonVector getPeopleEarnMoreThan15000(const CityVector &cityVector)
{
PersonVector outputPersonVector;
for (auto city : cityVector)
{
for (auto pPerson : city->getCitizens())
{
if (pPerson->getIncome() > 15000)
{
outputPersonVector.push_back(pPerson);
}
}
}
return outputPersonVector;
}
PersonVector getPeopleOldThan18(const CityVector &cityVector)
{
PersonVector outputPersonVector;
for (auto city : cityVector)
{
for (auto pPerson : city->getCitizens())
{
if (pPerson->getAge() > 18)
{
outputPersonVector.push_back(pPerson);
}
}
}
return outputPersonVector;
}