From 89431aa4c59aeb21737192f85b2a86ad2d3f50b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20B=C3=B6rchers?= Date: Sat, 29 Dec 2018 14:22:02 +0100 Subject: [PATCH] comments... --- src/Motorradvermietung.cpp | 173 +++++++++++++++++++++++++------------ 1 file changed, 117 insertions(+), 56 deletions(-) diff --git a/src/Motorradvermietung.cpp b/src/Motorradvermietung.cpp index d37d22b..ba0be43 100644 --- a/src/Motorradvermietung.cpp +++ b/src/Motorradvermietung.cpp @@ -324,22 +324,36 @@ public: return customer_; } + /** + * \brief Cancel reservation -> Give Motorcycle to the customer + */ void cancel_reservation() { canceled_ = true; } + /** + * \brief Get Id of the item + * \return Auto-incremented id as integer + */ int get_id() const { return id_; } + /** + * \brief get cancellation status of the reservation + * \return True is canceled. False otherwise. + */ bool get_cancellation() const { return canceled_; } }; +/** + * \brief All available motorcycles + */ string motorcycles[] = { "Suzuki Bandit", @@ -348,61 +362,92 @@ string motorcycles[] = "Kawasaki ZZR1400" }; +/** + * \brief Collection of customer-pointers + */ list customers; + +/** + * \brief Collection of reservation pointers. + */ list reservations; + +/** + * \brief Creates a new customer, let the user check the input and push it on the list. + */ void create_customer(); void create_reservation(); void rent_a_motorcycle(); void export_reservations(); +void main_menu(); +/** + * \brief Main entry method. Starts the main menu. + * \return success code + */ int main() { - 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 0; - default: - cout << "Unerlaubte Eingabe" << endl; - system("pause"); - } - } - } - catch (...) - { - cout << "Etwas unvorhergesehendes ist passiert. Tut mir leid." << endl; - system("pause"); - } + main_menu(); + return 0; } +/** + * \brief Let the user choice an option. + */ +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"); + + 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"); + } +} + + +/** + * \brief Creates a new customer, let the user check the input and push it on the list. + */ void create_customer() { while (true) @@ -424,6 +469,11 @@ void create_customer() } +/** + * \brief Finds customers by last name + * \param name Last name + * \return Returns a vector of customers with the same last name + */ vector find_customers_by_name(const string& name) { vector result; @@ -437,6 +487,29 @@ vector find_customers_by_name(const string& name) return result; } +/** + * \brief Find the first customer by first name. + * \param filtered_customers A vector of customers with the same last name + * \param first_name The first name + * \return The first customer with the matching first name. If no customer found, it returns a nullptr + */ +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; +} + +/** + * \brief Gets the validated date + * \param question Question to ask the user + * \return A date object. + */ date get_validated_date(const string&& question) { while (true) @@ -461,18 +534,6 @@ date get_validated_date(const string&& question) } } -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; -} - int select_motorcycle() { while (true)