diff --git a/homework/calculate/CMakeLists.txt b/homework/calculate/CMakeLists.txt index 087714e7..3fcbf95f 100644 --- a/homework/calculate/CMakeLists.txt +++ b/homework/calculate/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.11.0) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) include(FetchContent) @@ -14,7 +14,6 @@ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) # Now simply link against gtest or gtest_main as needed. Eg - project(calculate) enable_testing() diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 7a933a25..85f59493 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -1,7 +1,20 @@ #pragma once +#include #include std::string calculate(const std::string& command, int first, int second) { - // TODO: Implement your solution here and return proper value - return ""; + if (command == "add") { + return std::to_string(first + second); + } else if (command == "subtract") { + return std::to_string(first - second); + } else if (command == "multiply") { + return std::to_string(first * second); + } else if (command == "divide") { + if (second == 0) { + return "Division by 0"; + } + return std::to_string(first / second); + } + + return "Invalid data"; }