employee2.cpp
903 Bytes
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
#include <algorithm>
#include <iostream>
#include <set>
#include <string>
using namespace std;
class Employee {
string name;
char middle_initial;
long department;
public:
Employee(const string& n, int dept) : name(n), department(dept){};
virtual void print() const
{
cout << name << '\t' << department << endl;
}
virtual ~Employee(){};
};
class Manager : public Employee {
short level;
public:
Manager(const string& name, int dept, int l)
: Employee(name, dept), level(l){};
void print() const
{
Employee::print();
cout << "\tlevel" << level << endl;
}
};
void print_list(set<Employee*>& s)
{
for (Employee* p : s)
p->print();
}
int main()
{
Employee e("Brown", 1234);
Manager m("Smith", 1234, 2);
set<Employee*> empl;
empl.insert(&e);
empl.insert(&m);
print_list(empl);
}