working on...

This commit is contained in:
Holger Boerchers 2018-12-26 14:37:18 +01:00
parent 0094764a34
commit d998cd4a5a

View File

@ -42,6 +42,24 @@ bool ask_question(const string& question)
} }
} }
class date final
{
private:
unsigned short day_;
unsigned short month_;
unsigned short year_;
public:
date(const unsigned short day, const unsigned short month, const unsigned short year) : day_(day), month_(month),
year_(year)
{
}
int get_sum() const
{
return year_ + month_ + day_;
}
};
class address final class address final
{ {
private: private:
@ -150,18 +168,34 @@ class reservation final
{ {
private: private:
int id_; int id_;
string start_ = {}; date start_;
string end_ = {}; date end_;
short motorcycle_ = -1; // => -1 means nothing reserved short motorcycle_ = -1; // => -1 means nothing reserved
customer* customer_; customer* customer_;
public: public:
reservation(string start, string end, const short motorcycle, customer* customer) : id_(++next_reservation_id), reservation(const date start, const date end, const short motorcycle, customer* customer) :
start_(move(start)), id_(++next_reservation_id),
end_(move(end)), start_(start),
end_(end),
motorcycle_(motorcycle), motorcycle_(motorcycle),
customer_(customer) customer_(customer)
{ {
} }
date get_start_date() const
{
return start_;
}
date get_end_date() const
{
return end_;
}
short get_motorcycle() const
{
return motorcycle_;
}
}; };
string motorcycles[] = string motorcycles[] =
@ -261,28 +295,21 @@ vector<customer*> find_customers_by_name(const string& name)
return result; return result;
} }
bool validate_date(string& date) date get_validated_date(const string&& question)
{
auto day = 0, month = 0, year = 0;
const auto res = sscanf_s(date.c_str(), "%2d.%2d.%4d",
&day,
&month,
&year);
if (res != 3) return false;
if (month < 1 || month > 12) return false;
if (day < 1 || day > 31) return false;
if (year < 1900 || month > 2200) return false;
return true;
}
string get_validated_date(const string&& question)
{ {
while (true) while (true)
{ {
auto date = ask_question<string>(question + " (tt.mm.jjjj)"); auto date_as_string = ask_question<string>(question + " (tt.mm.jjjj)");
if (validate_date(date))
unsigned short day = 0, month = 0, year = 0;
const auto res = sscanf_s(date_as_string.c_str(), "%2d.%2d.%4d",
&day,
&month,
&year);
if (res == 3 && (month >= 1 && month <= 12) && (day >= 1 && day <= 31) && (year >= 1900 && month <= 2200))
{ {
return date; return date{day, month, year};
} }
cout << "Fehlerhafte Eingabe." << endl; cout << "Fehlerhafte Eingabe." << endl;
} }
@ -320,6 +347,21 @@ int select_motorcycle()
} }
} }
bool validate_reservation(reservation* const reservation)
{
for (auto r : reservations)
{
if(r->get_motorcycle() == reservation->get_motorcycle())
{
if(reservation->get_start_date().get_sum() > r->get_end_date().get_sum())
{
//TODO
}
}
}
}
void create_reservation() void create_reservation()
{ {
system("cls"); system("cls");
@ -352,7 +394,10 @@ void create_reservation()
const auto end_date = get_validated_date("Enddatum"); const auto end_date = get_validated_date("Enddatum");
const auto motorcycle = select_motorcycle(); const auto motorcycle = select_motorcycle();
const auto r = new reservation(start_date, end_date, motorcycle, current); const auto r = new reservation(start_date, end_date, motorcycle, current);
if (validate_reservation(r))
{
reservations.push_back(r); reservations.push_back(r);
}
} }
void rent_a_motorcycle() void rent_a_motorcycle()