more useful functionality
This commit is contained in:
parent
e3031ebbe3
commit
34faba5bd9
@ -1,4 +1,4 @@
|
||||
#include <iostream>
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <string>
|
||||
|
||||
@ -26,7 +26,7 @@ private:
|
||||
category category_ = None;
|
||||
public:
|
||||
Invoice(int number, double amount, unsigned short month, category category) : number_(number), amount_(amount),
|
||||
month_(month), category_(category)
|
||||
month_(month), category_(category)
|
||||
{
|
||||
}
|
||||
|
||||
@ -34,6 +34,38 @@ public:
|
||||
{
|
||||
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>
|
||||
@ -50,9 +82,19 @@ list<Invoice> invoices;
|
||||
|
||||
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()
|
||||
{
|
||||
@ -66,8 +108,9 @@ int main()
|
||||
cout << "2: Alle Ausgaben, sortiert nach Monat, ausgeben" << endl;
|
||||
cout << "3: Summe der Ausgaben pro Kategorie ausgeben" << endl;
|
||||
cout << "4: Rechnung l\x94schen" << endl;
|
||||
cout << endl;
|
||||
cout << "0: Programm beenden" << endl;
|
||||
auto input = ask_question<int>("Ihre Eingabe:");
|
||||
const auto input = ask_question<int>("Ihre Eingabe:");
|
||||
|
||||
switch (input)
|
||||
{
|
||||
@ -75,10 +118,21 @@ int main()
|
||||
create_invoice();
|
||||
break;
|
||||
case 2:
|
||||
output_invoice_per_month();
|
||||
{
|
||||
auto temp = list<Invoice>(invoices);
|
||||
temp.sort(compare_month_ascending);
|
||||
output_invoices(temp);
|
||||
}
|
||||
break;
|
||||
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;
|
||||
case 0:
|
||||
end_program = true;
|
||||
@ -96,20 +150,38 @@ category get_category();
|
||||
void create_invoice()
|
||||
{
|
||||
cout << "Eine neue Rechnung erstellen." << endl << endl;
|
||||
auto invoice_no = invoices.empty() ? 1 : invoices.back().get_number() + 1;
|
||||
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 invoice_no = invoices.empty() ? 1 : invoices.back().get_number() + 1;
|
||||
const auto amount = ask_question<double>("Bitte geben Sie den Betrag in Euro ein.");
|
||||
const auto month = ask_question<unsigned short>("Bitte geben Sie den Monat ein.");
|
||||
const auto category = get_category();
|
||||
const auto i = Invoice(invoice_no, amount, month, category);
|
||||
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()
|
||||
@ -130,6 +202,6 @@ category get_category()
|
||||
{
|
||||
return static_cast<category>(cat);
|
||||
}
|
||||
cout << "Ung\x81ltige Eingabe";
|
||||
cout << "Ung\x81ltige Eingabe" << endl << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user