almost done. comments are missing

This commit is contained in:
Holger Boerchers 2018-12-27 22:29:11 +01:00
parent e9922573f0
commit 8992990dc5

View File

@ -1,9 +1,9 @@
#include <iostream> #include <iostream>
#include <string>
#include <list> #include <list>
#include <vector> #include <vector>
#include <fstream>
#include <ctime> #include <ctime>
#include <string>
#include <fstream>
using namespace std; using namespace std;
@ -42,26 +42,49 @@ bool ask_question(const string& question)
} }
} }
auto int_to_string(const unsigned int value, const unsigned int numbers = 0) -> string
{
auto str = to_string(value);
const auto len = numbers > str.length() ? numbers - str.length() : 0;
for (unsigned int i = 0; i < len; ++i)
{
str.insert(0, "0");
}
return str;
}
class date final class date final
{ {
private: private:
unsigned short day_; unsigned short day_;
unsigned short month_; unsigned short month_;
unsigned short year_; unsigned short year_;
int sum_;
int day_number_from_date() const
{
const auto month = (month_ + 9) % 12;
const auto year = year_ - month / 10;
return 365 * year + year / 4 - year / 100 + year / 400 + (month * 306 + 5) / 10 + (day_ - 1);
}
public: public:
date(const unsigned short day, const unsigned short month, const unsigned short year) : day_(day), month_(month), date(const unsigned short day, const unsigned short month, const unsigned short year) : day_(day), month_(month),
year_(year) year_(year)
{ {
sum_ = day_number_from_date();
} }
int get_sum() const int get_sum() const
{ {
return year_ + month_ + day_; return sum_;
} }
friend ostream& operator<<(ostream& ostr, const date& date) friend ostream& operator<<(ostream& ostr, const date& date)
{ {
ostr << date.day_ << "." << date.month_ << "." << date.year_; ostr << int_to_string(date.day_, 2) << "."
<< int_to_string(date.month_, 2) << "."
<< int_to_string(date.year_, 4);
return ostr; return ostr;
} }
}; };
@ -161,12 +184,17 @@ public:
string get_name() const string get_name() const
{ {
return this->name_; return name_;
} }
string get_first_name() const string get_first_name() const
{ {
return this->first_name_; return first_name_;
}
bool get_has_driving_license() const
{
return has_driving_license_;
} }
}; };
@ -219,6 +247,11 @@ public:
{ {
return id_; return id_;
} }
bool get_cancellation() const
{
return canceled_;
}
}; };
string motorcycles[] = string motorcycles[] =
@ -419,6 +452,12 @@ void create_reservation()
system("pause"); system("pause");
return; return;
} }
if(!current->get_has_driving_license())
{
cout << "Der Kunde hat keinen entsprechenden Fuehrerschein." << endl;
system("pause");
return;
}
const auto start_date = get_validated_date("Startdatum"); const auto start_date = get_validated_date("Startdatum");
const auto end_date = get_validated_date("Enddatum"); const auto end_date = get_validated_date("Enddatum");
const auto motorcycle = select_motorcycle(); const auto motorcycle = select_motorcycle();
@ -478,17 +517,6 @@ void rent_a_motorcycle()
system("pause"); system("pause");
} }
auto int_to_string(const int value, const unsigned int numbers = 0) -> string
{
auto str = to_string(value);
const auto len = numbers - str.length();
for (unsigned int i = 0; i < len; ++i)
{
str.insert(0, "0");
}
return str;
}
string current_date_time() string current_date_time()
{ {
auto t = time(nullptr); auto t = time(nullptr);
@ -509,13 +537,16 @@ void export_reservations()
ofstream f; ofstream f;
f.open("reservierungen.txt", ios::app); f.open("reservierungen.txt", ios::app);
f << "Export (" << current_date_time() << ")" << endl; f << "Export (" << current_date_time() << ")" << endl;
f << "Id;Motorcycle;Start;End;Name;First_Name;Cancelled" << endl;
for (auto reservation : reservations) for (auto reservation : reservations)
{ {
f << reservation->get_id() << ". "; f << reservation->get_id() << ";";
f << motorcycles[reservation->get_motorcycle()] << " "; f << motorcycles[reservation->get_motorcycle()] << ";";
f << reservation->get_start_date() << " - " << reservation->get_end_date() << " "; f << reservation->get_start_date() << ";";
f << reservation->get_customer()->get_first_name() << " " << reservation->get_customer()->get_name(); f << reservation->get_end_date() << ";";
f << endl; f << reservation->get_customer()->get_name() << ";";
f << reservation->get_customer()->get_first_name() << ";";
f << (reservation->get_cancellation() ? "True" : "False") << endl;
} }
f << "------------" << endl; f << "------------" << endl;
f.close(); f.close();