1
0

Compare commits

..

10 Commits

2 changed files with 168 additions and 62 deletions

View File

@ -1,37 +1,33 @@
#include <iostream> #include <iostream>
#include <ctime> #include <ctime>
#include <utility>
#include <vector>
#include <list> #include <list>
#include <string> #include <string>
#include <exception>
using namespace std; using namespace std;
//Zeichen Hex Okt /**
//======================== * \brief Class to represent a date.
// '<27>' 8E 216 */
// '<27>' 84 204 class date
// '<27>' 99 231
// '<27>' 94 224
// '<27>' 9A 232
// '<27>' 81 201
// '<27>' E1 341
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)
{ {
} }
/**
* \brief Get age of current item
* \return
*/
int get_age() const int get_age() const
{ {
time_t timestamp; //Aktuelles Datum und Uhrzeit in Variable speichern time_t timestamp; //Aktuelles Datum und Uhrzeit in Variable speichern
@ -39,39 +35,59 @@ public:
tm date{}; tm date{};
localtime_s(&date, &timestamp); localtime_s(&date, &timestamp);
const auto current_year = date.tm_year + 1900; const auto current_year = date.tm_year + 1900;
return current_year - year; return current_year - year_;
} }
string get_birthday() const /**
* \brief
* \return birthday as string.
*/
string to_string() const
{ {
return std::to_string(day) + "." + to_string(month) + "." + to_string(year); return std::to_string(day_) + "." + std::to_string(month_) + "." + std::to_string(year_);
} }
/**
* \brief Implements the equality operator.
*/
bool operator ==(const date& d) const { return day_ == d.day_ && month_ == d.month_ && year_ == d.year_; }
/**
* \brief Implements the inequality operator.
*/
bool operator !=(const date& d) const { return !operator==(d); }
}; };
/**
* \brief Employee defined with name, first name & date of birth
*/
class employee class employee
{ {
private:
public: public:
/**
* \brief Creates a new instance of employee
*/
employee(): holidays(0), 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 * \brief Creates a new instance of employee
.taken_holidays) */
{
}
employee(string name, string first_name, short day, short month, unsigned int year) : name(move(name)), employee(string name, string first_name, short day, short month, unsigned int year) : name(move(name)),
first_name(move(first_name)), first_name(move(first_name)),
taken_holidays(0) taken_holidays(0)
{ {
day_of_birth = Date(day, month, year); day_of_birth = date(day, month, year);
const auto age = day_of_birth.get_age(); const auto age = day_of_birth.get_age();
holidays = age > 50 ? 32 : 30; holidays = age > 50 ? 32 : 30;
} }
/**
* \brief Try take holidays
* \param days Days to take.
* \return True if holidays ready to take. False otherwise.
*/
bool try_take_holidays(const int days) bool try_take_holidays(const int days)
{ {
if (holidays - taken_holidays - days > 0) if (holidays - taken_holidays - days > 0)
@ -82,20 +98,57 @@ public:
return false; return false;
} }
/**
* \brief Implements the equality operator.
*/
bool operator ==(const employee& e) const
{
return name == e.name && first_name == e.first_name && day_of_birth == e.day_of_birth;
}
/**
* \brief Implements the inequality operator.
*/
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;
int holidays; int holidays;
int taken_holidays; int taken_holidays;
}; };
/**
* \brief Collection of all employees (Database)
*/
static list<employee> employees; static list<employee> employees;
/**
* \brief Create new employee entry in database.
*/
void create_employee(); void create_employee();
/**
employee search_employee(); * \brief Search employee in the database
* \return Return pointer of type employee
*/
employee* search_employee();
/**
* \brief List all employees in database
*/
void list_employees(); void list_employees();
/**
* \brief Modify entry in database
*/
void modify_employee();
/**
* \brief Print information about employee
* \param employee Entry from database.
*/
void print_employee(employee employee);
/**
* \brief Enter holidays to take, if available.
* \param employee Employee as reference.
*/
void enter_holidays(employee& employee);
int main() int main()
{ {
@ -104,14 +157,13 @@ int main()
{ {
system("cls"); system("cls");
cout << "Urlaubsverwaltung (" << employees.size() << " Mitarbeiter)" << endl << endl; cout << "Urlaubsverwaltung (" << employees.size() << " Mitarbeiter)" << endl << endl;
cout << "Bitte w\x84hlen Sie eine Option:" << endl; cout << "Bitte w\x84hlen Sie:" << endl;
cout << "1: Mitarbeiter anlegen" << endl; cout << "1: Mitarbeiter anlegen" << endl;
cout << "2: Mitarbeiter l\x94schen" << endl; cout << "2: Mitarbeiter bearbeiten" << endl;
cout << "3: Urlaub eingeben" << endl; cout << "3: Alle Mitarbeiter auflisten" << endl;
cout << "4: Mitarbeiter suchen" << endl; cout << endl;
cout << "5: Alle Mitarbeiter auflisten" << endl;
cout << "0: Programm beenden" << endl; cout << "0: Programm beenden" << endl;
cout << "ihre Eingabe:"; cout << "> ";
auto input = 0; auto input = 0;
cin >> input; cin >> input;
@ -121,13 +173,9 @@ int main()
create_employee(); create_employee();
break; break;
case 2: case 2:
modify_employee();
break; break;
case 3: case 3:
break;
case 4:
search_employee();
break;
case 5:
list_employees(); list_employees();
break; break;
case 0: case 0:
@ -138,7 +186,8 @@ int main()
system("pause"); system("pause");
} }
} }
} return 0;
}
void create_employee() void create_employee()
{ {
@ -160,48 +209,104 @@ void create_employee()
unsigned int year; unsigned int year;
cout << "Jahr: "; cout << "Jahr: ";
cin >> year; cin >> year;
employees.emplace_back(name, first_name, day, month, year); auto em = employee(name, first_name, day, month, year);
employees.emplace_back(em);
cout << "--------------------------------" << endl;
print_employee(em);
cout << "Einen weiteren Benutzer eingeben? [J/N]" << endl; cout << "Einen weiteren Benutzer eingeben? [J/N]" << endl;
cout << "> ";
string input; string input;
cin >> input; cin >> input;
if (input._Equal("N") || input._Equal("n")) break; if (input._Equal("N") || input._Equal("n")) break;
} }
} }
void modify_employee(employee employee);
employee search_employee() employee* search_employee()
{ {
if (employees.empty()) throw exception("Es gibt keine Benutzer in der Datenbank.");
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;
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))
{ {
return e; return &e;
} }
} }
return employee{}; throw exception("Benutzer nicht gefunden.");
} }
void list_employees() void list_employees()
{ {
for (const auto& employee : employees) for (auto& employee : employees)
{ {
cout << " First name: " << employee.first_name << " Name: " << employee.name << endl; print_employee(employee);
cout << " Birthday: " << employee.day_of_birth.get_birthday() << endl;
cout << " Holidays: " << employee.holidays << " Taken Holidays: " << employee.taken_holidays << endl;
cout << "--------------------------------" << endl;
} }
system("pause"); 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");
cout << "Mitarbeiter:" << endl << endl;
print_employee(*current);
cout << "Bitte w\x84hlen Sie eine Option:" << endl;
cout << "1: Urlaub eingeben" << endl;
cout << "2: Mitarbeiter l\x94schen" << endl;
cout << endl;
cout << "0: Zur\x81 \bck" << endl;
cout << "> ";
auto input = 0;
cin >> input;
switch (input)
{
case 1:
enter_holidays(*current);
break;
case 2:
employees.remove(*current);
cout << "Benutzer gel\x94scht" << endl;
system("pause");
end_program = true;
break;
case 0:
end_program = true;
break;
default:
cout << "Unerlaubte Eingabe" << endl;
system("pause");
}
}
}
catch (exception& ex)
{
cout << ex.what() << endl;
system("pause");
}
}
void print_employee(employee employee)
{
cout << " " << employee.first_name << " " << employee.name << endl;
cout << " Geburtstag: " << employee.day_of_birth.to_string() << endl;
cout << " Resturlaub: " << employee.holidays - employee.taken_holidays << endl;
cout << "--------------------------------" << endl;
}
void enter_holidays(employee& employee)
{ {
while (true) while (true)
{ {
@ -210,7 +315,7 @@ void modify_employee(employee employee)
cin >> holidays; cin >> holidays;
if (employee.try_take_holidays(holidays)) if (employee.try_take_holidays(holidays))
{ {
cout << "Urlaub genehmingt." << endl; cout << "Urlaub genehmigt." << endl;
} }
else else
{ {
@ -218,6 +323,7 @@ void modify_employee(employee employee)
} }
cout << "Resturlaub: " << employee.holidays - employee.taken_holidays << " Tage" << endl; cout << "Resturlaub: " << employee.holidays - employee.taken_holidays << " Tage" << endl;
cout << "Einen weiteren Urlaubsantrag eingeben? [J/N]" << endl; cout << "Einen weiteren Urlaubsantrag eingeben? [J/N]" << endl;
cout << "> ";
string input; string input;
cin >> input; cin >> input;
if (input._Equal("N") || input._Equal("n")) break; if (input._Equal("N") || input._Equal("n")) break;

View File

@ -133,7 +133,7 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile> <ClCompile>
<PrecompiledHeader>Use</PrecompiledHeader> <PrecompiledHeader>NotUsing</PrecompiledHeader>
<WarningLevel>Level3</WarningLevel> <WarningLevel>Level3</WarningLevel>
<Optimization>MaxSpeed</Optimization> <Optimization>MaxSpeed</Optimization>
<FunctionLevelLinking>true</FunctionLevelLinking> <FunctionLevelLinking>true</FunctionLevelLinking>