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
| #include <iostream>
#include <map>
#include <functional>
#include <iterator>
#include <string>
#include <iostream>
class Person
{
public:
Person(std::string name, short age, std::string group):name_(name), age_(age), group_(group)
{
}
virtual ~Person() { }
std::string get_name() const {return name_;}
short get_age() const {return age_;}
std::string get_group() const {return group_;}
virtual void show(std::ostream& os) const
{
os << "Name: " << name_ << std::endl
<< "Age: " << age_ << std::endl
<< "Group: " << group_ << std::endl;
}
protected:
std::string name_;
short age_;
std::string group_;
};
class Student:public Person
{
public:
Student(const std::string& name, short age, const std::string& group, const std::string& dep):
Person(name, age, group), departement_(dep)
{
students.insert(std::make_pair(age, this));
}
std::string get_departement() const {return departement_;}
virtual void show(std::ostream& os) const
{
for (std::multimap<short, const Student*, std::greater<short> >::const_iterator iter = students.begin(); iter != students.end(); ++iter)
{
iter->second->show_me(os);
}
}
private:
static std::multimap<short, const Student*, std::greater<short> > students;
std::string departement_;
void show_me(std::ostream& os) const
{
Person::show(os);
os << "Departement: " << departement_ << std::endl;
}
};
std::multimap<short, const Student*, std::greater<short> > Student::students;
int main()
{
Student stud("Vasya", 18, "1A", "BD");
Student stud2("Vasya2", 19, "1B", "BD");
Student stud3("Vasya3", 18, "1C", "FD");
Student stud4("Vasya4", 17, "1D", "FD");
stud4.show(std::cout);
} |