1
0

more useful functionality

This commit is contained in:
Holger Boerchers 2018-11-30 21:52:31 +01:00
parent e3031ebbe3
commit 34faba5bd9

View File

@ -1,4 +1,4 @@
#include <iostream> #include <iostream>
#include <list> #include <list>
#include <string> #include <string>
@ -34,6 +34,38 @@ public:
{ {
return number_; return number_;
} }
unsigned short get_month() const
{
return month_;
}
category get_category() const
{
return category_;
}
void print() const
{
cout << "Rechnung: " << number_ << endl;
cout << "Betrag: " << amount_ << endl;
cout << "Monat: " << month_ << endl;
cout << "Kategorie: " << category_ << endl;
}
/**
* \brief Implements the equality operator.
*/
bool operator ==(const Invoice& e) const
{
return number_ == e.number_;
}
/**
* \brief Implements the inequality operator.
*/
bool operator !=(const Invoice& e) const { return !operator==(e); }
}; };
template <typename T> template <typename T>
@ -50,9 +82,19 @@ list<Invoice> invoices;
void create_invoice(); void create_invoice();
void output_invoice_per_month(); void output_invoices(list<Invoice> sorted_invoices);
void output_invoice_per_category(); void delete_invoice();
bool compare_category_ascending(const Invoice& first, const Invoice& second)
{
return first.get_category() < second.get_category();
}
bool compare_month_ascending(const Invoice& first, const Invoice& second)
{
return first.get_month() < second.get_month();
}
int main() int main()
{ {
@ -66,8 +108,9 @@ int main()
cout << "2: Alle Ausgaben, sortiert nach Monat, ausgeben" << endl; cout << "2: Alle Ausgaben, sortiert nach Monat, ausgeben" << endl;
cout << "3: Summe der Ausgaben pro Kategorie ausgeben" << endl; cout << "3: Summe der Ausgaben pro Kategorie ausgeben" << endl;
cout << "4: Rechnung l\x94schen" << endl; cout << "4: Rechnung l\x94schen" << endl;
cout << endl;
cout << "0: Programm beenden" << endl; cout << "0: Programm beenden" << endl;
auto input = ask_question<int>("Ihre Eingabe:"); const auto input = ask_question<int>("Ihre Eingabe:");
switch (input) switch (input)
{ {
@ -75,10 +118,21 @@ int main()
create_invoice(); create_invoice();
break; break;
case 2: case 2:
output_invoice_per_month(); {
auto temp = list<Invoice>(invoices);
temp.sort(compare_month_ascending);
output_invoices(temp);
}
break; break;
case 3: case 3:
output_invoice_per_category(); {
auto temp = list<Invoice>(invoices);
temp.sort(compare_category_ascending);
output_invoices(temp);
}
break;
case 4:
delete_invoice();
break; break;
case 0: case 0:
end_program = true; end_program = true;
@ -96,20 +150,38 @@ category get_category();
void create_invoice() void create_invoice()
{ {
cout << "Eine neue Rechnung erstellen." << endl << endl; cout << "Eine neue Rechnung erstellen." << endl << endl;
auto invoice_no = invoices.empty() ? 1 : invoices.back().get_number() + 1; const auto invoice_no = invoices.empty() ? 1 : invoices.back().get_number() + 1;
auto amount = ask_question<double>("Bitte geben Sie den Betrag in Euro ein."); const auto amount = ask_question<double>("Bitte geben Sie den Betrag in Euro ein.");
auto month = ask_question<unsigned short>("Bitte geben Sie den Monat ein."); const auto month = ask_question<unsigned short>("Bitte geben Sie den Monat ein.");
const auto category = get_category(); const auto category = get_category();
const auto i = Invoice(invoice_no, amount, month, category); const auto i = Invoice(invoice_no, amount, month, category);
invoices.push_back(i); invoices.push_back(i);
} }
void output_invoice_per_month()
void output_invoices(const list<Invoice> sorted_invoices)
{ {
for (auto invoice : sorted_invoices)
{
invoice.print();
cout << "--------------" << endl;
}
system("pause");
} }
void output_invoice_per_category() void delete_invoice()
{ {
auto invoice_number = ask_question<int>("Bitte geben Sie die Rechnungsnummer ein");
for (auto invoice : invoices)
{
if(invoice.get_number() == invoice_number)
{
invoices.remove(invoice);
return;
}
}
cout << "Rechnung nicht gefunden." << endl;
system("pause");
} }
category get_category() category get_category()
@ -130,6 +202,6 @@ category get_category()
{ {
return static_cast<category>(cat); return static_cast<category>(cat);
} }
cout << "Ung\x81ltige Eingabe"; cout << "Ung\x81ltige Eingabe" << endl << endl;
} }
} }