Fertig, es fehlen nur noch kommentare
This commit is contained in:
parent
ca5552e13c
commit
d8498859f1
@ -1,9 +1,13 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief invoice, which contains number, amount, month of creation and category.
|
||||||
|
*/
|
||||||
class invoice
|
class invoice
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
@ -15,11 +19,17 @@ public:
|
|||||||
static const char* categories[];
|
static const char* categories[];
|
||||||
static const char* months[];
|
static const char* months[];
|
||||||
|
|
||||||
invoice(int number, double amount, unsigned short month, int category) : number_(number), amount_(amount),
|
invoice(const int number, const double amount, const unsigned short month, const int category) : number_(number),
|
||||||
month_(month), category_(category)
|
amount_(amount),
|
||||||
|
month_(month),
|
||||||
|
category_(category)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Get number of invoice.
|
||||||
|
* \return number
|
||||||
|
*/
|
||||||
int get_number() const
|
int get_number() const
|
||||||
{
|
{
|
||||||
return number_;
|
return number_;
|
||||||
@ -35,10 +45,15 @@ public:
|
|||||||
return category_;
|
return category_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double get_amount() const
|
||||||
|
{
|
||||||
|
return amount_;
|
||||||
|
}
|
||||||
|
|
||||||
void print() const
|
void print() const
|
||||||
{
|
{
|
||||||
cout << " Rechnung: " << number_ << endl;
|
cout << " Rechnung: " << number_ << endl;
|
||||||
cout << " Betrag: " << amount_ << "€" << endl;
|
cout << " Betrag: " << amount_ << " Euro" << endl;
|
||||||
cout << " Monat: " << months[month_] << endl;
|
cout << " Monat: " << months[month_] << endl;
|
||||||
cout << " Kategorie: " << categories[category_] << endl;
|
cout << " Kategorie: " << categories[category_] << endl;
|
||||||
}
|
}
|
||||||
@ -57,8 +72,31 @@ public:
|
|||||||
bool operator !=(const invoice& e) const { return !operator==(e); }
|
bool operator !=(const invoice& e) const { return !operator==(e); }
|
||||||
};
|
};
|
||||||
|
|
||||||
const char* invoice::categories[] = {"Tanken", "Nahrungsmittel", "Reinigungsmittel", "Urlaub", "Haustiere", "Bekleidung", "Wohnen", "Versicherung"};
|
const char* invoice::categories[] = {
|
||||||
const char* invoice::months[] = {"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"};
|
"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>
|
template <typename T>
|
||||||
T ask_question(const string& question)
|
T ask_question(const string& question)
|
||||||
@ -70,23 +108,25 @@ T ask_question(const string& question)
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
list<invoice> invoices;
|
|
||||||
|
|
||||||
void create_invoice();
|
void create_invoice();
|
||||||
|
|
||||||
void output_invoices_order_by_month();
|
void invoices_ordered_by_month();
|
||||||
|
|
||||||
void delete_invoice();
|
void delete_invoice();
|
||||||
|
|
||||||
|
void sum_invoices_per_category();
|
||||||
|
|
||||||
bool compare_month_ascending(const invoice& first, const invoice& second)
|
bool compare_month_ascending(const invoice& first, const invoice& second)
|
||||||
{
|
{
|
||||||
return first.get_month() < second.get_month();
|
return first.get_month() < second.get_month();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
list<invoice> invoices;
|
||||||
|
int invoice_serial_number;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
auto end_program = false;
|
while (true)
|
||||||
while (!end_program)
|
|
||||||
{
|
{
|
||||||
system("cls");
|
system("cls");
|
||||||
cout << "Ausgabenverwaltung (" << invoices.size() << " Rechnungen)" << endl << endl;
|
cout << "Ausgabenverwaltung (" << invoices.size() << " Rechnungen)" << endl << endl;
|
||||||
@ -105,23 +145,21 @@ int main()
|
|||||||
create_invoice();
|
create_invoice();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
output_invoices_order_by_month();
|
invoices_ordered_by_month();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
//TODO
|
sum_invoices_per_category();
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
delete_invoice();
|
delete_invoice();
|
||||||
break;
|
break;
|
||||||
case 0:
|
case 0:
|
||||||
end_program = true;
|
return 0;
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
cout << "Unerlaubte Eingabe" << endl;
|
cout << "Unerlaubte Eingabe" << endl;
|
||||||
system("pause");
|
system("pause");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int get_month();
|
int get_month();
|
||||||
@ -132,7 +170,7 @@ void create_invoice()
|
|||||||
system("cls");
|
system("cls");
|
||||||
cout << "Eine neue Rechnung erstellen." << endl;
|
cout << "Eine neue Rechnung erstellen." << endl;
|
||||||
cout << "------------------------------------" << endl;
|
cout << "------------------------------------" << endl;
|
||||||
const auto invoice_no = invoices.empty() ? 1 : invoices.back().get_number() + 1;
|
const auto invoice_no = ++invoice_serial_number;
|
||||||
const 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.");
|
||||||
const auto month = get_month();
|
const auto month = get_month();
|
||||||
const auto category = get_category();
|
const auto category = get_category();
|
||||||
@ -141,7 +179,7 @@ void create_invoice()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void output_invoices_order_by_month()
|
void invoices_ordered_by_month()
|
||||||
{
|
{
|
||||||
system("cls");
|
system("cls");
|
||||||
cout << "Alle Rechnungen nach Monat sortiert:" << endl;
|
cout << "Alle Rechnungen nach Monat sortiert:" << endl;
|
||||||
@ -171,6 +209,22 @@ void delete_invoice()
|
|||||||
system("pause");
|
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()
|
int get_month()
|
||||||
{
|
{
|
||||||
while (true)
|
while (true)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user