#include "Staff.h" #include "Employee.h" #include #include #include #include #include using namespace std; class Incrementer { private: int count, step; // State public: Incrementer(int count, int step); // Constructor int operator() (); // Operator() }; class Concatenator { private: string theString; public: Concatenator(const string & initialContent = ""); string operator() (string stringToAdd, int repeatCount = 1); }; Incrementer::Incrementer(int count, int step) { this->count = count; this->step = step; } int Incrementer::operator() () { return count += step; } Concatenator::Concatenator(const string & initialContent) { theString = initialContent + "\n"; } string Concatenator::operator() (string stringToAdd, int repeatCount) { for (int i = 0; i < repeatCount; i++) theString += stringToAdd + "\n"; return theString; } template void print(const T& n) { cout << n << " "; } template struct printer { void operator() (const T& n) const; }; template void printer::operator() (const T& n) const { cout << n << " "; } int main() { Employee e0("Jayne", 10000, 100); Employee e1("Andy", 10100, 101); Employee e2("Emily", 10200, 102); Employee e3("Tom", 10300, 103); Employee e4("Claire", 10400, 104); Employee e5("Simon", 10500, 105); Employee e6("Joseff", 10600, 106); Employee e7("Iestyn", 10700, 107); Employee e8("Jack", 10800, 108); Employee e9("Jill", 10900, 109); string str = e1; cout << str << endl; Staff s(10); s.Insert(e0, 0); s.Insert(e1, 1); s.Insert(e2, 2); s.Insert(e3, 3); s.Insert(e4, 4); s.Insert(e5, 5); s.Insert(e6, 6); s.Insert(e7, 7); s.Insert(e8, 8); s.Insert(e9, 9); cout << "Enter an array index between 0 and " << s.NumEmps() - 1 << ": "; int index; cin >> index; Employee emp = s[index]; cout << "Full details via ToString(): " << emp.ToString() << endl; cout << "Employee cast to a string: " << (string)emp << endl; cout << "Employee cast to an int: " << (int)emp << endl; cout << "\nEnter the name of an employee: "; string name; cin >> name; emp = s[name]; cout << "Full details via ToString(): " << emp.ToString() << endl; cout << "Employee cast to a string: " << (string)emp << endl; cout << "Employee cast to an int: " << (int)emp << endl; /* // Some algorithms :-) double array1[] = { 1, 2, 3, 4, 5 }; double array2[] = { 10, 20, 30, 40, 50 }; double results[5]; transform(array1, array1+5, array2, results, plus()); for_each(results, results+5, printer()); cout << endl; */ return 0; }