1
0

Compare commits

...

2 Commits

Author SHA1 Message Date
Holger Boerchers
0040965d2f Merge branch 'master' of https://git.boerchers.org/CPP/Urlaubsverwaltung 2018-11-20 22:12:33 +01:00
Holger Boerchers
3c4e1056e3 found solution! 2018-11-20 20:06:06 +01:00

View File

@ -20,15 +20,15 @@ using namespace std;
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)
{
}
@ -39,15 +39,17 @@ public:
tm date{};
localtime_s(&date, &timestamp);
const auto current_year = date.tm_year + 1900;
return current_year - year;
return current_year - year_;
}
string get_birthday() const
{
return std::to_string(day) + "." + to_string(month) + "." + to_string(year);
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
{
@ -82,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;
@ -90,12 +99,12 @@ public:
};
static list<employee> employees;
void create_employee();
employee search_employee();
employee* search_employee();
void list_employees();
void modify_employee();
void print_employee(employee employee);
void enter_holidays(employee& employee);
int main()
{
@ -106,10 +115,8 @@ int main()
cout << "Urlaubsverwaltung (" << employees.size() << " Mitarbeiter)" << endl << endl;
cout << "Bitte w\x84hlen Sie eine Option:" << endl;
cout << "1: Mitarbeiter anlegen" << endl;
cout << "2: Mitarbeiter l\x94schen" << 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;
@ -121,13 +128,9 @@ 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:
@ -168,40 +171,100 @@ void create_employee()
}
}
void modify_employee(employee employee);
employee 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;
for (auto e : employees)
for (auto& e : employees)
{
if (e.first_name._Equal(first_name) && e.name._Equal(name))
{
return e;
return &e;
}
}
return employee{};
throw 0;
}
void list_employees()
{
for (const auto& employee : employees)
for (auto& employee : employees)
{
cout << " First name: " << employee.first_name << " Name: " << employee.name << endl;
cout << " Birthday: " << employee.day_of_birth.get_birthday() << endl;
cout << " Holidays: " << employee.holidays << " Taken Holidays: " << employee.taken_holidays << endl;
cout << "--------------------------------" << endl;
print_employee(employee);
}
system("pause");
}
void modify_employee(employee employee)
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)
{