From 50b31358a11cfb73f70d62befd105f23c60fe32a Mon Sep 17 00:00:00 2001 From: Andrew Zabolotnikov Date: Fri, 11 Oct 2024 19:21:25 +0300 Subject: [PATCH 1/5] =?UTF-8?q?=D0=94=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D0=B5?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20task=5F01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task_01/src/main.cpp | 11 ++++++++++- task_01/src/mediana.cpp | 15 +++++++++++++++ task_01/src/mediana.h | 2 ++ task_01/src/test.cpp | 13 +++++++++++-- 4 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 task_01/src/mediana.cpp create mode 100644 task_01/src/mediana.h diff --git a/task_01/src/main.cpp b/task_01/src/main.cpp index 0e4393b..488bcd8 100644 --- a/task_01/src/main.cpp +++ b/task_01/src/main.cpp @@ -1,3 +1,12 @@ +#include "mediana.h" #include -int main() { return 0; } +int main() { + double a; + double b; + double c; + std::cin>>a>>b>>c; + double result = mediana(a, b, c); + std::cout< +double mediana(double a, double b, double c) { + double max_value = {a}; + double min_value = {a}; + std::vector numbers = {a, b, c}; + for(auto &x: numbers) { + if (x < min_value) + min_value = x; + if (x>max_value) + max_value = x; + } + double mediana_value = a + b + c - min_value - max_value; + return mediana_value; +} diff --git a/task_01/src/mediana.h b/task_01/src/mediana.h new file mode 100644 index 0000000..4f576f2 --- /dev/null +++ b/task_01/src/mediana.h @@ -0,0 +1,2 @@ +#pragma once +double mediana(double a, double b, double c); diff --git a/task_01/src/test.cpp b/task_01/src/test.cpp index 0c33b55..27d9261 100644 --- a/task_01/src/test.cpp +++ b/task_01/src/test.cpp @@ -1,5 +1,14 @@ #include +#include "mediana.h" + +TEST(Test, Simple) { + ASSERT_EQ(mediana(1, 2, 3), 2); + ASSERT_EQ(mediana(4, 5, 4.4), 4.4); + ASSERT_EQ(mediana(34, 2, 676), 34); + ASSERT_EQ(mediana(0, 0, 0), 0); + ASSERT_EQ(mediana(1, -6, -5), -5); + +} + -#include -TEST(Test, Simple) { ASSERT_EQ(Sum(1, 2, 3), 6); } \ No newline at end of file From 091240aa0e179bf00f9ac46d0a015fdc3c2c777b Mon Sep 17 00:00:00 2001 From: Andrew Zabolotnikov Date: Sun, 20 Oct 2024 14:39:10 +0300 Subject: [PATCH 2/5] =?UTF-8?q?=D0=94=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D0=B5?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20task=5F01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task_02/src/maximum.cpp | 10 ++++++++++ task_02/src/maximum.h | 2 ++ task_02/src/test.cpp | 12 ++++++++++-- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 task_02/src/maximum.cpp create mode 100644 task_02/src/maximum.h diff --git a/task_02/src/maximum.cpp b/task_02/src/maximum.cpp new file mode 100644 index 0000000..bace7e0 --- /dev/null +++ b/task_02/src/maximum.cpp @@ -0,0 +1,10 @@ + +#include "maximum.h" +double maximum(double *ptr, const int size) { + double maximum = *ptr; + for(auto i{1}; i < size; i++) { + if (maximum < *(ptr + i)) + maximum = *(ptr + i); + } + return maximum; +} \ No newline at end of file diff --git a/task_02/src/maximum.h b/task_02/src/maximum.h new file mode 100644 index 0000000..beca909 --- /dev/null +++ b/task_02/src/maximum.h @@ -0,0 +1,2 @@ +#pragma once +double maximum(double *ptr, int size); diff --git a/task_02/src/test.cpp b/task_02/src/test.cpp index 87cef73..e66cfae 100644 --- a/task_02/src/test.cpp +++ b/task_02/src/test.cpp @@ -1,5 +1,13 @@ #include +#include "maximum.h" + +double sp[] {1, 23 ,4, 234, 34, 4322, 0, -14}; +double *ptr = {sp}; + TEST(Test, Simple) { - ASSERT_EQ(1, 1); // Stack [] -} \ No newline at end of file + ASSERT_EQ(maximum(ptr,3), 23); + ASSERT_EQ(maximum(ptr,30), 4322); + ASSERT_EQ(maximum(ptr,1), 1); + ASSERT_EQ(maximum(ptr,5), 234); +} From 070b27f7d0258cc98ff5c5844400fbe51bbb1b0f Mon Sep 17 00:00:00 2001 From: Andrew Zabolotnikov Date: Sun, 20 Oct 2024 14:45:12 +0300 Subject: [PATCH 3/5] =?UTF-8?q?=D0=94=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D0=B5?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20task=5F02?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task_02/src/main.cpp | 3 --- task_02/src/maximum.cpp | 2 +- task_02/src/maximum.h | 1 + 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/task_02/src/main.cpp b/task_02/src/main.cpp index 0e4393b..e69de29 100644 --- a/task_02/src/main.cpp +++ b/task_02/src/main.cpp @@ -1,3 +0,0 @@ -#include - -int main() { return 0; } diff --git a/task_02/src/maximum.cpp b/task_02/src/maximum.cpp index bace7e0..68b22aa 100644 --- a/task_02/src/maximum.cpp +++ b/task_02/src/maximum.cpp @@ -1,5 +1,5 @@ - #include "maximum.h" + double maximum(double *ptr, const int size) { double maximum = *ptr; for(auto i{1}; i < size; i++) { diff --git a/task_02/src/maximum.h b/task_02/src/maximum.h index beca909..d6edd69 100644 --- a/task_02/src/maximum.h +++ b/task_02/src/maximum.h @@ -1,2 +1,3 @@ #pragma once + double maximum(double *ptr, int size); From 9cf9cc42c5e3978beedd4a13e1642a27ad7df144 Mon Sep 17 00:00:00 2001 From: Andrew Zabolotnikov Date: Sun, 20 Oct 2024 14:46:16 +0300 Subject: [PATCH 4/5] =?UTF-8?q?=D0=94=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D0=B5?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20task=5F02?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task_02/src/test.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/task_02/src/test.cpp b/task_02/src/test.cpp index e66cfae..80b550c 100644 --- a/task_02/src/test.cpp +++ b/task_02/src/test.cpp @@ -4,7 +4,6 @@ double sp[] {1, 23 ,4, 234, 34, 4322, 0, -14}; double *ptr = {sp}; - TEST(Test, Simple) { ASSERT_EQ(maximum(ptr,3), 23); ASSERT_EQ(maximum(ptr,30), 4322); From 5afdef4a82bb6aa66b5c5fe14304da316fdeb276 Mon Sep 17 00:00:00 2001 From: Andrew Zabolotnikov Date: Sun, 20 Oct 2024 16:28:12 +0300 Subject: [PATCH 5/5] =?UTF-8?q?=D0=94=D0=BE=D0=BC=D0=B0=D1=88=D0=BD=D0=B5?= =?UTF-8?q?=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20task=5F03?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- task_03/src/main.cpp | 1 - task_03/src/reverse.cpp | 8 +++++++- task_03/src/reverse.hpp | 4 +--- task_03/src/test.cpp | 19 +++++++++++++++++-- 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/task_03/src/main.cpp b/task_03/src/main.cpp index 76e8197..e69de29 100644 --- a/task_03/src/main.cpp +++ b/task_03/src/main.cpp @@ -1 +0,0 @@ -int main() { return 0; } diff --git a/task_03/src/reverse.cpp b/task_03/src/reverse.cpp index 3457424..d595739 100644 --- a/task_03/src/reverse.cpp +++ b/task_03/src/reverse.cpp @@ -1,3 +1,9 @@ #include "reverse.hpp" -void Reverse(int *array, size_t len) {} \ No newline at end of file +void Reverse(double *array, int len) { + for(auto i{0}; int(i - -void Reverse(int *array, size_t len); +void Reverse(double *array, int len); diff --git a/task_03/src/test.cpp b/task_03/src/test.cpp index 2d868db..e57c9e1 100644 --- a/task_03/src/test.cpp +++ b/task_03/src/test.cpp @@ -1,6 +1,21 @@ - +#include #include #include "reverse.hpp" -TEST(Reverse, Simple) {} +double sp[] {1, 23, 4, 234, 34, 4322, 0, -14}; +double sp_mod[] {-14, 0, 4322, 34, 234, 4, 23, 1}; +double sp2[] {1, 23, 4, 5, 7}; +double sp_mod2[] {7, 5, 4, 23, 1}; + + +TEST(Reverse, Simple) { + Reverse(sp, 8); + for (int i{0}; i < 8; i++) { + ASSERT_EQ(sp[i], sp_mod[i]); + } + Reverse(sp2, 5); + for (int i{0}; i < 5; i++) { + ASSERT_EQ(sp2[i], sp_mod2[i]); + } +}