working on #5
This commit is contained in:
parent
e57a04aae2
commit
0bcc421678
@ -1,10 +1,15 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
|
#include <utility>
|
||||||
|
#include <vector>
|
||||||
#include <experimental/filesystem>
|
#include <experimental/filesystem>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
int next_customer_id;
|
||||||
|
int next_reservation_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief ask a question and get a answer.
|
* \brief ask a question and get a answer.
|
||||||
* \tparam T return parameter
|
* \tparam T return parameter
|
||||||
@ -78,20 +83,10 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class reservation final
|
|
||||||
{
|
|
||||||
private:
|
|
||||||
tm start_ = {};
|
|
||||||
tm end_ = {};
|
|
||||||
short motorcycle_ = -1; // => -1 means nothing reserved
|
|
||||||
string customer_name_;
|
|
||||||
string costumer_first_name_;
|
|
||||||
public:
|
|
||||||
};
|
|
||||||
|
|
||||||
class customer final
|
class customer final
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
int id_;
|
||||||
string name_;
|
string name_;
|
||||||
string first_name_;
|
string first_name_;
|
||||||
address address_;
|
address address_;
|
||||||
@ -99,10 +94,13 @@ private:
|
|||||||
string phone_no_;
|
string phone_no_;
|
||||||
bool has_driving_license_ = false;
|
bool has_driving_license_ = false;
|
||||||
public:
|
public:
|
||||||
customer() = default;
|
customer() : id_(++next_customer_id)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
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) : id_(++next_customer_id),
|
||||||
|
name_(name),
|
||||||
first_name_(first_name),
|
first_name_(first_name),
|
||||||
address_(address),
|
address_(address),
|
||||||
year_of_birth_(year_of_birth),
|
year_of_birth_(year_of_birth),
|
||||||
@ -111,18 +109,18 @@ public:
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
friend istream& operator>>(istream& istr, customer& customer)
|
friend istream& operator>>(istream& istr, customer*& customer)
|
||||||
{
|
{
|
||||||
cout << "Name: ";
|
cout << "Name: ";
|
||||||
istr >> customer.name_;
|
istr >> customer->name_;
|
||||||
cout << "Vorname: ";
|
cout << "Vorname: ";
|
||||||
istr >> customer.first_name_;
|
istr >> customer->first_name_;
|
||||||
cout << "Geburtsjahr: ";
|
cout << "Geburtsjahr: ";
|
||||||
istr >> customer.year_of_birth_;
|
istr >> customer->year_of_birth_;
|
||||||
istr >> customer.address_;
|
istr >> customer->address_;
|
||||||
cout << "Telefonnumer: ";
|
cout << "Telefonnumer: ";
|
||||||
istr >> customer.phone_no_;
|
istr >> customer->phone_no_;
|
||||||
customer.has_driving_license_ = ask_question("Fuehrerschein der Klasse A?");
|
customer->has_driving_license_ = ask_question("Fuehrerschein der Klasse A?");
|
||||||
return istr;
|
return istr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,6 +134,35 @@ public:
|
|||||||
ostr << "Fuehrerschein " << (customer.has_driving_license_ ? "" : "nicht ") << "vorhanden." << endl;
|
ostr << "Fuehrerschein " << (customer.has_driving_license_ ? "" : "nicht ") << "vorhanden." << endl;
|
||||||
return ostr;
|
return ostr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string get_name() const
|
||||||
|
{
|
||||||
|
return this->name_;
|
||||||
|
}
|
||||||
|
|
||||||
|
string get_first_name() const
|
||||||
|
{
|
||||||
|
return this->first_name_;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class reservation final
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
int id_;
|
||||||
|
string start_ = {};
|
||||||
|
string end_ = {};
|
||||||
|
short motorcycle_ = -1; // => -1 means nothing reserved
|
||||||
|
customer* customer_;
|
||||||
|
public:
|
||||||
|
reservation(string start, string end, const short motorcycle, customer* customer) : id_(++next_reservation_id),
|
||||||
|
start_(
|
||||||
|
std::move(start)), end_(
|
||||||
|
std::move(end)),
|
||||||
|
motorcycle_(motorcycle),
|
||||||
|
customer_(customer)
|
||||||
|
{
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
string motorcycles[] = {
|
string motorcycles[] = {
|
||||||
@ -145,6 +172,8 @@ string motorcycles[] = {
|
|||||||
"Kawasaki ZZR1400"
|
"Kawasaki ZZR1400"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
list<customer*> customers;
|
||||||
|
list<reservation*> reservations;
|
||||||
int size_of_motorcycles = 4;
|
int size_of_motorcycles = 4;
|
||||||
|
|
||||||
void create_customer();
|
void create_customer();
|
||||||
@ -152,9 +181,6 @@ void create_reservation();
|
|||||||
void rent_a_motorcycle();
|
void rent_a_motorcycle();
|
||||||
void export_reservations();
|
void export_reservations();
|
||||||
|
|
||||||
list<customer> customers;
|
|
||||||
list<reservation> reservations;
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -211,20 +237,102 @@ void create_customer()
|
|||||||
cout << "Neuen Kunden anlegen" << endl;
|
cout << "Neuen Kunden anlegen" << endl;
|
||||||
cout << "------------------------------------" << endl;
|
cout << "------------------------------------" << endl;
|
||||||
|
|
||||||
customer customer;
|
auto c = new customer;
|
||||||
cin >> customer;
|
cin >> c;
|
||||||
cout << endl << endl;
|
cout << endl << endl;
|
||||||
cout << customer;
|
cout << *c;
|
||||||
if (ask_question("Angaben korrekt?"))
|
if (ask_question("Angaben korrekt?"))
|
||||||
{
|
{
|
||||||
customers.push_back(customer);
|
customers.push_back(c);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
vector<customer*> find_customers_by_name(const string& name)
|
||||||
|
{
|
||||||
|
vector<customer*> result;
|
||||||
|
for (auto customer : customers)
|
||||||
|
{
|
||||||
|
if (customer->get_name() == name)
|
||||||
|
{
|
||||||
|
result.push_back(customer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool validate_date(string& date)
|
||||||
|
{
|
||||||
|
auto day = 0, month = 0, year = 0;
|
||||||
|
const auto res = sscanf_s(date.c_str(), "%2d.%2d.%4d",
|
||||||
|
&day,
|
||||||
|
&month,
|
||||||
|
&year);
|
||||||
|
if (res != 3) return false;
|
||||||
|
if (month < 1 || month > 12) return false;
|
||||||
|
if (day < 1 || day > 31) return false;
|
||||||
|
if (year < 1900 || month > 2200) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
string get_validated_date(const string&& question)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
auto date = ask_question<string>(question + " (tt.mm.jjjj)");
|
||||||
|
if (validate_date(date))
|
||||||
|
{
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
cout << "Fehlerhafte Eingabe." << endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
customer* find_customer_by_first_name(const vector<customer*>& filtered_customers, const string& first_name)
|
||||||
|
{
|
||||||
|
for (auto c : filtered_customers)
|
||||||
|
{
|
||||||
|
if (c->get_first_name() == first_name)
|
||||||
|
{
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
void create_reservation()
|
void create_reservation()
|
||||||
{
|
{
|
||||||
|
system("cls");
|
||||||
|
const auto name = ask_question<string>("Name des Kunden");
|
||||||
|
auto customers = find_customers_by_name(name);
|
||||||
|
customer* current;
|
||||||
|
if (customers.size() > 1)
|
||||||
|
{
|
||||||
|
const auto first_name = ask_question<string>("Vorname des Kunden");
|
||||||
|
current = find_customer_by_first_name(customers, first_name);
|
||||||
|
if (current == nullptr)
|
||||||
|
{
|
||||||
|
cout << "Kunde nicht gefunden" << endl;
|
||||||
|
system("pause");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (customers.empty())
|
||||||
|
{
|
||||||
|
cout << "Kunde nicht gefunden" << endl;
|
||||||
|
system("pause");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
current = customers.front();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto start_date = get_validated_date("Startdatum");
|
||||||
|
const auto end_date = get_validated_date("Enddatum");
|
||||||
|
auto r = reservation(start_date, end_date, 2, current);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rent_a_motorcycle()
|
void rent_a_motorcycle()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user