diff options
Autocommit at 14.06.2022 @ 15:04
2 files changed, 22 insertions, 1 deletions
| -rw-r--r-- | src/Models/CellFormula.cpp | 15 | ||||
| -rw-r--r-- | src/Models/CellInt.h | 8 |
diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp index fead01d..1cdf06a 100644 --- a/src/Models/CellFormula.cpp +++ b/src/Models/CellFormula.cpp @@ -29,8 +29,9 @@ double CellFormula::calculate(unsigned index) const { const Cell* currCell = ptrByInd(formula[index].left); double numVal = (currCell == nullptr) ? 0 : currCell->getNumeralValue(); + // Handle prioritised operation while (formula[index].right < 0) { - switch (-formula[index++].right) { + switch (-formula[index++].right) { // Prioritized operations are stored as negative characters case '+' : numVal += ptrByInd(formula[index].left)->getNumeralValue(); break; case '*' : numVal *= ptrByInd(formula[index].left)->getNumeralValue(); break; case '/' : if (ptrByInd(formula[index].left)->getNumeralValue() == 0) throw std::logic_error("Error: Divion by zero!"); @@ -59,6 +60,12 @@ CellFormula::CellFormula(const char* str, const List<List<Cell*>>* tableCells) : #include <iostream> +/*! + * Value is recalculated every time this function is called (in case a referenced cell is changed). + * + * \return 0 \if Calculation failed + * \return Calculated value \otherwise + */ double CellFormula::getNumeralValue() const { try { return calculate(); @@ -68,6 +75,12 @@ double CellFormula::getNumeralValue() const { } } +/*! + * Value is recalculated every time this function is called (in case a referenced cell is changed). + * + * \return "Error" \if Calculation failed + * \return Calculated value as a String \otherwise + */ String CellFormula::getValueForPrint() const { try { return String() += calculate(); diff --git a/src/Models/CellInt.h b/src/Models/CellInt.h index 8be1022..c24ef85 100644 --- a/src/Models/CellInt.h +++ b/src/Models/CellInt.h @@ -1,8 +1,16 @@ #ifndef HEADER_CELLINT #define HEADER_CELLINT +/*! \file CellInt.h + * \brief Stores the declaration of class Cell + */ + #include "Cell.h" +/*! \brief A table cell which contains an integer + * + * Impelements the Cell class by implementing a value of type int + */ class CellInt : public Cell { int value; |
