comments comments

This commit is contained in:
Holger Börchers 2018-12-28 21:02:27 +01:00
parent ed0dd06804
commit 0eec488dfb

View File

@ -64,14 +64,21 @@ auto int_to_string(const unsigned int value, const unsigned int digits = 0) -> s
return str; return str;
} }
/**
* \brief Present a date with day, month and year
*/
class date final class date final
{ {
private: private:
unsigned short day_; unsigned short day_;
unsigned short month_; unsigned short month_;
unsigned short year_; unsigned short year_;
int sum_; int day_num_;
/**
* \brief Get the day number from current day/month/year.
* \return Number of days
*/
int day_number_from_date() const int day_number_from_date() const
{ {
const auto month = (month_ + 9) % 12; const auto month = (month_ + 9) % 12;
@ -81,16 +88,27 @@ private:
public: public:
date(const unsigned short day, const unsigned short month, const unsigned short year) : day_(day), month_(month), date(const unsigned short day, const unsigned short month, const unsigned short year) : day_(day), month_(month),
year_(year) year_(year),
day_num_(
day_number_from_date())
{ {
sum_ = day_number_from_date();
} }
int get_sum() const /**
* \brief Get day num of current day/month/year
* \return Number of days
*/
int get_day_num() const
{ {
return sum_; return day_num_;
} }
/**
* \brief Output operator of date formatted as DD.MM.YYYY
* \param ostr output stream
* \param date current date
* \return output stream
*/
friend ostream& operator<<(ostream& ostr, const date& date) friend ostream& operator<<(ostream& ostr, const date& date)
{ {
ostr << int_to_string(date.day_, 2) << "." ostr << int_to_string(date.day_, 2) << "."
@ -100,6 +118,9 @@ public:
} }
}; };
/**
* \brief address containing street, no, postal code and city
*/
class address final class address final
{ {
private: private:
@ -118,6 +139,12 @@ public:
{ {
} }
/**
* \brief Input operator of address
* \param istr output stream
* \param address current address
* \return output stream
*/
friend istream& operator>>(istream& istr, address& address) friend istream& operator>>(istream& istr, address& address)
{ {
cout << "Strasse: "; cout << "Strasse: ";
@ -131,12 +158,18 @@ public:
return istr; return istr;
} }
friend ostream& operator<<(ostream& ostr, const address& customer) /**
* \brief Output operator of address
* \param ostr output stream
* \param address current address
* \return output stream
*/
friend ostream& operator<<(ostream& ostr, const address& address)
{ {
ostr << "Strasse: " << customer.street_ << endl; ostr << "Strasse: " << address.street_ << endl;
ostr << "Hausnummer: " << customer.street_no_ << endl; ostr << "Hausnummer: " << address.street_no_ << endl;
ostr << "Postleitzahl: " << customer.postal_code_ << endl; ostr << "Postleitzahl: " << address.postal_code_ << endl;
ostr << "Ort: " << customer.city_ << endl; ostr << "Ort: " << address.city_ << endl;
return ostr; return ostr;
} }
}; };
@ -421,14 +454,14 @@ int select_motorcycle()
bool validate_reservation(reservation* const reservation) bool validate_reservation(reservation* const reservation)
{ {
const auto start_sum = reservation->get_start_date().get_sum(); const auto start_sum = reservation->get_start_date().get_day_num();
const auto end_sum = reservation->get_end_date().get_sum(); const auto end_sum = reservation->get_end_date().get_day_num();
for (auto r : reservations) for (auto r : reservations)
{ {
if (r->get_motorcycle() == reservation->get_motorcycle()) if (r->get_motorcycle() == reservation->get_motorcycle())
{ {
if (start_sum < r->get_end_date().get_sum() && end_sum > r->get_start_date().get_sum() if (start_sum < r->get_end_date().get_day_num() && end_sum > r->get_start_date().get_day_num()
|| end_sum > r->get_start_date().get_sum() && end_sum < r->get_end_date().get_sum()) || end_sum > r->get_start_date().get_day_num() && end_sum < r->get_end_date().get_day_num())
{ {
return false; return false;
} }