almost done. comments are missing
This commit is contained in:
parent
e9922573f0
commit
8992990dc5
@ -1,9 +1,9 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
#include <fstream>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
|
||||
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
|
||||
{
|
||||
private:
|
||||
unsigned short day_;
|
||||
unsigned short month_;
|
||||
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:
|
||||
date(const unsigned short day, const unsigned short month, const unsigned short year) : day_(day), month_(month),
|
||||
year_(year)
|
||||
{
|
||||
sum_ = day_number_from_date();
|
||||
}
|
||||
|
||||
int get_sum() const
|
||||
{
|
||||
return year_ + month_ + day_;
|
||||
return sum_;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
@ -161,12 +184,17 @@ public:
|
||||
|
||||
string get_name() const
|
||||
{
|
||||
return this->name_;
|
||||
return name_;
|
||||
}
|
||||
|
||||
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_;
|
||||
}
|
||||
|
||||
bool get_cancellation() const
|
||||
{
|
||||
return canceled_;
|
||||
}
|
||||
};
|
||||
|
||||
string motorcycles[] =
|
||||
@ -419,6 +452,12 @@ void create_reservation()
|
||||
system("pause");
|
||||
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 end_date = get_validated_date("Enddatum");
|
||||
const auto motorcycle = select_motorcycle();
|
||||
@ -478,17 +517,6 @@ void rent_a_motorcycle()
|
||||
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()
|
||||
{
|
||||
auto t = time(nullptr);
|
||||
@ -509,13 +537,16 @@ void export_reservations()
|
||||
ofstream f;
|
||||
f.open("reservierungen.txt", ios::app);
|
||||
f << "Export (" << current_date_time() << ")" << endl;
|
||||
f << "Id;Motorcycle;Start;End;Name;First_Name;Cancelled" << endl;
|
||||
for (auto reservation : reservations)
|
||||
{
|
||||
f << reservation->get_id() << ". ";
|
||||
f << motorcycles[reservation->get_motorcycle()] << " ";
|
||||
f << reservation->get_start_date() << " - " << reservation->get_end_date() << " ";
|
||||
f << reservation->get_customer()->get_first_name() << " " << reservation->get_customer()->get_name();
|
||||
f << endl;
|
||||
f << reservation->get_id() << ";";
|
||||
f << motorcycles[reservation->get_motorcycle()] << ";";
|
||||
f << reservation->get_start_date() << ";";
|
||||
f << reservation->get_end_date() << ";";
|
||||
f << reservation->get_customer()->get_name() << ";";
|
||||
f << reservation->get_customer()->get_first_name() << ";";
|
||||
f << (reservation->get_cancellation() ? "True" : "False") << endl;
|
||||
}
|
||||
f << "------------" << endl;
|
||||
f.close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user