From d8498859f19a0d26b3917cf62477dbde32602c23 Mon Sep 17 00:00:00 2001 From: Holger Boerchers Date: Tue, 4 Dec 2018 21:10:14 +0100 Subject: [PATCH] Fertig, es fehlen nur noch kommentare --- src/Ausgabenverwaltung.cpp | 94 ++++++++++++++++++++++++++++++-------- 1 file changed, 74 insertions(+), 20 deletions(-) diff --git a/src/Ausgabenverwaltung.cpp b/src/Ausgabenverwaltung.cpp index 6a37395..2d543b1 100644 --- a/src/Ausgabenverwaltung.cpp +++ b/src/Ausgabenverwaltung.cpp @@ -1,9 +1,13 @@ #include #include #include +#include using namespace std; +/** + * \brief invoice, which contains number, amount, month of creation and category. + */ class invoice { private: @@ -15,11 +19,17 @@ public: static const char* categories[]; static const char* months[]; - invoice(int number, double amount, unsigned short month, int category) : number_(number), amount_(amount), - month_(month), category_(category) + invoice(const int number, const double amount, const unsigned short month, const int category) : number_(number), + amount_(amount), + month_(month), + category_(category) { } + /** + * \brief Get number of invoice. + * \return number + */ int get_number() const { return number_; @@ -35,10 +45,15 @@ public: return category_; } + double get_amount() const + { + return amount_; + } + void print() const { cout << " Rechnung: " << number_ << endl; - cout << " Betrag: " << amount_ << "€" << endl; + cout << " Betrag: " << amount_ << " Euro" << endl; cout << " Monat: " << months[month_] << endl; cout << " Kategorie: " << categories[category_] << endl; } @@ -57,8 +72,31 @@ public: bool operator !=(const invoice& e) const { return !operator==(e); } }; -const char* invoice::categories[] = {"Tanken", "Nahrungsmittel", "Reinigungsmittel", "Urlaub", "Haustiere", "Bekleidung", "Wohnen", "Versicherung"}; -const char* invoice::months[] = {"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"}; +const char* invoice::categories[] = { + "Tanken", + "Nahrungsmittel", + "Reinigungsmittel", + "Urlaub", + "Haustiere", + "Bekleidung", + "Wohnen", + "Versicherung" +}; + +const char* invoice::months[] = { + "Januar", + "Februar", + "März", + "April", + "Mai", + "Juni", + "Juli", + "August", + "September", + "Oktober", + "November", + "Dezember" +}; template T ask_question(const string& question) @@ -70,23 +108,25 @@ T ask_question(const string& question) return value; } -list invoices; - void create_invoice(); -void output_invoices_order_by_month(); +void invoices_ordered_by_month(); void delete_invoice(); +void sum_invoices_per_category(); + bool compare_month_ascending(const invoice& first, const invoice& second) { return first.get_month() < second.get_month(); } +list invoices; +int invoice_serial_number; + int main() { - auto end_program = false; - while (!end_program) + while (true) { system("cls"); cout << "Ausgabenverwaltung (" << invoices.size() << " Rechnungen)" << endl << endl; @@ -105,23 +145,21 @@ int main() create_invoice(); break; case 2: - output_invoices_order_by_month(); + invoices_ordered_by_month(); break; case 3: - //TODO + sum_invoices_per_category(); break; case 4: delete_invoice(); break; case 0: - end_program = true; - break; + return 0; default: cout << "Unerlaubte Eingabe" << endl; system("pause"); } } - return 0; } int get_month(); @@ -131,8 +169,8 @@ void create_invoice() { system("cls"); cout << "Eine neue Rechnung erstellen." << endl; - cout << "------------------------------------"<("Bitte geben Sie den Betrag in Euro ein."); const auto month = get_month(); const auto category = get_category(); @@ -141,11 +179,11 @@ void create_invoice() } -void output_invoices_order_by_month() +void invoices_ordered_by_month() { system("cls"); - cout << "Alle Rechnungen nach Monat sortiert:"<(invoices); temp.sort(compare_month_ascending); for (auto invoice : temp) @@ -171,6 +209,22 @@ void delete_invoice() system("pause"); } +void sum_invoices_per_category() +{ + map sums; + for (auto invoice : invoices) + { + sums[invoice.get_category()] = sums[invoice.get_category()] += invoice.get_amount(); + } + for (const auto sum : sums) + { + cout << " Kategorie: " << invoice::categories[sum.first] << endl; + cout << " Summe: " << sum.second << " Euro" << endl; + cout << "------------------------------------" << endl; + } + system("pause"); +} + int get_month() { while (true)