nearly done...
This commit is contained in:
parent
34faba5bd9
commit
ca5552e13c
@ -4,28 +4,18 @@
|
||||
|
||||
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
|
||||
class invoice
|
||||
{
|
||||
private:
|
||||
int number_ = 0;
|
||||
double amount_;
|
||||
unsigned short month_ = 0;
|
||||
category category_ = None;
|
||||
int category_ = 0;
|
||||
public:
|
||||
Invoice(int number, double amount, unsigned short month, category category) : number_(number), amount_(amount),
|
||||
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)
|
||||
{
|
||||
}
|
||||
@ -40,7 +30,7 @@ public:
|
||||
return month_;
|
||||
}
|
||||
|
||||
category get_category() const
|
||||
int get_category() const
|
||||
{
|
||||
return category_;
|
||||
}
|
||||
@ -48,15 +38,15 @@ public:
|
||||
void print() const
|
||||
{
|
||||
cout << " Rechnung: " << number_ << endl;
|
||||
cout << "Betrag: " << amount_ << endl;
|
||||
cout << "Monat: " << month_ << endl;
|
||||
cout << "Kategorie: " << category_ << endl;
|
||||
cout << " Betrag: " << amount_ << "€" << endl;
|
||||
cout << " Monat: " << months[month_] << endl;
|
||||
cout << " Kategorie: " << categories[category_] << endl;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Implements the equality operator.
|
||||
*/
|
||||
bool operator ==(const Invoice& e) const
|
||||
bool operator ==(const invoice& e) const
|
||||
{
|
||||
return number_ == e.number_;
|
||||
}
|
||||
@ -64,10 +54,12 @@ public:
|
||||
/**
|
||||
* \brief Implements the inequality operator.
|
||||
*/
|
||||
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::months[] = {"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"};
|
||||
|
||||
template <typename T>
|
||||
T ask_question(const string& question)
|
||||
{
|
||||
@ -78,20 +70,15 @@ T ask_question(const string& question)
|
||||
return value;
|
||||
}
|
||||
|
||||
list<Invoice> invoices;
|
||||
list<invoice> invoices;
|
||||
|
||||
void create_invoice();
|
||||
|
||||
void output_invoices(list<Invoice> sorted_invoices);
|
||||
void output_invoices_order_by_month();
|
||||
|
||||
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)
|
||||
bool compare_month_ascending(const invoice& first, const invoice& second)
|
||||
{
|
||||
return first.get_month() < second.get_month();
|
||||
}
|
||||
@ -118,18 +105,10 @@ int main()
|
||||
create_invoice();
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
auto temp = list<Invoice>(invoices);
|
||||
temp.sort(compare_month_ascending);
|
||||
output_invoices(temp);
|
||||
}
|
||||
output_invoices_order_by_month();
|
||||
break;
|
||||
case 3:
|
||||
{
|
||||
auto temp = list<Invoice>(invoices);
|
||||
temp.sort(compare_category_ascending);
|
||||
output_invoices(temp);
|
||||
}
|
||||
//TODO
|
||||
break;
|
||||
case 4:
|
||||
delete_invoice();
|
||||
@ -145,33 +124,41 @@ int main()
|
||||
return 0;
|
||||
}
|
||||
|
||||
category get_category();
|
||||
int get_month();
|
||||
int get_category();
|
||||
|
||||
void create_invoice()
|
||||
{
|
||||
cout << "Eine neue Rechnung erstellen." << endl << endl;
|
||||
system("cls");
|
||||
cout << "Eine neue Rechnung erstellen." << endl;
|
||||
cout << "------------------------------------"<<endl;
|
||||
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 month = get_month();
|
||||
const auto category = get_category();
|
||||
const auto i = Invoice(invoice_no, amount, month, category);
|
||||
const auto i = invoice(invoice_no, amount, month, category);
|
||||
invoices.push_back(i);
|
||||
}
|
||||
|
||||
|
||||
void output_invoices(const list<Invoice> sorted_invoices)
|
||||
void output_invoices_order_by_month()
|
||||
{
|
||||
for (auto invoice : sorted_invoices)
|
||||
system("cls");
|
||||
cout << "Alle Rechnungen nach Monat sortiert:"<<endl;
|
||||
cout << "------------------------------------"<<endl;
|
||||
auto temp = list<invoice>(invoices);
|
||||
temp.sort(compare_month_ascending);
|
||||
for (auto invoice : temp)
|
||||
{
|
||||
invoice.print();
|
||||
cout << "--------------" << endl;
|
||||
cout << "------------------------------------" << endl;
|
||||
}
|
||||
system("pause");
|
||||
}
|
||||
|
||||
void delete_invoice()
|
||||
{
|
||||
auto invoice_number = ask_question<int>("Bitte geben Sie die Rechnungsnummer ein");
|
||||
const auto invoice_number = ask_question<int>("Bitte geben Sie die Rechnungsnummer ein");
|
||||
for (auto invoice : invoices)
|
||||
{
|
||||
if (invoice.get_number() == invoice_number)
|
||||
@ -184,23 +171,39 @@ void delete_invoice()
|
||||
system("pause");
|
||||
}
|
||||
|
||||
category get_category()
|
||||
int get_month()
|
||||
{
|
||||
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)
|
||||
cout << "Bitte w\x84hlen sie einen Monat aus:" << endl;
|
||||
auto index = 0;
|
||||
for (auto month : invoice::months)
|
||||
{
|
||||
return static_cast<category>(cat);
|
||||
cout << ++index << ": " << month << endl;
|
||||
}
|
||||
const auto answer = ask_question<unsigned int>("");
|
||||
if (answer > 0 && answer <= 12)
|
||||
{
|
||||
return answer - 1;
|
||||
}
|
||||
cout << "Ung\x81ltige Eingabe" << endl << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int get_category()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
cout << "Bitte w\x84hlen sie eine Kategorie aus:" << endl;
|
||||
auto index = 0;
|
||||
for (auto category : invoice::categories)
|
||||
{
|
||||
cout << ++index << ": " << category << endl;
|
||||
}
|
||||
const auto answer = ask_question<int>("");
|
||||
if (answer > 0 && answer <= 8)
|
||||
{
|
||||
return answer - 1;
|
||||
}
|
||||
cout << "Ung\x81ltige Eingabe" << endl << endl;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user