From be14d0b276606d029bebc878f36da7019f1a1935 Mon Sep 17 00:00:00 2001 From: Sebastian Sosnowski Date: Wed, 7 Jan 2026 20:53:11 +0100 Subject: [PATCH 1/3] Implement print function --- .../vector-of-shared-ptrs/vectorFunctions.cpp | 20 +++++++++++++++++++ .../vector-of-shared-ptrs/vectorFunctions.hpp | 11 ++++++++++ 2 files changed, 31 insertions(+) create mode 100644 homework/vector-of-shared-ptrs/vectorFunctions.cpp create mode 100644 homework/vector-of-shared-ptrs/vectorFunctions.hpp diff --git a/homework/vector-of-shared-ptrs/vectorFunctions.cpp b/homework/vector-of-shared-ptrs/vectorFunctions.cpp new file mode 100644 index 00000000..65ee024c --- /dev/null +++ b/homework/vector-of-shared-ptrs/vectorFunctions.cpp @@ -0,0 +1,20 @@ +#include "vectorFunctions.hpp" + +std::vector> generate(int count) { + return std::vector>{}; +} +void print(const std::vector>& vec) { + for (const auto& num : vec) { + std::cout << *num << "\n"; + } +} + +void add10(std::vector>& vec) { + ; +} +void sub10(const int* num) { + ; +} +void sub10(std::vector> vec) { + ; +} \ No newline at end of file diff --git a/homework/vector-of-shared-ptrs/vectorFunctions.hpp b/homework/vector-of-shared-ptrs/vectorFunctions.hpp new file mode 100644 index 00000000..4b998fbf --- /dev/null +++ b/homework/vector-of-shared-ptrs/vectorFunctions.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include +#include +#include + +std::vector> generate(int count); +void print(const std::vector>& vec); +void add10(std::vector>& vec); +void sub10(const int* num); +void sub10(std::vector> vec); \ No newline at end of file From 6f3264a7c74adb83b847706467b31ffba366843f Mon Sep 17 00:00:00 2001 From: Sebastian Sosnowski Date: Wed, 7 Jan 2026 20:58:38 +0100 Subject: [PATCH 2/3] Implement generate function --- homework/vector-of-shared-ptrs/vectorFunctions.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/homework/vector-of-shared-ptrs/vectorFunctions.cpp b/homework/vector-of-shared-ptrs/vectorFunctions.cpp index 65ee024c..384ed0ef 100644 --- a/homework/vector-of-shared-ptrs/vectorFunctions.cpp +++ b/homework/vector-of-shared-ptrs/vectorFunctions.cpp @@ -1,7 +1,11 @@ #include "vectorFunctions.hpp" std::vector> generate(int count) { - return std::vector>{}; + std::vector> vec; + for (int i = 0; i < count; i++) { + vec.push_back(std::make_shared(i)); + } + return vec; } void print(const std::vector>& vec) { for (const auto& num : vec) { From ded15932e6fb45829286a986a321702f78cc8f8d Mon Sep 17 00:00:00 2001 From: Sebastian Sosnowski Date: Wed, 7 Jan 2026 21:12:38 +0100 Subject: [PATCH 3/3] Implement add10 and sub10 functions --- .../vector-of-shared-ptrs/vectorFunctions.cpp | 16 ++++++++++++---- .../vector-of-shared-ptrs/vectorFunctions.hpp | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/homework/vector-of-shared-ptrs/vectorFunctions.cpp b/homework/vector-of-shared-ptrs/vectorFunctions.cpp index 384ed0ef..bc86adff 100644 --- a/homework/vector-of-shared-ptrs/vectorFunctions.cpp +++ b/homework/vector-of-shared-ptrs/vectorFunctions.cpp @@ -14,11 +14,19 @@ void print(const std::vector>& vec) { } void add10(std::vector>& vec) { - ; + for (auto& num : vec) { + if (num) { + *num += 10; + } + } } -void sub10(const int* num) { - ; +void sub10(int* const num) { + if (num) { + *num -= 10; + } } void sub10(std::vector> vec) { - ; + for (auto& num : vec) { + sub10(num.get()); + } } \ No newline at end of file diff --git a/homework/vector-of-shared-ptrs/vectorFunctions.hpp b/homework/vector-of-shared-ptrs/vectorFunctions.hpp index 4b998fbf..d53743c6 100644 --- a/homework/vector-of-shared-ptrs/vectorFunctions.hpp +++ b/homework/vector-of-shared-ptrs/vectorFunctions.hpp @@ -7,5 +7,5 @@ std::vector> generate(int count); void print(const std::vector>& vec); void add10(std::vector>& vec); -void sub10(const int* num); +void sub10(int* const num); void sub10(std::vector> vec); \ No newline at end of file