From e9922573f00caa7bea9131f09d20c769dfa51cd3 Mon Sep 17 00:00:00 2001 From: Holger Boerchers Date: Thu, 27 Dec 2018 21:24:50 +0100 Subject: [PATCH] working on #3 --- src/Motorradvermietung.cpp | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/Motorradvermietung.cpp b/src/Motorradvermietung.cpp index fc5ccf9..36b95db 100644 --- a/src/Motorradvermietung.cpp +++ b/src/Motorradvermietung.cpp @@ -3,6 +3,7 @@ #include #include #include +#include using namespace std; @@ -477,18 +478,44 @@ 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); + struct tm buf{}; + localtime_s(&buf, &t); + const auto time = int_to_string(buf.tm_hour, 2) + + ":" + int_to_string(buf.tm_min, 2) + + ":" + int_to_string(buf.tm_sec, 2); + const auto date = int_to_string(buf.tm_mday, 2) + + "." + int_to_string(1 + buf.tm_mon, 2) + + "." + int_to_string(1900 + buf.tm_year, 4); + + return date + " " + time; +} + void export_reservations() { ofstream f; f.open("reservierungen.txt", ios::app); - f << "Export" << endl; + f << "Export (" << current_date_time() << ")" << 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_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 <