done #1
This commit is contained in:
parent
ae5b12e235
commit
73900a4cab
@ -4,6 +4,38 @@
|
|||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief ask a question and get a answer.
|
||||||
|
* \tparam T return parameter
|
||||||
|
* \param question the question.
|
||||||
|
* \return the value.
|
||||||
|
*/
|
||||||
|
template <typename T>
|
||||||
|
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<char>(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
|
class address final
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -34,6 +66,15 @@ public:
|
|||||||
istr >> address.city_;
|
istr >> address.city_;
|
||||||
return istr;
|
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
|
class reservation final
|
||||||
@ -57,9 +98,7 @@ private:
|
|||||||
string phone_no_;
|
string phone_no_;
|
||||||
bool has_driving_license_ = false;
|
bool has_driving_license_ = false;
|
||||||
public:
|
public:
|
||||||
customer()
|
customer() = default;
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
customer(string&& name, string&& first_name, address&& address, unsigned short&& year_of_birth, string&& phone_no,
|
customer(string&& name, string&& first_name, address&& address, unsigned short&& year_of_birth, string&& phone_no,
|
||||||
bool&& has_driving_license) : name_(name),
|
bool&& has_driving_license) : name_(name),
|
||||||
@ -82,32 +121,22 @@ public:
|
|||||||
istr >> customer.address_;
|
istr >> customer.address_;
|
||||||
cout << "Telefonnumer: ";
|
cout << "Telefonnumer: ";
|
||||||
istr >> customer.phone_no_;
|
istr >> customer.phone_no_;
|
||||||
cout << "Fuehrerschein der Klasse A? (J/N): ";
|
customer.has_driving_license_ = ask_question("Fuehrerschein der Klasse A?");
|
||||||
char driving_license;
|
|
||||||
istr >> driving_license;
|
|
||||||
if (driving_license == 'j' || driving_license == 'J')
|
|
||||||
{
|
|
||||||
customer.has_driving_license_ = true;
|
|
||||||
}
|
|
||||||
return istr;
|
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 <typename T>
|
|
||||||
T ask_question(const string& question)
|
|
||||||
{
|
|
||||||
cout << question << endl;
|
|
||||||
cout << "> ";
|
|
||||||
T value;
|
|
||||||
cin >> value;
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void create_customer();
|
void create_customer();
|
||||||
void create_reservation();
|
void create_reservation();
|
||||||
@ -122,7 +151,8 @@ int main()
|
|||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
system("cls");
|
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 << "Bitte w\x84hlen Sie eine Option:" << endl;
|
||||||
cout << "1: Neuen Kunden anlegen" << endl;
|
cout << "1: Neuen Kunden anlegen" << endl;
|
||||||
cout << "2: Erstellen einer Reservierung" << endl;
|
cout << "2: Erstellen einer Reservierung" << endl;
|
||||||
@ -130,7 +160,7 @@ int main()
|
|||||||
cout << "4: Reservierungen exportieren" << endl;
|
cout << "4: Reservierungen exportieren" << endl;
|
||||||
cout << endl;
|
cout << endl;
|
||||||
cout << "0: Programm beenden" << endl;
|
cout << "0: Programm beenden" << endl;
|
||||||
const auto input = ask_question<int>("Ihre Eingabe:");
|
const auto input = ask_question<int>("Ihre Eingabe");
|
||||||
|
|
||||||
switch (input)
|
switch (input)
|
||||||
{
|
{
|
||||||
@ -157,13 +187,22 @@ int main()
|
|||||||
|
|
||||||
void create_customer()
|
void create_customer()
|
||||||
{
|
{
|
||||||
system("cls");
|
while (true)
|
||||||
cout << "Neuen Kunden anlegen" << endl;
|
{
|
||||||
cout << "------------------------------------" << endl;
|
system("cls");
|
||||||
|
cout << "Neuen Kunden anlegen" << endl;
|
||||||
|
cout << "------------------------------------" << endl;
|
||||||
|
|
||||||
customer customer;
|
customer customer;
|
||||||
cin >> customer;
|
cin >> customer;
|
||||||
customers.push_back(customer);
|
cout << endl << endl;
|
||||||
|
cout << customer;
|
||||||
|
if (ask_question("Angaben korrekt?"))
|
||||||
|
{
|
||||||
|
customers.push_back(customer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void create_reservation()
|
void create_reservation()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user