comments...

This commit is contained in:
Holger Börchers 2018-12-29 11:48:30 +01:00
parent 0eec488dfb
commit c5d7a7eb60

View File

@ -69,7 +69,6 @@ auto int_to_string(const unsigned int value, const unsigned int digits = 0) -> s
*/ */
class date final class date final
{ {
private:
unsigned short day_; unsigned short day_;
unsigned short month_; unsigned short month_;
unsigned short year_; unsigned short year_;
@ -123,7 +122,6 @@ public:
*/ */
class address final class address final
{ {
private:
string street_; string street_;
string street_no_; string street_no_;
string postal_code_; string postal_code_;
@ -158,13 +156,13 @@ public:
return istr; return istr;
} }
/** /**
* \brief Output operator of address * \brief Output operator of address
* \param ostr output stream * \param ostr output stream
* \param address current address * \param address current address
* \return output stream * \return output stream
*/ */
friend ostream& operator<<(ostream& ostr, const address& address) friend ostream& operator<<(ostream& ostr, const address& address)
{ {
ostr << "Strasse: " << address.street_ << endl; ostr << "Strasse: " << address.street_ << endl;
ostr << "Hausnummer: " << address.street_no_ << endl; ostr << "Hausnummer: " << address.street_no_ << endl;
@ -174,9 +172,11 @@ public:
} }
}; };
/**
* \brief Customer, represented by name, first name, address, phone and year of birth
*/
class customer final class customer final
{ {
private:
int id_; int id_;
string name_; string name_;
string first_name_; string first_name_;
@ -200,6 +200,12 @@ public:
{ {
} }
/**
* \brief Input operator of customer
* \param istr input stream
* \param customer current address instance
* \return output stream
*/
friend istream& operator>>(istream& istr, customer*& customer) friend istream& operator>>(istream& istr, customer*& customer)
{ {
cout << "Name: "; cout << "Name: ";
@ -215,6 +221,12 @@ public:
return istr; return istr;
} }
/**
* \brief Output operator of customer
* \param ostr output stream
* \param customer current customer instance
* \return output stream
*/
friend ostream& operator<<(ostream& ostr, const customer& customer) friend ostream& operator<<(ostream& ostr, const customer& customer)
{ {
ostr << "Name: " << customer.name_ << endl; ostr << "Name: " << customer.name_ << endl;
@ -226,29 +238,43 @@ public:
return ostr; return ostr;
} }
/**
* \brief get name of customer
* \return name
*/
string get_name() const string get_name() const
{ {
return name_; return name_;
} }
/**
* \brief get first name of customer
* \return first name
*/
string get_first_name() const string get_first_name() const
{ {
return first_name_; return first_name_;
} }
/**
* \brief get the value, if customer hast driving license
* \return True if customer hast driving license. False otherwise.
*/
bool get_has_driving_license() const bool get_has_driving_license() const
{ {
return has_driving_license_; return has_driving_license_;
} }
}; };
/**
* \brief Reservation of a motorcycle
*/
class reservation final class reservation final
{ {
private:
int id_; int id_;
date start_; date start_;
date end_; date end_;
short motorcycle_ = -1; // => -1 means nothing reserved short motorcycle_index_ = -1; // => -1 means nothing reserved
customer* customer_; customer* customer_;
bool canceled_; bool canceled_;
public: public:
@ -256,27 +282,43 @@ public:
id_(++next_reservation_id), id_(++next_reservation_id),
start_(start), start_(start),
end_(end), end_(end),
motorcycle_(motorcycle), motorcycle_index_(motorcycle),
customer_(customer), customer_(customer),
canceled_(false) canceled_(false)
{ {
} }
/**
* \brief get start date of reservation
* \return date instance
*/
date get_start_date() const date get_start_date() const
{ {
return start_; return start_;
} }
/**
* \brief get end date of reservation
* \return date instance
*/
date get_end_date() const date get_end_date() const
{ {
return end_; return end_;
} }
short get_motorcycle() const /**
* \brief get index of motorcycle array
* \return integer value of index
*/
short get_motorcycle_index() const
{ {
return motorcycle_; return motorcycle_index_;
} }
/**
* \brief get pointer of customer, attached to this instance
* \return pointer to customer
*/
customer* get_customer() const customer* get_customer() const
{ {
return customer_; return customer_;
@ -458,7 +500,7 @@ bool validate_reservation(reservation* const reservation)
const auto end_sum = reservation->get_end_date().get_day_num(); 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_index() == reservation->get_motorcycle_index())
{ {
if (start_sum < r->get_end_date().get_day_num() && end_sum > r->get_start_date().get_day_num() 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_day_num() && end_sum < r->get_end_date().get_day_num()) || end_sum > r->get_start_date().get_day_num() && end_sum < r->get_end_date().get_day_num())
@ -528,7 +570,7 @@ reservation* get_reservation_for_customer(customer* const current_customer)
if (reservation->get_customer() == current_customer) if (reservation->get_customer() == current_customer)
{ {
cout << ++index << ". " << reservation->get_start_date() << " - " << reservation->get_end_date() << ": " << cout << ++index << ". " << reservation->get_start_date() << " - " << reservation->get_end_date() << ": " <<
motorcycles[reservation->get_motorcycle()] << endl; motorcycles[reservation->get_motorcycle_index()] << endl;
reservations_of_customer.push_back(reservation); reservations_of_customer.push_back(reservation);
} }
} }
@ -585,7 +627,7 @@ void export_reservations()
for (auto reservation : reservations) for (auto reservation : reservations)
{ {
f << reservation->get_id() << ";"; f << reservation->get_id() << ";";
f << motorcycles[reservation->get_motorcycle()] << ";"; f << motorcycles[reservation->get_motorcycle_index()] << ";";
f << reservation->get_start_date() << ";"; f << reservation->get_start_date() << ";";
f << reservation->get_end_date() << ";"; f << reservation->get_end_date() << ";";
f << reservation->get_customer()->get_name() << ";"; f << reservation->get_customer()->get_name() << ";";