Solved: 04 - Variables and Types

This commit is contained in:
2026-08-12 08:56:24 +03:00
parent 2d25dd503a
commit d9c7987269
@@ -1,43 +1,38 @@
#include "variables_and_types.hpp"
#include <sstream>
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