From f3a349f7cf26d71fe2a542d0f416f1844a348b7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20B=C3=B6rchers?= Date: Sat, 29 Dec 2018 14:30:26 +0100 Subject: [PATCH] comments and reorganization --- src/Motorradvermietung.cpp | 133 ++++++++++++++++++++----------------- 1 file changed, 72 insertions(+), 61 deletions(-) diff --git a/src/Motorradvermietung.cpp b/src/Motorradvermietung.cpp index ba0be43..f6bbef8 100644 --- a/src/Motorradvermietung.cpp +++ b/src/Motorradvermietung.cpp @@ -7,9 +7,6 @@ using namespace std; -int next_customer_id; -int next_reservation_id; - /** * \brief ask a question and get a answer. * \tparam T return parameter @@ -53,7 +50,7 @@ bool ask_question(const string& question) * \param digits Number of digits to fill * \return Formatted integer as string */ -auto int_to_string(const unsigned int value, const unsigned int digits = 0) -> string +string int_to_string(const unsigned int value, const unsigned int digits = 0) { auto str = to_string(value); const auto len = digits > str.length() ? digits - str.length() : 0; @@ -172,6 +169,11 @@ public: } }; +/** + * \brief Incremental raised number as id for customer. + */ +int next_customer_id; + /** * \brief Customer, represented by name, first name, address, phone and year of birth */ @@ -266,6 +268,11 @@ public: } }; +/** + * \brief Incremental raised number as id for a reservation. + */ +int next_reservation_id; + /** * \brief Reservation of a motorcycle */ @@ -388,7 +395,7 @@ void main_menu(); int main() { main_menu(); - return 0; + return 0; } /** @@ -396,52 +403,52 @@ int main() */ void main_menu() { - try - { - while (true) - { - system("cls"); - cout << "Motorradvermietung (" << reservations.size() << " Reservierungen; " << customers.size() << - " Kunden)" - << endl << endl; - cout << "Bitte w\x84hlen Sie eine Option:" << endl; - cout << "1: Neuen Kunden anlegen" << endl; - cout << "2: Erstellen einer Reservierung" << endl; - cout << "3: Motorrad herausgeben" << endl; - cout << "4: Reservierungen exportieren" << endl; - cout << endl; - cout << "0: Programm beenden" << endl; - const auto input = ask_question("Ihre Eingabe"); + try + { + while (true) + { + system("cls"); + cout << "Motorradvermietung (" << reservations.size() << " Reservierungen; " << customers.size() << + " Kunden)" + << endl << endl; + cout << "Bitte w\x84hlen Sie eine Option:" << endl; + cout << "1: Neuen Kunden anlegen" << endl; + cout << "2: Erstellen einer Reservierung" << endl; + cout << "3: Motorrad herausgeben" << endl; + cout << "4: Reservierungen exportieren" << endl; + cout << endl; + cout << "0: Programm beenden" << endl; + const auto input = ask_question("Ihre Eingabe"); - switch (input) - { - case 1: - create_customer(); - break; - case 2: - create_reservation(); - break; - case 3: - rent_a_motorcycle(); - break; - case 4: - export_reservations(); - break; - case 0: - { - return; - } - default: - cout << "Unerlaubte Eingabe" << endl; - system("pause"); - } - } - } - catch (...) - { - cout << "Etwas unvorhergesehendes ist passiert. Tut mir leid." << endl; - system("pause"); - } + switch (input) + { + case 1: + create_customer(); + break; + case 2: + create_reservation(); + break; + case 3: + rent_a_motorcycle(); + break; + case 4: + export_reservations(); + break; + case 0: + { + return; + } + default: + cout << "Unerlaubte Eingabe" << endl; + system("pause"); + } + } + } + catch (...) + { + cout << "Etwas unvorhergesehendes ist passiert. Tut mir leid." << endl; + system("pause"); + } } @@ -495,14 +502,14 @@ vector find_customers_by_name(const string& name) */ customer* find_customer_by_first_name(const vector& filtered_customers, const string& first_name) { - for (auto c : filtered_customers) - { - if (c->get_first_name() == first_name) - { - return c; - } - } - return nullptr; + for (auto c : filtered_customers) + { + if (c->get_first_name() == first_name) + { + return c; + } + } + return nullptr; } /** @@ -534,6 +541,10 @@ date get_validated_date(const string&& question) } } +/** + * \brief + * \return + */ int select_motorcycle() { while (true) @@ -544,9 +555,8 @@ int select_motorcycle() { cout << ++index << ": " << cycle << endl; } - const auto answer = ask_question("Auswahl"); - const auto size = static_cast(sizeof(motorcycles) / sizeof(*motorcycles)); - if (answer > 0 && answer <= size) + const auto answer = ask_question("Auswahl"); + if (answer > 0 && answer <= index) { return answer - 1; } @@ -599,6 +609,7 @@ void create_reservation() system("pause"); return; } + cout << "Kunde gefunden: " << current->get_first_name() << " " << current->get_name() << endl; if (!current->get_has_driving_license()) { cout << "Der Kunde hat keinen entsprechenden Fuehrerschein." << endl;