1
0

Fertig, es fehlen nur noch kommentare

This commit is contained in:
Holger Boerchers 2018-12-04 21:10:14 +01:00
parent ca5552e13c
commit d8498859f1

View File

@ -1,9 +1,13 @@
#include <iostream>
#include <list>
#include <string>
#include <map>
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 <typename T>
T ask_question(const string& question)
@ -70,23 +108,25 @@ T ask_question(const string& question)
return value;
}
list<invoice> 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<invoice> 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 << "------------------------------------"<<endl;
const auto invoice_no = invoices.empty() ? 1 : invoices.back().get_number() + 1;
cout << "------------------------------------" << endl;
const auto invoice_no = ++invoice_serial_number;
const auto amount = ask_question<double>("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:"<<endl;
cout << "------------------------------------"<<endl;
cout << "Alle Rechnungen nach Monat sortiert:" << endl;
cout << "------------------------------------" << endl;
auto temp = list<invoice>(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<int, double> 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)