Kunde erstellen #6
@ -1,8 +1,41 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
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
|
||||
{
|
||||
private:
|
||||
@ -11,12 +44,48 @@ 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;
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
private:
|
||||
tm start_ = {};
|
||||
tm end_ = {};
|
||||
short motorcycle_ = -1; // => nothing reserved
|
||||
string customer_name_;
|
||||
string costumer_first_name_;
|
||||
public:
|
||||
};
|
||||
|
||||
class customer final
|
||||
@ -28,20 +97,122 @@ 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),
|
||||
address_(address),
|
||||
year_of_birth_(year_of_birth),
|
||||
phone_no_(phone_no),
|
||||
has_driving_license_(has_driving_license)
|
||||
customer() = default;
|
||||
|
||||
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_;
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
void create_customer();
|
||||
void create_reservation();
|
||||
void rent_a_motorcycle();
|
||||
void export_reservations();
|
||||
|
||||
list<customer> customers;
|
||||
list<reservation> reservations;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Hello World!\n";
|
||||
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<int>("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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void create_customer()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
system("cls");
|
||||
cout << "Neuen Kunden anlegen" << endl;
|
||||
cout << "------------------------------------" << endl;
|
||||
|
||||
customer customer;
|
||||
cin >> customer;
|
||||
cout << endl << endl;
|
||||
cout << customer;
|
||||
if (ask_question("Angaben korrekt?"))
|
||||
{
|
||||
customers.push_back(customer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void create_reservation()
|
||||
{
|
||||
}
|
||||
|
||||
void rent_a_motorcycle()
|
||||
{
|
||||
}
|
||||
|
||||
void export_reservations()
|
||||
{
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user