1
0

ein paar kommentare

This commit is contained in:
Holger Boerchers 2018-12-04 21:43:26 +01:00
parent d8498859f1
commit e1e86b3f8b

View File

@ -16,9 +16,18 @@ private:
unsigned short month_ = 0; unsigned short month_ = 0;
int category_ = 0; int category_ = 0;
public: public:
/**
* \brief collection of categories
*/
static const char* categories[]; static const char* categories[];
/**
* \brief collection of months
*/
static const char* months[]; static const char* months[];
/**
* \brief Creates a new instance of invoice
*/
invoice(const int number, const double amount, const unsigned short month, const int category) : number_(number), invoice(const int number, const double amount, const unsigned short month, const int category) : number_(number),
amount_(amount), amount_(amount),
month_(month), month_(month),
@ -28,36 +37,40 @@ public:
/** /**
* \brief Get number of invoice. * \brief Get number of invoice.
* \return number * \return current number
*/ */
int get_number() const int get_number() const
{ {
return number_; return number_;
} }
/**
* \brief get month of invoice
* \return month as index
*/
unsigned short get_month() const unsigned short get_month() const
{ {
return month_; return month_;
} }
/**
* \brief get category of invoice
* \return category as index
*/
int get_category() const int get_category() const
{ {
return category_; return category_;
} }
/**
* \brief get amount of invoice
* \return amount in euro
*/
double get_amount() const double get_amount() const
{ {
return amount_; return amount_;
} }
void print() const
{
cout << " Rechnung: " << number_ << endl;
cout << " Betrag: " << amount_ << " Euro" << endl;
cout << " Monat: " << months[month_] << endl;
cout << " Kategorie: " << categories[category_] << endl;
}
/** /**
* \brief Implements the equality operator. * \brief Implements the equality operator.
*/ */
@ -98,6 +111,12 @@ const char* invoice::months[] = {
"Dezember" "Dezember"
}; };
/**
* \brief ask a question and get a answer.
* \tparam T return parameter
* \param question the question.
* \return the value.
*/
template <typename T> template <typename T>
T ask_question(const string& question) T ask_question(const string& question)
{ {
@ -109,21 +128,35 @@ T ask_question(const string& question)
} }
void create_invoice(); void create_invoice();
int get_month();
int get_category();
void invoices_ordered_by_month(); void invoices_ordered_by_month();
void delete_invoice(); void delete_invoice();
void sum_invoices_per_category(); void sum_invoices_per_category();
/**
* \brief compares months ascending.
* \param first the first invoice
* \param second the second invoice
* \return true, if first is smaller than second. False otherwise.
*/
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();
} }
/**
* \brief Double linked list of all invoices.
*/
list<invoice> invoices; list<invoice> invoices;
/**
* \brief Consecutive invoice number
*/
int invoice_serial_number; int invoice_serial_number;
/**
* \brief Start point of application
*/
int main() int main()
{ {
while (true) while (true)
@ -162,9 +195,6 @@ int main()
} }
} }
int get_month();
int get_category();
void create_invoice() void create_invoice()
{ {
system("cls"); system("cls");
@ -178,7 +208,6 @@ void create_invoice()
invoices.push_back(i); invoices.push_back(i);
} }
void invoices_ordered_by_month() void invoices_ordered_by_month()
{ {
system("cls"); system("cls");
@ -188,7 +217,10 @@ void invoices_ordered_by_month()
temp.sort(compare_month_ascending); temp.sort(compare_month_ascending);
for (auto invoice : temp) for (auto invoice : temp)
{ {
invoice.print(); cout << " Rechnung: " << invoice.get_number() << endl;
cout << " Betrag: " << invoice.get_amount() << " Euro" << endl;
cout << " Monat: " << invoice::months[invoice.get_month()] << endl;
cout << " Kategorie: " << invoice::categories[invoice.get_category()] << endl;
cout << "------------------------------------" << endl; cout << "------------------------------------" << endl;
} }
system("pause"); system("pause");
@ -196,7 +228,7 @@ void invoices_ordered_by_month()
void delete_invoice() void delete_invoice()
{ {
const auto invoice_number = ask_question<int>("Bitte geben Sie die Rechnungsnummer ein"); const auto invoice_number = ask_question<int>("Bitte geben Sie eine Rechnungsnummer ein");
for (auto invoice : invoices) for (auto invoice : invoices)
{ {
if (invoice.get_number() == invoice_number) if (invoice.get_number() == invoice_number)
@ -205,7 +237,7 @@ void delete_invoice()
return; return;
} }
} }
cout << "Rechnung nicht gefunden." << endl; cerr << "Fehler: Rechnung nicht gefunden." << endl;
system("pause"); system("pause");
} }
@ -218,8 +250,8 @@ void sum_invoices_per_category()
} }
for (const auto sum : sums) for (const auto sum : sums)
{ {
cout << " Kategorie: " << invoice::categories[sum.first] << endl; cout << " Kategorie: " << invoice::categories[sum.first] << endl;
cout << " Summe: " << sum.second << " Euro" << endl; cout << " Summe: " << sum.second << " Euro" << endl;
cout << "------------------------------------" << endl; cout << "------------------------------------" << endl;
} }
system("pause"); system("pause");