Skip to content

Commit a55efb7

Browse files
committed
All homeworks added
1 parent 959fb07 commit a55efb7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1529
-0
lines changed

.github/workflows/add-even.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: C++ fundamentals - add even
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
fibonacci:
7+
runs-on: ubuntu-latest
8+
env:
9+
path: homework/add-even/build
10+
steps:
11+
- name: Check out code
12+
uses: actions/checkout@master
13+
- name: Create build directory
14+
run: mkdir ${{ env.repo }}
15+
- name: Compile
16+
working-directory: ${{ env.repo }}
17+
run: |
18+
cmake ..
19+
make
20+
- name: Run tests
21+
working-directory: ${{ env.repo }}
22+
run: ctest -V

.github/workflows/calculate.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: C++ fundamentals - calculate
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
fibonacci:
7+
runs-on: ubuntu-latest
8+
env:
9+
path: homework/calculate/build
10+
steps:
11+
- name: Check out code
12+
uses: actions/checkout@master
13+
- name: Create build directory
14+
run: mkdir ${{ env.repo }}
15+
- name: Compile
16+
working-directory: ${{ env.repo }}
17+
run: |
18+
cmake ..
19+
make
20+
- name: Run tests
21+
working-directory: ${{ env.repo }}
22+
run: ctest -V

.github/workflows/fibonacci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: C++ fundamentals - fibonacci
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
fibonacci:
7+
runs-on: ubuntu-latest
8+
env:
9+
path: homework/fibonacci/build
10+
steps:
11+
- name: Check out code
12+
uses: actions/checkout@master
13+
- name: Create build directory
14+
run: mkdir ${{ env.repo }}
15+
- name: Compile
16+
working-directory: ${{ env.repo }}
17+
run: |
18+
cmake ..
19+
make
20+
- name: Run tests
21+
working-directory: ${{ env.repo }}
22+
run: ctest -V
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: C++ fundamentals - max of vector
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
fibonacci:
7+
runs-on: ubuntu-latest
8+
env:
9+
path: homework/max-of-vector/build
10+
steps:
11+
- name: Check out code
12+
uses: actions/checkout@master
13+
- name: Create build directory
14+
run: mkdir ${{ env.repo }}
15+
- name: Compile
16+
working-directory: ${{ env.repo }}
17+
run: |
18+
cmake ..
19+
make
20+
- name: Run tests
21+
working-directory: ${{ env.repo }}
22+
run: ctest -V
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: C++ fundamentals - generate sequence
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
fibonacci:
7+
runs-on: ubuntu-latest
8+
env:
9+
path: homework/generate-sequence/build
10+
steps:
11+
- name: Check out code
12+
uses: actions/checkout@master
13+
- name: Create build directory
14+
run: mkdir ${{ env.repo }}
15+
- name: Compile
16+
working-directory: ${{ env.repo }}
17+
run: |
18+
cmake ..
19+
make
20+
- name: Run tests
21+
working-directory: ${{ env.repo }}
22+
run: ctest -V

.github/workflows/nwd-nnw.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: C++ fundamentals - NWD NNW
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
fibonacci:
7+
runs-on: ubuntu-latest
8+
env:
9+
path: homework/nwd-nnw/build
10+
steps:
11+
- name: Check out code
12+
uses: actions/checkout@master
13+
- name: Create build directory
14+
run: mkdir ${{ env.repo }}
15+
- name: Compile
16+
working-directory: ${{ env.repo }}
17+
run: |
18+
cmake ..
19+
make
20+
- name: Run tests
21+
working-directory: ${{ env.repo }}
22+
run: ctest -V
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: C++ fundamentals - vector of shared ptrs
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
fibonacci:
7+
runs-on: ubuntu-latest
8+
env:
9+
path: homework/vector-of-shared-ptrs/build
10+
steps:
11+
- name: Check out code
12+
uses: actions/checkout@master
13+
- name: Create build directory
14+
run: mkdir ${{ env.repo }}
15+
- name: Compile
16+
working-directory: ${{ env.repo }}
17+
run: |
18+
cmake ..
19+
make
20+
- name: Run tests
21+
working-directory: ${{ env.repo }}
22+
run: ctest -V
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: C++ fundamentals - password check
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
fibonacci:
7+
runs-on: ubuntu-latest
8+
env:
9+
path: homework/password-check/build
10+
steps:
11+
- name: Check out code
12+
uses: actions/checkout@master
13+
- name: Create build directory
14+
run: mkdir ${{ env.repo }}
15+
- name: Compile
16+
working-directory: ${{ env.repo }}
17+
run: |
18+
cmake ..
19+
make
20+
- name: Run tests
21+
working-directory: ${{ env.repo }}
22+
run: ctest -V

homework/README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Praca domowa
2+
3+
___
4+
5+
## Zadanie 1
6+
7+
Zaimplementuj funkcję, której zadaniem ma być wykonywanie działań arytmetycznych na dwóch liczbach.
8+
9+
Sygnatura - `std::string calculate(const std::string& command, int first, int second)`.
10+
11+
### Parametry
12+
13+
* `const std::string& command` - rodzaj działania. Jedno z `add`, `subtract`, `multiply`, `divide`
14+
* `int first` - pierwsza liczba
15+
* `int second` - druga liczba
16+
17+
### Wartość zwracana
18+
19+
* `std::string` - wynik działania jako tekst
20+
21+
W przypadku podania błędnego parametru `command` funkcja powinna zwrócić napis "Invalid data".
22+
23+
### Przykłady użycia
24+
25+
```cpp
26+
auto result = calculate("add", 2, 3); // result = "5"
27+
result = calculate("multiply", 2, 3); // result = "6"
28+
result = calculate("hello", 2, 3); // result = "Invalid data"
29+
```
30+
31+
### Implementacja
32+
33+
Zmodyfikuj jedynie plik `calculate.hpp`. Reszty plików nie modyfikuj, chyba że chcesz się po prostu pobawić tym projektem :)
34+
35+
Plik `main.cpp` zawiera funkcję główną. Jeśli chcesz manualnie przetestować swój program po skompilowaniu go uruchom `./calculate`
36+
37+
Plik `test.cpp` zawiera testy. Testy uruchamia się wpisując `ctest -V` po skompilowaniu. Przełącznik `-V` powoduje, że wyświetlane są informacje o testach, które przeszły lub nie.
38+
39+
___
40+
41+
## Zadanie 2 - Fibonacci
42+
43+
Zaimplementuj dwie funkcje. Obie mają liczyć n-tą liczbę [ciągu Fibonacciego](https://pl.wikipedia.org/wiki/Ciąg_Fibonacciego), ale na odmienne sposoby.
44+
45+
* iteracyjnie (z użyciem pętli)
46+
* rekurencyjnie (funkcja ma wołać samą siebie)
47+
48+
Funkcje muszą mieć określone sygnatury:
49+
50+
```cpp
51+
int fibonacci_iterative(int sequence);
52+
int fibonacci_recursive(int sequence);
53+
```
54+
55+
___
56+
57+
## Dostarczenie zadań
58+
59+
1. Zrób fork repo [cpp-fundamentals](https://github.com/coders-school/cpp-fundamentals)
60+
2. Ściągnij swój fork - `git clone https://github.com/YOURNICK/cpp-fundamentals.git`
61+
3. Przejdź do katalogu cpp-fundamentals - `cd cpp-fundamentals`
62+
4. Utwórz gałąź o nazwie `calculate` na rozwiązanie zadania calculate - `git checkout -b calculate`
63+
5. Przejdź do katalogu module1/homework/calculate - `cd module1/homework/calculate`
64+
6. Tutaj znajduje się szkielet programu, który musisz wypełnić. Szkielet programu zawiera już testy, które sprawdzą, czy Twoja implementacja jest poprawna. Zanim rozpoczniesz implementację wpisz następujące zaklęcia:
65+
66+
```bash
67+
mkdir build # tworzy katalog build
68+
cd build # przechodzi do katalogu build
69+
cmake .. # generuje system budowania wg przepisu z pliku ../CMakeLists.txt
70+
make # kompiluje
71+
ctest -V # odpala testy
72+
```
73+
74+
7. Zaimplementuj funkcjonalność (najlepiej po kawałku, np. zacznij od samego dodawania)
75+
8. Sprawdź, czy implementacja przechodzi testy - `make` (kompilacja) oraz `ctest -V` (uruchomienie testów)
76+
9. Zrób commit z opisem działającej funkcjonalności - `git commit -am"adding works"`
77+
10. Wróć do punktu 7 i zaimplementuj kolejny kawałek. Jeśli rozwiązanie przechodzi wszystkie testy przejdź do kolejnego punktu
78+
11. Wypchnij zmiany do swojego forka - `git push origin calculate`
79+
12. Wyklikaj Pull Request na GitHubie.
80+
13. Poczekaj chwilę na raport Continuous Integration (CI), aby sprawdzić, czy rozwiązanie kompiluje się i przechodzi testy także na GitHubie.
81+
14. Jeśli jest ✅ - brawo, rozwiązanie jest poprawne. Jeśli jest ❌ kliknij na niego i sprawdź opis błędu. Popraw go (punkty 7-11) i poczekaj na kolejny raport CI.
82+
83+
___
84+
85+
## Dostarczenie kolejnych zadań
86+
87+
Najpierw wróć na gałąź główną - `git checkout master` i postępuj od kroku 4 dla kolejnego zadania (stworzenie nowej gałęzi o innej nazwie)
88+
89+
Możesz zaobserwować, że przełączenie się na inną gałąź spowodowało, że nie masz rozwiązania pierwszego zadania. Spokojnie, jest ono po prostu na innej gałęzi. Możesz do niego wrócić przechodząc na gałąź tego zadania - `git checkout nazwa`.

homework/add-even/CMakeLists.txt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
cmake_minimum_required(VERSION 2.8.2)
2+
3+
set(CMAKE_CXX_STANDARD 17)
4+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
5+
6+
# Download and unpack googletest at configure time
7+
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
8+
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" .
9+
RESULT_VARIABLE result
10+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
11+
if(result)
12+
message(FATAL_ERROR "CMake step for googletest failed: ${result}")
13+
endif()
14+
execute_process(COMMAND ${CMAKE_COMMAND} --build .
15+
RESULT_VARIABLE result
16+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/googletest-download )
17+
if(result)
18+
message(FATAL_ERROR "Build step for googletest failed: ${result}")
19+
endif()
20+
21+
# Prevent overriding the parent project's compiler/linker
22+
# settings on Windows
23+
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
24+
25+
# Add googletest directly to our build. This defines
26+
# the gtest and gtest_main targets.
27+
add_subdirectory(${CMAKE_CURRENT_BINARY_DIR}/googletest-src
28+
${CMAKE_CURRENT_BINARY_DIR}/googletest-build
29+
EXCLUDE_FROM_ALL)
30+
31+
# The gtest/gtest_main targets carry header search path
32+
# dependencies automatically when using CMake 2.8.11 or
33+
# later. Otherwise we have to add them here ourselves.
34+
if (CMAKE_VERSION VERSION_LESS 2.8.11)
35+
include_directories("${gtest_SOURCE_DIR}/include")
36+
endif()
37+
38+
project(addEven)
39+
enable_testing()
40+
41+
add_executable(${PROJECT_NAME} main.cpp)
42+
add_executable(${PROJECT_NAME}-ut test.cpp)
43+
44+
target_link_libraries(${PROJECT_NAME}-ut gtest_main)
45+
add_test(NAME ${PROJECT_NAME}_test COMMAND ${PROJECT_NAME}-ut)

0 commit comments

Comments
 (0)