AdvC++ - zadanie 2 students filtrowanie

This commit is contained in:
Sasza Stanczew 2024-04-26 11:36:08 +02:00
parent 1295a11932
commit 05f5e5df3d

View file

@ -15,7 +15,10 @@ struct Student {
};
std::vector<Student*> filterStudents(const std::vector<std::unique_ptr<Student>>& students, double minAverage) {
// Implement method here
std::vector<Student*> ptr;
rn::transform(students, std::back_inserter(ptr), [](const std::unique_ptr<Student> &s){return s.get();});
std::erase_if(ptr, [minAverage](Student* s){return s->average_ < minAverage;});
return ptr;
}
int main() {
@ -30,5 +33,7 @@ int main() {
students.push_back(std::make_unique<Student>(811111, "Mike", 4.45));
const auto res = filterStudents(students, 4.45);
// Print result here using ranges (do not create friend operator<<)
}
for(const auto& [ind, nam, av] : res | std::views::transform([](Student *ptr){return *ptr;})){
printf("%d %s %f\n", ind, nam.c_str(), av);
}
}