#ifndef interface_h #define interface_h #include #include bool interface(const std::string command, const std::string text, int &number1, double &number2); bool interface(const std::string command, const std::string text, int &number1); bool interface(const std::string command, const std::string text); bool is_number(const std::string text); double to_double(const std::string text); bool interface(const std::string command, const std::string text, int &number1, double &number2) { bool result = false; if (command == text) { std::string param1, param2; std::cin >> param1 >> param2; if (is_number(param1) && is_number(param2)) { number1 = to_double(param1); number2 = to_double(param2); result = true; } } return result; } bool interface(const std::string command, const std::string text, int &number1) { bool result = false; if (command == text) { std::string param1; std::cin >> param1; if(is_number(param1)) { number1 = to_double(param1); result = true; } } return result; } bool interface(const std::string command, const std::string text) { bool result = false; if (command == text) { result = true; } return result; } bool is_number(const std::string text) { char *num; std::strtod(text.c_str(), &num); return *num == 0; } double to_double(const std::string text) { char *tmp; return strtod(text.c_str(), &tmp); } #endif /* interface_h */