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 <iostream>
#include <ctime> #include <ctime>
#include <utility> #include <utility>
@ -8,34 +7,50 @@
using namespace std; 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 class Date
{ {
private: private:
short day; short day_;
short month; short month_;
unsigned int year; unsigned int year_;
public: 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{}; time_t timestamp; //Aktuelles Datum und Uhrzeit in Variable speichern
__time64_t long_time; timestamp = time(nullptr);
_time64(&long_time); tm date{};
const auto err = _localtime64_s(&new_time, &long_time); localtime_s(&date, &timestamp);
if (!err) return new_time.tm_year - (year - 1900) - 1; const auto current_year = date.tm_year + 1900;
printf("Invalid argument to _localtime_s"); return current_year - year_;
return 0;
} }
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 class employee
{ {
private: private:
@ -69,6 +84,13 @@ public:
return false; 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 name;
string first_name; string first_name;
Date day_of_birth; Date day_of_birth;
@ -77,10 +99,12 @@ public:
}; };
static list<employee> employees; static list<employee> employees;
void create_employee(); void create_employee();
employee* search_employee();
void search_employee(); void list_employees();
void modify_employee();
void print_employee(employee employee);
void enter_holidays(employee& employee);
int main() int main()
{ {
@ -89,12 +113,10 @@ int main()
{ {
system("cls"); system("cls");
cout << "Urlaubsverwaltung (" << employees.size() << " Mitarbeiter)" << endl << endl; 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 << "1: Mitarbeiter anlegen" << endl;
cout << "2: Mitarbeiter l<EFBFBD>schen" << endl; cout << "2: Mitarbeiter bearbeiten" << endl;
cout << "3: Urlaub eingeben" << endl; cout << "3: Alle Mitarbeiter auflisten" << endl;
cout << "4: Mitarbeiter suchen" << endl;
cout << "5: Alle Mitarbeiter auflisten" << endl;
cout << "0: Programm beenden" << endl; cout << "0: Programm beenden" << endl;
cout << "ihre Eingabe:"; cout << "ihre Eingabe:";
auto input = 0; auto input = 0;
@ -106,13 +128,10 @@ int main()
create_employee(); create_employee();
break; break;
case 2: case 2:
modify_employee();
break; break;
case 3: case 3:
break; list_employees();
case 4:
search_employee();
break;
case 5:
break; break;
case 0: case 0:
end_program = true; 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; string name;
cout << "Bitte einen Namen eingeben: "; cout << "Bitte einen Namen eingeben: ";
cin >> name; cin >> name;
string first_name; string first_name;
cout << "Bitte einen Vornamen eingeben: "; cout << "Bitte einen Vornamen eingeben: ";
cin >> first_name; 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)) if (e.first_name._Equal(first_name) && e.name._Equal(name))
{ {
found = employee(e); return &e;
break;
} }
} }
modify_employee(found); throw 0;
employees.remove(found);
} }
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) while (true)
{ {

View File

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

View File

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