diff --git a/Urlaubsverwaltung/Urlaubsverwaltung.cpp b/Urlaubsverwaltung/Urlaubsverwaltung.cpp index da11dfe..48cef3d 100644 --- a/Urlaubsverwaltung/Urlaubsverwaltung.cpp +++ b/Urlaubsverwaltung/Urlaubsverwaltung.cpp @@ -1,4 +1,3 @@ -#include "pch.h" #include #include #include @@ -8,34 +7,50 @@ using namespace std; +//Zeichen Hex Okt +//======================== +// 'Ä' 8E 216 +// 'ä' 84 204 +// 'Ö' 99 231 +// 'ö' 94 224 +// 'Ü' 9A 232 +// 'ü' 81 201 +// 'ß' E1 341 + class Date { private: - short day; - short month; - unsigned int year; + short day_; + short month_; + unsigned int year_; public: - Date() : day(1), month(1), year(1900) + Date() : day_(1), month_(1), year_(1900) { } - Date(short day, short month, unsigned int year) : day(day), month(month), year(year) + Date(short day, short month, unsigned int year) : day_(day), month_(month), year_(year) { } - double get_age() const + int get_age() const { - tm new_time{}; - __time64_t long_time; - _time64(&long_time); - 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; + time_t timestamp; //Aktuelles Datum und Uhrzeit in Variable speichern + timestamp = time(nullptr); + tm date{}; + localtime_s(&date, ×tamp); + const auto current_year = date.tm_year + 1900; + return current_year - year_; } + + string get_birthday() const + { + return std::to_string(day_) + "." + to_string(month_) + "." + to_string(year_); + } + + bool operator ==(const Date& d) const { return day_ == d.day_ && month_ == d.month_ && year_ == d.year_; } + bool operator !=(const Date& d) const { return !operator==(d); } }; - class employee { private: @@ -69,6 +84,13 @@ public: return false; } + bool operator ==(const employee& e) const + { + return name == e.name && first_name == e.first_name && day_of_birth == e.day_of_birth; + } + + bool operator !=(const employee& e) const { return !operator==(e); } + string name; string first_name; Date day_of_birth; @@ -77,10 +99,12 @@ public: }; static list employees; - void create_employee(); - -void search_employee(); +employee* search_employee(); +void list_employees(); +void modify_employee(); +void print_employee(employee employee); +void enter_holidays(employee& employee); int main() { @@ -89,12 +113,10 @@ int main() { system("cls"); cout << "Urlaubsverwaltung (" << employees.size() << " Mitarbeiter)" << endl << endl; - cout << "Bitte wählen Sie eine Option:" << endl; + cout << "Bitte w\x84hlen Sie eine Option:" << endl; cout << "1: Mitarbeiter anlegen" << endl; - cout << "2: Mitarbeiter löschen" << endl; - cout << "3: Urlaub eingeben" << endl; - cout << "4: Mitarbeiter suchen" << endl; - cout << "5: Alle Mitarbeiter auflisten" << endl; + cout << "2: Mitarbeiter bearbeiten" << endl; + cout << "3: Alle Mitarbeiter auflisten" << endl; cout << "0: Programm beenden" << endl; cout << "ihre Eingabe:"; auto input = 0; @@ -106,13 +128,10 @@ int main() create_employee(); break; case 2: + modify_employee(); break; case 3: - break; - case 4: - search_employee(); - break; - case 5: + list_employees(); break; case 0: end_program = true; @@ -152,30 +171,100 @@ void create_employee() } } -void modify_employee(employee employee); -void search_employee() +employee* search_employee() { + if (employees.empty()) throw 1; string name; cout << "Bitte einen Namen eingeben: "; cin >> name; string first_name; cout << "Bitte einen Vornamen eingeben: "; cin >> first_name; - auto found = employee(); - for (auto e : employees) + for (auto& e : employees) { if (e.first_name._Equal(first_name) && e.name._Equal(name)) { - found = employee(e); - break; + return &e; } } - modify_employee(found); - employees.remove(found); + throw 0; } -void modify_employee(employee employee) +void list_employees() +{ + for (auto& employee : employees) + { + print_employee(employee); + } + system("pause"); +} + +void modify_employee() +{ + auto end_program = false; + try + { + const auto current = search_employee(); + + while (!end_program) + { + system("cls"); + print_employee(*current); + cout << "Bitte w\x84hlen Sie eine Option:" << endl; + cout << "1: Urlaub eingeben" << endl; + cout << "2: Mitarbeiter l\x94schen" << endl; + cout << "0: Zurueck" << endl; + cout << "Ihre Eingabe:"; + auto input = 0; + cin >> input; + + switch (input) + { + case 1: + enter_holidays(*current); + break; + case 2: + employees.remove(*current); + cout << "Benutzer gel\x94scht"; + system("pause"); + end_program = true; + break; + case 0: + end_program = true; + break; + default: + cout << "Unerlaubte Eingabe" << endl; + system("pause"); + } + } + } + catch (int ex) + { + switch (ex) + { + case 0: + cout << "Benutzer nicht gefunden. Code: " << ex << endl; + break; + case 1: + cout << "Es gibt keine Benutzer in der Datenbank. Code: " << ex << endl; + break; + default: + cout << "Unbekannter Fehler. Code: " << ex << endl; + } + system("pause"); + } +} + +void print_employee(employee employee) +{ + cout << " " << employee.first_name << employee.name << endl; + cout << " Geburtstag: " << employee.day_of_birth.get_birthday() << endl; + cout << " Urlaub: " << employee.holidays << " Genehmigter Urlaub: " << employee.taken_holidays << endl; + cout << "--------------------------------" << endl; +} + +void enter_holidays(employee& employee) { while (true) { diff --git a/Urlaubsverwaltung/Urlaubsverwaltung.vcxproj b/Urlaubsverwaltung/Urlaubsverwaltung.vcxproj index b26ec53..34a23db 100644 --- a/Urlaubsverwaltung/Urlaubsverwaltung.vcxproj +++ b/Urlaubsverwaltung/Urlaubsverwaltung.vcxproj @@ -99,7 +99,7 @@ - Use + NotUsing Level3 Disabled true @@ -151,15 +151,6 @@ - - - - - Create - Create - Create - Create - diff --git a/Urlaubsverwaltung/Urlaubsverwaltung.vcxproj.filters b/Urlaubsverwaltung/Urlaubsverwaltung.vcxproj.filters index c4fb352..656c6dc 100644 --- a/Urlaubsverwaltung/Urlaubsverwaltung.vcxproj.filters +++ b/Urlaubsverwaltung/Urlaubsverwaltung.vcxproj.filters @@ -15,14 +15,6 @@ - - Headerdateien - - - - - Quelldateien - Quelldateien