comments...

This commit is contained in:
Holger Börchers 2018-12-29 14:22:02 +01:00
parent c5d7a7eb60
commit 89431aa4c5

View File

@ -324,22 +324,36 @@ public:
return customer_; return customer_;
} }
/**
* \brief Cancel reservation -> Give Motorcycle to the customer
*/
void cancel_reservation() void cancel_reservation()
{ {
canceled_ = true; canceled_ = true;
} }
/**
* \brief Get Id of the item
* \return Auto-incremented id as integer
*/
int get_id() const int get_id() const
{ {
return id_; return id_;
} }
/**
* \brief get cancellation status of the reservation
* \return True is canceled. False otherwise.
*/
bool get_cancellation() const bool get_cancellation() const
{ {
return canceled_; return canceled_;
} }
}; };
/**
* \brief All available motorcycles
*/
string motorcycles[] = string motorcycles[] =
{ {
"Suzuki Bandit", "Suzuki Bandit",
@ -348,61 +362,92 @@ string motorcycles[] =
"Kawasaki ZZR1400" "Kawasaki ZZR1400"
}; };
/**
* \brief Collection of customer-pointers
*/
list<customer*> customers; list<customer*> customers;
/**
* \brief Collection of reservation pointers.
*/
list<reservation*> reservations; list<reservation*> reservations;
/**
* \brief Creates a new customer, let the user check the input and push it on the list.
*/
void create_customer(); void create_customer();
void create_reservation(); void create_reservation();
void rent_a_motorcycle(); void rent_a_motorcycle();
void export_reservations(); void export_reservations();
void main_menu();
/**
* \brief Main entry method. Starts the main menu.
* \return success code
*/
int main() int main()
{ {
try main_menu();
{ return 0;
while (true)
{
system("cls");
cout << "Motorradvermietung (" << reservations.size() << " Reservierungen; " << customers.size() <<
" Kunden)"
<< endl << endl;
cout << "Bitte w\x84hlen Sie eine Option:" << endl;
cout << "1: Neuen Kunden anlegen" << endl;
cout << "2: Erstellen einer Reservierung" << endl;
cout << "3: Motorrad herausgeben" << endl;
cout << "4: Reservierungen exportieren" << endl;
cout << endl;
cout << "0: Programm beenden" << endl;
const auto input = ask_question<int>("Ihre Eingabe");
switch (input)
{
case 1:
create_customer();
break;
case 2:
create_reservation();
break;
case 3:
rent_a_motorcycle();
break;
case 4:
export_reservations();
break;
case 0:
return 0;
default:
cout << "Unerlaubte Eingabe" << endl;
system("pause");
}
}
}
catch (...)
{
cout << "Etwas unvorhergesehendes ist passiert. Tut mir leid." << endl;
system("pause");
}
} }
/**
* \brief Let the user choice an option.
*/
void main_menu()
{
try
{
while (true)
{
system("cls");
cout << "Motorradvermietung (" << reservations.size() << " Reservierungen; " << customers.size() <<
" Kunden)"
<< endl << endl;
cout << "Bitte w\x84hlen Sie eine Option:" << endl;
cout << "1: Neuen Kunden anlegen" << endl;
cout << "2: Erstellen einer Reservierung" << endl;
cout << "3: Motorrad herausgeben" << endl;
cout << "4: Reservierungen exportieren" << endl;
cout << endl;
cout << "0: Programm beenden" << endl;
const auto input = ask_question<int>("Ihre Eingabe");
switch (input)
{
case 1:
create_customer();
break;
case 2:
create_reservation();
break;
case 3:
rent_a_motorcycle();
break;
case 4:
export_reservations();
break;
case 0:
{
return;
}
default:
cout << "Unerlaubte Eingabe" << endl;
system("pause");
}
}
}
catch (...)
{
cout << "Etwas unvorhergesehendes ist passiert. Tut mir leid." << endl;
system("pause");
}
}
/**
* \brief Creates a new customer, let the user check the input and push it on the list.
*/
void create_customer() void create_customer()
{ {
while (true) while (true)
@ -424,6 +469,11 @@ void create_customer()
} }
/**
* \brief Finds customers by last name
* \param name Last name
* \return Returns a vector of customers with the same last name
*/
vector<customer*> find_customers_by_name(const string& name) vector<customer*> find_customers_by_name(const string& name)
{ {
vector<customer*> result; vector<customer*> result;
@ -437,6 +487,29 @@ vector<customer*> find_customers_by_name(const string& name)
return result; return result;
} }
/**
* \brief Find the first customer by first name.
* \param filtered_customers A vector of customers with the same last name
* \param first_name The first name
* \return The first customer with the matching first name. If no customer found, it returns a nullptr
*/
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;
}
/**
* \brief Gets the validated date
* \param question Question to ask the user
* \return A date object.
*/
date get_validated_date(const string&& question) date get_validated_date(const string&& question)
{ {
while (true) while (true)
@ -461,18 +534,6 @@ date get_validated_date(const string&& question)
} }
} }
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;
}
int select_motorcycle() int select_motorcycle()
{ {
while (true) while (true)