1
0

Compare commits

...

8 Commits

2 changed files with 96 additions and 53 deletions

View File

@ -1,37 +1,33 @@
#include <iostream>
#include <ctime>
#include <utility>
#include <vector>
#include <list>
#include <string>
#include <exception>
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
/**
* \brief Class to represent a date.
*/
class date
{
private:
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)
{
}
/**
* \brief Get age of current item
* \return
*/
int get_age() const
{
time_t timestamp; //Aktuelles Datum und Uhrzeit in Variable speichern
@ -42,38 +38,56 @@ public:
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_);
}
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); }
/**
* \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
{
private:
public:
/**
* \brief Creates a new instance of employee
*/
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
.taken_holidays)
{
}
/**
* \brief Creates a new instance of employee
*/
employee(string name, string first_name, short day, short month, unsigned int year) : name(move(name)),
first_name(move(first_name)),
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();
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)
{
if (holidays - taken_holidays - days > 0)
@ -84,26 +98,56 @@ public:
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 first_name;
Date day_of_birth;
date day_of_birth;
int holidays;
int taken_holidays;
};
/**
* \brief Collection of all employees (Database)
*/
static list<employee> employees;
/**
* \brief Create new employee entry in database.
*/
void create_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();
/**
* \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()
@ -113,12 +157,13 @@ int main()
{
system("cls");
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 << "2: Mitarbeiter bearbeiten" << endl;
cout << "3: Alle Mitarbeiter auflisten" << endl;
cout << endl;
cout << "0: Programm beenden" << endl;
cout << "ihre Eingabe:";
cout << "> ";
auto input = 0;
cin >> input;
@ -141,6 +186,7 @@ int main()
system("pause");
}
}
return 0;
}
void create_employee()
@ -163,8 +209,12 @@ void create_employee()
unsigned int year;
cout << "Jahr: ";
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 << "> ";
string input;
cin >> input;
if (input._Equal("N") || input._Equal("n")) break;
@ -174,7 +224,7 @@ void create_employee()
employee* search_employee()
{
if (employees.empty()) throw 1;
if (employees.empty()) throw exception("Es gibt keine Benutzer in der Datenbank.");
string name;
cout << "Bitte einen Namen eingeben: ";
cin >> name;
@ -188,7 +238,7 @@ employee* search_employee()
return &e;
}
}
throw 0;
throw exception("Benutzer nicht gefunden.");
}
void list_employees()
@ -210,12 +260,14 @@ void modify_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 << "0: Zurueck" << endl;
cout << "Ihre Eingabe:";
cout << endl;
cout << "0: Zur\x81 \bck" << endl;
cout << "> ";
auto input = 0;
cin >> input;
@ -226,7 +278,7 @@ void modify_employee()
break;
case 2:
employees.remove(*current);
cout << "Benutzer gel\x94scht";
cout << "Benutzer gel\x94scht" << endl;
system("pause");
end_program = true;
break;
@ -239,28 +291,18 @@ void modify_employee()
}
}
}
catch (int ex)
catch (exception& 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;
}
cout << ex.what() << 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 << " " << 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;
}
@ -273,7 +315,7 @@ void enter_holidays(employee& employee)
cin >> holidays;
if (employee.try_take_holidays(holidays))
{
cout << "Urlaub genehmingt." << endl;
cout << "Urlaub genehmigt." << endl;
}
else
{
@ -281,6 +323,7 @@ void enter_holidays(employee& employee)
}
cout << "Resturlaub: " << employee.holidays - employee.taken_holidays << " Tage" << endl;
cout << "Einen weiteren Urlaubsantrag eingeben? [J/N]" << endl;
cout << "> ";
string input;
cin >> input;
if (input._Equal("N") || input._Equal("n")) break;

View File

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