From fab9aa4ce9017d68a9f5ae54e2929ca31bc876d8 Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Wed, 12 Aug 2026 10:10:41 +0200 Subject: [PATCH 1/5] Implement 'add' feature --- homework/calculate/calculate.hpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 7a933a25..a142bc54 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -2,6 +2,10 @@ #include std::string calculate(const std::string& command, int first, int second) { - // TODO: Implement your solution here and return proper value - return ""; + int result = 0; + if (command == "add") { + result = first + second; + } + + return std::to_string(result); } From 799d2d538e11de06678b0af78f54f383c2b5649d Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Wed, 12 Aug 2026 10:12:13 +0200 Subject: [PATCH 2/5] Implement 'subtract' feature --- homework/calculate/calculate.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index a142bc54..235821e3 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -7,5 +7,9 @@ std::string calculate(const std::string& command, int first, int second) { result = first + second; } - return std::to_string(result); + else if (command == "subtract") { + result = first - second; + } + + return std::to_string(result); } From 431b0c9bd71041361492dc360093cce2f42742fa Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Wed, 12 Aug 2026 10:13:03 +0200 Subject: [PATCH 3/5] Implement 'multiply' feature --- homework/calculate/calculate.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 235821e3..97d8ed61 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -11,5 +11,9 @@ std::string calculate(const std::string& command, int first, int second) { result = first - second; } + else if (command == "multiply") { + result = first * second; + } + return std::to_string(result); } From 4232041fdeafb4d161d0495c4c43ef8328d237eb Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Wed, 12 Aug 2026 10:27:55 +0200 Subject: [PATCH 4/5] Implement 'divide' feature --- homework/calculate/calculate.hpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 97d8ed61..98795e51 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -15,5 +15,13 @@ std::string calculate(const std::string& command, int first, int second) { result = first * second; } + else if (command == "divide") { + if (second == 0) { + return "Division by 0"; + } + + result = first / second; + } + return std::to_string(result); } From fa1c0100b9a168919c83221d52cbb61889925e12 Mon Sep 17 00:00:00 2001 From: Bartosz Rybarczyk Date: Wed, 12 Aug 2026 10:31:22 +0200 Subject: [PATCH 5/5] Implement 'Invalid data' feature --- homework/calculate/calculate.hpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/homework/calculate/calculate.hpp b/homework/calculate/calculate.hpp index 98795e51..8908346f 100644 --- a/homework/calculate/calculate.hpp +++ b/homework/calculate/calculate.hpp @@ -23,5 +23,9 @@ std::string calculate(const std::string& command, int first, int second) { result = first / second; } + else { + return "Invalid data"; + } + return std::to_string(result); }