From d9c798726930e6541a895c48f5deebcca78b8fb4 Mon Sep 17 00:00:00 2001 From: studiosi Date: Wed, 12 Aug 2026 08:56:24 +0300 Subject: [PATCH] Solved: 04 - Variables and Types --- .../src/variables_and_types.cpp | 47 +++++++++---------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/modules/01_fundamentals/src/variables_and_types.cpp b/modules/01_fundamentals/src/variables_and_types.cpp index 3da84fa..60b7390 100644 --- a/modules/01_fundamentals/src/variables_and_types.cpp +++ b/modules/01_fundamentals/src/variables_and_types.cpp @@ -1,43 +1,38 @@ #include "variables_and_types.hpp" +#include + namespace fundamentals { -auto add_integers(int lhs, int rhs) -> int { - // TODO: Return the sum. - (void)lhs; - (void)rhs; - return 0; +auto add_integers(const int lhs, const int rhs) -> int { + return lhs + rhs; } -auto multiply_doubles(double lhs, double rhs) -> double { - // TODO: Return the product. - (void)lhs; - (void)rhs; - return 0.0; +auto multiply_doubles(const double lhs, const double rhs) -> double { + return lhs * rhs; } -auto is_even(std::int64_t value) -> bool { - // TODO: Return true when value is divisible by 2. - (void)value; - return false; +auto is_even(const std::int64_t value) -> bool { + return value % 2 == 0; } -auto describe_type(int value) -> std::string { - // TODO: Return "int:" followed by the decimal representation. - (void)value; - return "int:0"; +auto describe_type(const int value) -> std::string { + auto oss = std::ostringstream{}; + oss << "int:" << value; + return oss.str(); } -auto describe_type(double value) -> std::string { - // TODO: Return "double:" followed by the value with one decimal place. - (void)value; - return "double:0.0"; +auto describe_type(const double value) -> std::string { + auto oss = std::ostringstream{}; + oss << "double:" << value; + return oss.str(); } -auto describe_type(bool value) -> std::string { - // TODO: Return "bool:true" or "bool:false". - (void)value; - return "bool:false"; +auto describe_type(const bool value) -> std::string { + auto oss = std::ostringstream{}; + const std::string representation = value ? "true" : "false"; + oss << "bool:" << representation; + return oss.str(); } } // namespace fundamentals