working on #3

This commit is contained in:
Holger Boerchers 2018-12-27 21:24:50 +01:00
parent 91b63b022f
commit e9922573f0

View File

@ -3,6 +3,7 @@
#include <list> #include <list>
#include <vector> #include <vector>
#include <fstream> #include <fstream>
#include <ctime>
using namespace std; using namespace std;
@ -477,18 +478,44 @@ 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()
{
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() void export_reservations()
{ {
ofstream f; ofstream f;
f.open("reservierungen.txt", ios::app); f.open("reservierungen.txt", ios::app);
f << "Export" << endl; f << "Export (" << current_date_time() << ")" << 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() << " - " << reservation->get_end_date() << " ";
f << reservation->get_customer()->get_first_name() << " " << reservation->get_customer()->get_name(); f << reservation->get_customer()->get_first_name() << " " << reservation->get_customer()->get_name();
f <<endl; f << endl;
} }
f << "------------" << endl; f << "------------" << endl;
f.close(); f.close();