#include "Calculator.h" int Calculator::run() { std::cout << "Fractional calculator\n\n"; while ( true ) { if ( ! readFraction() ) return 0; if ( ! readOperation() ) return 0; } } bool Calculator::readFraction() { std::cout << "fr> "; if ( ! (std::cin >> other) ) return false; ecci::Fraction previousResult = result; switch ( operador ) { case '+': result = result + other; break; // case '-': resultado = resultado - otra; break; // case '*': result = result * other; break; // case '/': resultado = resultado / otra; break; case 'c': case 'C': case ' ': result = other; std::cout << result << std::endl; return true; case '=': return true; default: std::cout << "Err" << std::endl; return true; } std::cout << previousResult << " " << operador << " " << other << " = " << result << std::endl; return true; } bool Calculator::readOperation() { std::cout << "op> "; std::cin >> operador; switch ( operador ) { case '=': std::cout << result << std::endl; break; case 'c': case 'C': result = 0; std::cout << result << std::endl; break; case 'q': case 'Q': return false; } return std::cin.good(); }