From 579d3355ccf18a3bef8d7c55d188df3d79cad48d Mon Sep 17 00:00:00 2001 From: Eric Teunis de Boone Date: Mon, 6 Jan 2020 16:36:53 +0100 Subject: [PATCH] Ex8.1 --- ex8.1/Manager.hh | 43 +++++++++++++++++++++++++++++++++++++++++++ ex8.1/main.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 ex8.1/Manager.hh create mode 100644 ex8.1/main.cpp diff --git a/ex8.1/Manager.hh b/ex8.1/Manager.hh new file mode 100644 index 0000000..6a099dc --- /dev/null +++ b/ex8.1/Manager.hh @@ -0,0 +1,43 @@ +#ifndef MANAGER_HH +#define MANAGER_HH + +#include +#include +#include +#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& listOfSubordinates() const { + return _subordinates; + } + +private: + string _name ; + double _salary ; + set _subordinates ;// subordinates is an unordered collection so set is usefull enough + +} ; + +#endif diff --git a/ex8.1/main.cpp b/ex8.1/main.cpp new file mode 100644 index 0000000..f5c011f --- /dev/null +++ b/ex8.1/main.cpp @@ -0,0 +1,32 @@ +#include +#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; + +}