1
0
This commit is contained in:
Holger Boerchers
2018-11-20 22:12:33 +01:00
3 changed files with 127 additions and 55 deletions

View File

@ -1,4 +1,3 @@
#include "pch.h"
#include <iostream>
#include <ctime>
#include <utility>
@ -8,34 +7,50 @@
using namespace std;
//Zeichen Hex Okt
//========================
// '<27>' 8E 216
// '<27>' 84 204
// '<27>' 99 231
// '<27>' 94 224
// '<27>' 9A 232
// '<27>' 81 201
// '<27>' 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, &timestamp);
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<employee> 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<EFBFBD>hlen Sie eine Option:" << endl;
cout << "Bitte w\x84hlen Sie eine Option:" << endl;
cout << "1: Mitarbeiter anlegen" << endl;
cout << "2: Mitarbeiter l<EFBFBD>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)
{

View File

@ -99,7 +99,7 @@
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel>
<Optimization>Disabled</Optimization>
<SDLCheck>true</SDLCheck>
@ -151,15 +151,6 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="pch.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
</ClCompile>
<ClCompile Include="Urlaubsverwaltung.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />

View File

@ -15,14 +15,6 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include="pch.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="Urlaubsverwaltung.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>