diff options
| Commit | cd40b3479f8ce874cc69663b7318dc9f033ed1f1 (patch) | |
|---|---|---|
| Author | 2022-05-29 10:14:27 +0300 | |
| Committer | 2022-05-29 10:14:27 +0300 | |
| Files | 343fa572cdf20e4d861c90eb6c53178348de3045 /src | |
| FMI-OOP-P2_Tables-cd40b3479f8ce874cc69663b7318dc9f033ed1f1.tar FMI-OOP-P2_Tables-cd40b3479f8ce874cc69663b7318dc9f033ed1f1.tar.gz FMI-OOP-P2_Tables-cd40b3479f8ce874cc69663b7318dc9f033ed1f1.zip | ||
| Parent | a1ebb727ac98a291a944562f7be17e3645f5315a (diff) | |
Autocommit at 29.05.2022 @ 10:14
3 files changed, 5 insertions, 4 deletions
| -rw-r--r-- | src/Models/CellFormula.cpp | 3 | ||||
| -rw-r--r-- | src/Models/Table.cpp | 4 | ||||
| -rw-r--r-- | src/main.cpp | 2 |
diff --git a/src/Models/CellFormula.cpp b/src/Models/CellFormula.cpp index ecea06d..72c2a99 100644 --- a/src/Models/CellFormula.cpp +++ b/src/Models/CellFormula.cpp @@ -27,7 +27,7 @@ double CellFormula::calculate(unsigned index) { case '-' : return lval - calculate(++index); case '*' : return lval * calculate(++index); case '/' : return lval / calculate(++index); - case '^' : + case '^' : return pow(lval, calculate(++index)); case '\0' : default : return lval; } @@ -45,7 +45,6 @@ double CellFormula::getNumeralValue() { } String CellFormula::getValueForPrint() { - std::cout << formula.get_count() << std::endl; return String() += calculate(); } diff --git a/src/Models/Table.cpp b/src/Models/Table.cpp index 7e4a7ac..ce902f9 100644 --- a/src/Models/Table.cpp +++ b/src/Models/Table.cpp @@ -24,6 +24,8 @@ bool containsNumber(const char*& str) { (*str >= '0' && *str <= '9'); // + or -, followed by digit, or it just a digit } +#define abs(a) ((a < 0) ? -a : a) + void Table::putCell(unsigned row, unsigned col, const char* rawValue) { Cell* newCell; @@ -31,7 +33,7 @@ void Table::putCell(unsigned row, unsigned col, const char* rawValue) { double intParse = atoi(rawValue); double doubleParse = atof(rawValue); - newCell = (doubleParse - intParse > 0.00001 && doubleParse > 0.00001) + newCell = (abs(doubleParse) - abs(intParse) > 0.00001) ? (Cell*)new CellDouble(doubleParse) : (Cell*)new CellInt(intParse); } else { diff --git a/src/main.cpp b/src/main.cpp index 93b3f3b..caa2e19 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,7 @@ int main() { table.putCell(0, 0, "8"); table.putCell(0, 1, "3"); table.putCell(0, 2, "String"); - table.putCell(0, 3, "= 3 * R0C1 + R0C0 ^ R0C1 * 9 - 10 + R0C2"); + table.putCell(0, 3, "= 2 ^ 10"); UserInterface ui(&table); ui.run(); } |
