diff --git a/Urlaubsverwaltung/Urlaubsverwaltung.cpp b/Urlaubsverwaltung/Urlaubsverwaltung.cpp index 657d0d2..cf92491 100644 --- a/Urlaubsverwaltung/Urlaubsverwaltung.cpp +++ b/Urlaubsverwaltung/Urlaubsverwaltung.cpp @@ -17,39 +17,58 @@ private: public: Date() : day(1), month(1), year(1900) { - } + Date(short day, short month, unsigned int year) : day(day), month(month), year(year) { } - double get_age() + double get_age() const { - struct tm newtime; + tm new_time{}; __time64_t long_time; _time64(&long_time); - auto err = _localtime64_s(&newtime, &long_time); - if(err) - { - printf("Invalid argument to _localtime_s"); - return 0; - } - return newtime.tm_year - (year - 1900); + const auto err = _localtime64_s(&new_time, &long_time); + if (!err) return new_time.tm_year - (year - 1900) - 1; + printf("Invalid argument to _localtime_s"); + return 0; } }; -class Employee +class employee { private: public: - Employee(string name, string first_name, short day, short month, unsigned int year) : name(move(name)), first_name(move(first_name)), taken_holidays(0) + employee(): holidays(0), taken_holidays(0) + { + } + + employee(const employee& rhs) : name(rhs.name), first_name(rhs.first_name), day_of_birth(rhs.day_of_birth), + holidays(rhs.holidays), taken_holidays(rhs + .taken_holidays) + { + } + + employee(string name, string first_name, short day, short month, unsigned int year) : name(move(name)), + first_name(move(first_name)), + taken_holidays(0) { day_of_birth = Date(day, month, year); - auto age = day_of_birth.get_age(); + const auto age = day_of_birth.get_age(); holidays = age > 50 ? 32 : 30; } + bool try_take_holidays(const int days) + { + if (holidays - taken_holidays - days > 0) + { + taken_holidays += days; + return true; + } + return false; + } + string name; string first_name; Date day_of_birth; @@ -57,17 +76,19 @@ public: int taken_holidays; }; -static list employees; +static list employees; void create_employee(); +void search_employee(); + int main() { auto end_program = false; while (!end_program) { system("cls"); - cout << "Urlaubsverwaltung" << endl << endl; + cout << "Urlaubsverwaltung (" << employees.size() << " Mitarbeiter)" << endl << endl; cout << "Bitte wählen Sie eine Option:" << endl; cout << "1: Mitarbeiter anlegen" << endl; cout << "2: Mitarbeiter löschen" << endl; @@ -89,6 +110,7 @@ int main() case 3: break; case 4: + search_employee(); break; case 5: break; @@ -107,9 +129,9 @@ void create_employee() while (true) { string name; - string first_name; cout << "Bitte einen Namen eingeben: "; cin >> name; + string first_name; cout << "Bitte einen Vornamen eingeben: "; cin >> first_name; cout << "Bitte das Geburtsdatum eingeben: " << endl; @@ -126,6 +148,52 @@ void create_employee() cout << "Einen weiteren Benutzer eingeben? [J/N]" << endl; string input; cin >> input; - if (input._Equal("N")|| input._Equal("n")) break; + if (input._Equal("N") || input._Equal("n")) break; + } +} + +void modify_employee(employee employee); + +void search_employee() +{ + string name; + cout << "Bitte einen Namen eingeben: "; + cin >> name; + string first_name; + cout << "Bitte einen Vornamen eingeben: "; + cin >> first_name; + const auto found = employee(); + for (auto e : employees) + { + if (e.first_name._Equal(first_name) && e.name._Equal(name)) + { + found = const employee(e); + break; + } + } + modify_employee(found); + employees.remove(const found); +} + +void modify_employee(employee employee) +{ + while (true) + { + int holidays; + cout << "Urlaubstage eingeben: "; + cin >> holidays; + if (employee.try_take_holidays(holidays)) + { + cout << "Urlaub genehmingt." << endl; + } + else + { + cout << "Urlaub abgelehnt." << endl; + } + cout << "Resturlaub: " << employee.holidays - employee.taken_holidays << " Tage" << endl; + cout << "Einen weiteren Urlaubsantrag eingeben? [J/N]" << endl; + string input; + cin >> input; + if (input._Equal("N") || input._Equal("n")) break; } }