From fa1dc0d19a530be717ba6df3f5c939a640405fed Mon Sep 17 00:00:00 2001 From: Holger Boerchers Date: Sun, 23 Dec 2018 11:31:16 +0100 Subject: [PATCH 1/4] created customer, reservation and address --- src/Motorradvermietung.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/Motorradvermietung.cpp b/src/Motorradvermietung.cpp index 026bd3e..c255cf1 100644 --- a/src/Motorradvermietung.cpp +++ b/src/Motorradvermietung.cpp @@ -19,6 +19,17 @@ public: } }; +class reservation final +{ +private: + tm start_ = {}; + tm end_ = {}; + short motorcycle_ = -1; // => nothing reserved + string customer_name_; + string costumer_first_name_; +public: +}; + class customer final { private: @@ -28,7 +39,6 @@ private: unsigned short year_of_birth_ = 1900; string phone_no_; bool has_driving_license_ = false; - short reserved_motorcycle_ = -1; // => nothing reserved public: customer(string&& name, string&& first_name,address&& address, unsigned short&& year_of_birth, string&& phone_no, bool&& has_driving_license) : name_(name), first_name_(first_name), @@ -41,6 +51,27 @@ public: } }; +/** + * \brief ask a question and get a answer. + * \tparam T return parameter + * \param question the question. + * \return the value. + */ +template +T ask_question(const string& question) +{ + cout << question << endl; + cout << "> "; + T value; + cin >> value; + return value; +} + +void create_customer(); +void create_reservation(); +void take_reservation(); +void export_reservations(); + int main() { std::cout << "Hello World!\n"; From 0c15d4fbf340d4f7f9e03cdf7c8769e3eec0e17e Mon Sep 17 00:00:00 2001 From: Holger Boerchers Date: Sun, 23 Dec 2018 12:52:43 +0100 Subject: [PATCH 2/4] Working on #1 --- src/Motorradvermietung.cpp | 40 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/src/Motorradvermietung.cpp b/src/Motorradvermietung.cpp index c255cf1..ecf2160 100644 --- a/src/Motorradvermietung.cpp +++ b/src/Motorradvermietung.cpp @@ -1,5 +1,6 @@ #include #include +#include using namespace std; @@ -69,10 +70,45 @@ T ask_question(const string& question) void create_customer(); void create_reservation(); -void take_reservation(); +void rent_a_motorcycle(); void export_reservations(); +list reservations; + int main() { - std::cout << "Hello World!\n"; + while (true) + { + system("cls"); + cout << "Motorradvermietung (" << reservations.size() << " Reservierungen)" << endl << endl; + cout << "Bitte w\x84hlen Sie eine Option:" << endl; + cout << "1: Erstellen eines Kunden" << 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"); + } + } } From ae5b12e235f195baaacd11ad3a494a01454dc354 Mon Sep 17 00:00:00 2001 From: Holger Boerchers Date: Sun, 23 Dec 2018 13:39:09 +0100 Subject: [PATCH 3/4] Working on #1 --- src/Motorradvermietung.cpp | 89 +++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 12 deletions(-) diff --git a/src/Motorradvermietung.cpp b/src/Motorradvermietung.cpp index ecf2160..4e07253 100644 --- a/src/Motorradvermietung.cpp +++ b/src/Motorradvermietung.cpp @@ -12,12 +12,28 @@ private: string postal_code_; string city_; public: - address(const string&& street, const string&& street_no, const string&& postal_code, const string&& city) : street_(street), - street_no_(street_no), - postal_code_(postal_code), - city_(city) + address() = default; + + address(const string&& street, const string&& street_no, const string&& postal_code, const string&& city) : + street_(street), + street_no_(street_no), + postal_code_(postal_code), + city_(city) { } + + friend istream& operator>>(istream& istr, address& address) + { + cout << "Strasse: "; + istr >> address.street_; + cout << "Hausnummer: "; + istr >> address.street_no_; + cout << "Postleitzahl: "; + istr >> address.postal_code_; + cout << "Ort: "; + istr >> address.city_; + return istr; + } }; class reservation final @@ -41,14 +57,39 @@ private: string phone_no_; bool has_driving_license_ = false; public: - customer(string&& name, string&& first_name,address&& address, unsigned short&& year_of_birth, string&& phone_no, bool&& has_driving_license) : name_(name), - first_name_(first_name), - address_(address), - year_of_birth_(year_of_birth), - phone_no_(phone_no), - has_driving_license_(has_driving_license) + customer() { - + } + + customer(string&& name, string&& first_name, address&& address, unsigned short&& year_of_birth, string&& phone_no, + bool&& has_driving_license) : name_(name), + first_name_(first_name), + address_(address), + year_of_birth_(year_of_birth), + phone_no_(phone_no), + has_driving_license_(has_driving_license) + { + } + + friend istream& operator>>(istream& istr, customer& customer) + { + cout << "Name: "; + istr >> customer.name_; + cout << "Vorname: "; + istr >> customer.first_name_; + cout << "Geburtsjahr: "; + istr >> customer.year_of_birth_; + istr >> customer.address_; + cout << "Telefonnumer: "; + istr >> customer.phone_no_; + cout << "Fuehrerschein der Klasse A? (J/N): "; + char driving_license; + istr >> driving_license; + if (driving_license == 'j' || driving_license == 'J') + { + customer.has_driving_license_ = true; + } + return istr; } }; @@ -73,6 +114,7 @@ void create_reservation(); void rent_a_motorcycle(); void export_reservations(); +list customers; list reservations; int main() @@ -82,7 +124,7 @@ int main() system("cls"); cout << "Motorradvermietung (" << reservations.size() << " Reservierungen)" << endl << endl; cout << "Bitte w\x84hlen Sie eine Option:" << endl; - cout << "1: Erstellen eines Kunden" << endl; + cout << "1: Neuen Kunden anlegen" << endl; cout << "2: Erstellen einer Reservierung" << endl; cout << "3: Motorrad herausgeben" << endl; cout << "4: Reservierungen exportieren" << endl; @@ -112,3 +154,26 @@ int main() } } } + +void create_customer() +{ + system("cls"); + cout << "Neuen Kunden anlegen" << endl; + cout << "------------------------------------" << endl; + + customer customer; + cin >> customer; + customers.push_back(customer); +} + +void create_reservation() +{ +} + +void rent_a_motorcycle() +{ +} + +void export_reservations() +{ +} From 73900a4cabb63a5f08218a13f3d70d7855360d77 Mon Sep 17 00:00:00 2001 From: Holger Boerchers Date: Sun, 23 Dec 2018 17:45:15 +0100 Subject: [PATCH 4/4] done #1 --- src/Motorradvermietung.cpp | 105 +++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 33 deletions(-) diff --git a/src/Motorradvermietung.cpp b/src/Motorradvermietung.cpp index 4e07253..ac53dd2 100644 --- a/src/Motorradvermietung.cpp +++ b/src/Motorradvermietung.cpp @@ -4,6 +4,38 @@ using namespace std; +/** + * \brief ask a question and get a answer. + * \tparam T return parameter + * \param question the question. + * \return the value. + */ +template +T ask_question(const string& question) +{ + cout << question << ": "; + T value; + cin >> value; + return value; +} + +bool ask_question(const string& question) +{ + while (true) + { + const auto answer = ask_question(question + " (J/N)"); + if (answer == 'j' || answer == 'J') + { + return true; + } + if (answer == 'n' || answer == 'N') + { + return false; + } + cout << "Ungueltige Eigabe. Bitte noch einmal versuchen!"; + } +} + class address final { private: @@ -34,6 +66,15 @@ public: istr >> address.city_; return istr; } + + friend ostream& operator<<(ostream& ostr, const address& customer) + { + ostr << "Strasse: " << customer.street_ << endl; + ostr << "Hausnummer: " << customer.street_no_ << endl; + ostr << "Postleitzahl: " << customer.postal_code_ << endl; + ostr << "Ort: " << customer.city_ << endl; + return ostr; + } }; class reservation final @@ -57,9 +98,7 @@ private: string phone_no_; bool has_driving_license_ = false; public: - customer() - { - } + customer() = default; customer(string&& name, string&& first_name, address&& address, unsigned short&& year_of_birth, string&& phone_no, bool&& has_driving_license) : name_(name), @@ -82,32 +121,22 @@ public: istr >> customer.address_; cout << "Telefonnumer: "; istr >> customer.phone_no_; - cout << "Fuehrerschein der Klasse A? (J/N): "; - char driving_license; - istr >> driving_license; - if (driving_license == 'j' || driving_license == 'J') - { - customer.has_driving_license_ = true; - } + customer.has_driving_license_ = ask_question("Fuehrerschein der Klasse A?"); return istr; } + + friend ostream& operator<<(ostream& ostr, const customer& customer) + { + ostr << "Name: " << customer.name_ << endl; + ostr << "Vorname: " << customer.first_name_ << endl; + ostr << "Geburtsjahr: " << customer.year_of_birth_ << endl; + ostr << customer.address_; + ostr << "Telefonnummer: " << customer.phone_no_ << endl; + ostr << "Fuehrerschein " << (customer.has_driving_license_ ? "" : "nicht ") << "vorhanden." << endl; + return ostr; + } }; -/** - * \brief ask a question and get a answer. - * \tparam T return parameter - * \param question the question. - * \return the value. - */ -template -T ask_question(const string& question) -{ - cout << question << endl; - cout << "> "; - T value; - cin >> value; - return value; -} void create_customer(); void create_reservation(); @@ -122,7 +151,8 @@ int main() while (true) { system("cls"); - cout << "Motorradvermietung (" << reservations.size() << " Reservierungen)" << endl << endl; + 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; @@ -130,7 +160,7 @@ int main() cout << "4: Reservierungen exportieren" << endl; cout << endl; cout << "0: Programm beenden" << endl; - const auto input = ask_question("Ihre Eingabe:"); + const auto input = ask_question("Ihre Eingabe"); switch (input) { @@ -157,13 +187,22 @@ int main() void create_customer() { - system("cls"); - cout << "Neuen Kunden anlegen" << endl; - cout << "------------------------------------" << endl; + while (true) + { + system("cls"); + cout << "Neuen Kunden anlegen" << endl; + cout << "------------------------------------" << endl; - customer customer; - cin >> customer; - customers.push_back(customer); + customer customer; + cin >> customer; + cout << endl << endl; + cout << customer; + if (ask_question("Angaben korrekt?")) + { + customers.push_back(customer); + return; + } + } } void create_reservation()