1
0
Fork 0
This commit is contained in:
Eric Teunis de Boone 2020-01-06 16:36:53 +01:00
parent d9cbe495da
commit 579d3355cc
2 changed files with 75 additions and 0 deletions

43
ex8.1/Manager.hh Normal file
View file

@ -0,0 +1,43 @@
#ifndef MANAGER_HH
#define MANAGER_HH
#include <string>
#include <iostream>
#include <set>
#include "Employee.hh"
using namespace std ;
class Manager : public Employee {
public:
Manager(const char* name, double salary) : Employee(name, salary) {}
void businessCard( ostream& os = cout) const {
Employee::businessCard( os );
os << " +----------+ " << endl
<< " Subordinates " << endl
<< " +----------+ " << endl;
for ( auto iter = _subordinates.begin() ; iter != _subordinates.end(); iter++ ) {
os << " - " << (*iter)->name() << endl;
}
os << " +----------+ " << endl;
}
void addSubordinate ( Employee& empl ) {
_subordinates.insert( &empl );
}
const set<Employee*>& listOfSubordinates() const {
return _subordinates;
}
private:
string _name ;
double _salary ;
set<Employee*> _subordinates ;// subordinates is an unordered collection so set is usefull enough
} ;
#endif

32
ex8.1/main.cpp Normal file
View file

@ -0,0 +1,32 @@
#include <iostream>
#include "Employee.hh"
#include "Manager.hh"
int main() {
Employee wouter("Wouter", 0);
Employee ivo("Ivo", 0);
Manager stan("Stan", 0);
Manager jo("Jo", 0);
Manager frank("Frank", 0);
stan.addSubordinate(wouter);
stan.addSubordinate(ivo);
frank.addSubordinate(stan); // This does not give a problem because stan is also of type Employee
frank.addSubordinate(jo);
// Print the Business Cards
frank.businessCard();
std::cout << std::endl;
jo.businessCard();
std::cout << std::endl;
stan.businessCard();
std::cout << std::endl;
wouter.businessCard();
std::cout << std::endl;
ivo.businessCard();
std::cout << std::endl;
}