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