diff --git a/sandbox/template/src/foo.hpp b/sandbox/template/src/foo.hpp new file mode 100644 index 0000000..b0eaf35 --- /dev/null +++ b/sandbox/template/src/foo.hpp @@ -0,0 +1,3 @@ +#pragma once + +void Bar() {} diff --git a/sandbox/template/src/main.cpp b/sandbox/template/src/main.cpp index 0e4393b..bc7c1d4 100644 --- a/sandbox/template/src/main.cpp +++ b/sandbox/template/src/main.cpp @@ -1,3 +1,26 @@ +#include #include -int main() { return 0; } +#include "utils.hpp" + +int main() { + utils::IntArray a(10); + + for (int i = 0; i < a.GetSize(); ++i) { + a[i] = i; + } + + int sum = 0; + for (int i = 0; i < a.GetSize(); ++i) { + sum += a[i]; + } + + std::cout << sum << '\n'; + + utils::IntArray adda; + utils::IntArray b(1, 1); + + { utils::IntArray a; } + + return 0; +} diff --git a/sandbox/template/src/utils.cpp b/sandbox/template/src/utils.cpp index 0ee624c..302ccea 100644 --- a/sandbox/template/src/utils.cpp +++ b/sandbox/template/src/utils.cpp @@ -1 +1,52 @@ #include "utils.hpp" +#include +#include +#include +#include + +namespace utils { + +// IntArray::IntArray() : data_(nullptr), size_(0), bar("Bar"), foo() { +// std::cout << "IntArray::IntArray()\n"; +// } + +IntArray::IntArray(int size) : foo(size), bar("Bar") { + std::cout << "IntArray::IntArray(int size = " << size << ")\n "; + data_ = new int[size]; + size_ = size; +} + +IntArray::IntArray(int num, int size) { + std::cout << "IntArray::IntArray(int num = " << num << "int size " << size + << ")\n"; + data_ = new int[size]; + size_ = size; + for (int i = 0; i < size; ++i) { + data_[i] = num; + } +} + +IntArray::~IntArray() { + Clear(); + std::cout << "IntArray::~IntArray()\n"; +} + +int IntArray::GetSize() const { return size_; } + +bool IntArray::IsEmpty() const { return !size_; } + +int &IntArray::operator[](int index) { + if (index < 0) + throw std::out_of_range("index is negative"); + if (index >= size_) + throw std::out_of_range("index is too big"); + return data_[index]; +} + +void IntArray::Clear() { + delete[] data_; + data_ = nullptr; + size_ = 0; +} + +} // namespace utils diff --git a/sandbox/template/src/utils.hpp b/sandbox/template/src/utils.hpp index 6f70f09..1fcefa8 100644 --- a/sandbox/template/src/utils.hpp +++ b/sandbox/template/src/utils.hpp @@ -1 +1,39 @@ #pragma once + +#include + +namespace utils { + +class Foo { +public: + Foo() { std::cout << "Foo()\n"; } + Foo(int) { std::cout << "Foo(int)\n"; } + Foo(const std::string &s) { std::cout << s << "(string)\n"; } + ~Foo() { std::cout << "~Foo()\n"; } +}; + +class IntArray { +public: + IntArray() = delete; + IntArray(int size); + IntArray(int num, int size); + ~IntArray(); + + int GetSize() const; + + bool IsEmpty() const; + + void Resize(int size); + + int &operator[](int index); + + void Clear(); + +private: + Foo foo; + Foo bar; + int *data_; + int size_; +}; + +} // namespace utils \ No newline at end of file diff --git a/task_01/src/main.cpp b/task_01/src/main.cpp index 0e4393b..71fca33 100644 --- a/task_01/src/main.cpp +++ b/task_01/src/main.cpp @@ -1,3 +1,7 @@ #include -int main() { return 0; } +int main() { + std::cout << "Hello, world!\n"; + + return 0; +} diff --git a/task_01/src/sum.cpp b/task_01/src/sum.cpp new file mode 100644 index 0000000..345155a --- /dev/null +++ b/task_01/src/sum.cpp @@ -0,0 +1,3 @@ +#include "sum.hpp" + +int Sum(int first_number, int second_number, int third_number) { return 6; } \ No newline at end of file diff --git a/task_01/src/sum.hpp b/task_01/src/sum.hpp index 97cc293..9c229b4 100644 --- a/task_01/src/sum.hpp +++ b/task_01/src/sum.hpp @@ -1 +1 @@ -int Sum(int first_number, int second_number, int third_number) { return 6; } \ No newline at end of file +int Sum(int first_number, int second_number, int third_number); \ No newline at end of file diff --git a/task_05/CMakeLists.txt b/task_05/CMakeLists.txt new file mode 100644 index 0000000..0e23984 --- /dev/null +++ b/task_05/CMakeLists.txt @@ -0,0 +1,39 @@ +cmake_minimum_required(VERSION 3.10) + +get_filename_component(PROJECT_NAME ${CMAKE_CURRENT_LIST_DIR} NAME) +string(REPLACE " " "_" PROJECT_NAME ${PROJECT_NAME}) +project(${PROJECT_NAME} C CXX) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +file(GLOB_RECURSE source_list "src/*.cpp" "src/*.hpp") +file(GLOB_RECURSE lib_source_list "../lib/src/*.cpp" "../lib/src/*.hpp") +file(GLOB_RECURSE main_source_list "src/main.cpp") +file(GLOB_RECURSE test_source_list "src/*.cpp") +file(GLOB_RECURSE test_list "src/*test.cpp") + +list(REMOVE_ITEM test_source_list ${main_source_list}) +list(REMOVE_ITEM source_list ${test_list}) + +include_directories(${PROJECT_NAME} PUBLIC src) +include_directories(${PROJECT_NAME} PUBLIC ../lib/src) + +add_executable(${PROJECT_NAME} ${source_list}) +target_link_libraries(${PROJECT_NAME} PUBLIC Utils) + +# Locate GTest +enable_testing() +find_package(GTest REQUIRED) +include_directories(${GTEST_INCLUDE_DIRS}) + +# Link runTests with what we want to test and the GTest and pthread library +add_executable(${PROJECT_NAME}_tests ${test_source_list}) +target_link_libraries( + ${PROJECT_NAME}_tests + GTest::gtest_main + Utils +) + +include(GoogleTest) +gtest_discover_tests(${PROJECT_NAME}_tests) diff --git a/task_05/README.md b/task_05/README.md new file mode 100644 index 0000000..0658849 --- /dev/null +++ b/task_05/README.md @@ -0,0 +1,3 @@ +# Сдвиг элементов + +Создайте функцию, которая принимает указатель на массив целых чисел, его размер, и целое число N. Функция должна сдвинуть все элементы массива на N позиций вправо, чтобы первые элементы стали последними. Элементы, которые "выталкиваются" из массива, должны появиться с левой стороны. diff --git a/task_05/src/main.cpp b/task_05/src/main.cpp new file mode 100644 index 0000000..0e4393b --- /dev/null +++ b/task_05/src/main.cpp @@ -0,0 +1,3 @@ +#include + +int main() { return 0; } diff --git a/task_05/src/test.cpp b/task_05/src/test.cpp new file mode 100644 index 0000000..5e11617 --- /dev/null +++ b/task_05/src/test.cpp @@ -0,0 +1,6 @@ + +#include + +TEST(TopologySort, Simple) { + ASSERT_EQ(1, 1); // Stack [] +}