1
0

implemented first option

This commit is contained in:
Holger Boerchers 2018-11-30 13:49:29 +01:00
parent 731d86eb8d
commit e3031ebbe3

View File

@ -1,6 +1,135 @@
#include <iostream> #include <iostream>
#include <list>
#include <string>
using namespace std;
enum category
{
None = 0,
Tanken = 1,
Nahrungsmittel = 2,
Reinigungsmittel = 3,
Urlaub = 4,
Haustiere = 5,
Bekleidung = 6,
Wohnen = 7,
Versicherung = 8
};
class Invoice
{
private:
int number_ = 0;
double amount_;
unsigned short month_ = 0;
category category_ = None;
public:
Invoice(int number, double amount, unsigned short month, category category) : number_(number), amount_(amount),
month_(month), category_(category)
{
}
int get_number() const
{
return number_;
}
};
template <typename T>
T ask_question(const string& question)
{
cout << question << endl;
cout << "> ";
T value;
cin >> value;
return value;
}
list<Invoice> invoices;
void create_invoice();
void output_invoice_per_month();
void output_invoice_per_category();
int main() int main()
{ {
std::cout << "Hello World!\n"; auto end_program = false;
while (!end_program)
{
system("cls");
cout << "Ausgabenverwaltung (" << invoices.size() << " Rechnungen)" << endl << endl;
cout << "Bitte w\x84hlen Sie eine Option:" << endl;
cout << "1: Erfassung einer Rechnung (inkl. Abfrage der Rechnungsdaten)" << endl;
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 << "0: Programm beenden" << endl;
auto input = ask_question<int>("Ihre Eingabe:");
switch (input)
{
case 1:
create_invoice();
break;
case 2:
output_invoice_per_month();
break;
case 3:
output_invoice_per_category();
break;
case 0:
end_program = true;
break;
default:
cout << "Unerlaubte Eingabe" << endl;
system("pause");
}
}
return 0;
}
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 category = get_category();
const auto i = Invoice(invoice_no, amount, month, category);
invoices.push_back(i);
}
void output_invoice_per_month()
{
}
void output_invoice_per_category()
{
}
category get_category()
{
while (true)
{
cout << "Bitte w\x84hlen sie eine Kategorie aus:" << endl;
cout << " 1: Tanken" << endl;
cout << " 2: Nahrungsmittel" << endl;
cout << " 3: Reinigungsmittel" << endl;
cout << " 4: Urlaub" << endl;
cout << " 5: Haustiere" << endl;
cout << " 6: Bekleidung" << endl;
cout << " 7: Wohnen" << endl;
cout << " 8: Versicherung" << endl;
auto cat = ask_question<int>("");
if (cat > 0 && cat <= 8)
{
return static_cast<category>(cat);
}
cout << "Ung\x81ltige Eingabe";
}
} }