From 43f7b10225ab91094065a34cca8d8930101f7eb5 Mon Sep 17 00:00:00 2001 From: MrMijagi Date: Wed, 26 Aug 2020 14:18:27 +0200 Subject: [PATCH 1/7] renamed files, added generated translated presentations --- module1/01_types.en.md | 205 ++++++++++++++++++ .../{presentation_types.md => 01_types.pl.md} | 0 module1/02_functions.en.md | 67 ++++++ ...tation_functions.md => 02_functions.pl.md} | 0 module1/03_branches.en.md | 111 ++++++++++ ...entation_branches.md => 03_branches.pl.md} | 0 module1/04_loops.en.md | 125 +++++++++++ .../{presentation_loops.md => 04_loops.pl.md} | 0 module1/05_arrays.en.md | 84 +++++++ ...presentation_arrays.md => 05_arrays.pl.md} | 0 module1/06_homework.en.md | 133 ++++++++++++ ...entation_homework.md => 06_homework.pl.md} | 0 module1/{index.html => index.en.html} | 0 module1/index.pl.html | 137 ++++++++++++ 14 files changed, 862 insertions(+) create mode 100644 module1/01_types.en.md rename module1/{presentation_types.md => 01_types.pl.md} (100%) create mode 100644 module1/02_functions.en.md rename module1/{presentation_functions.md => 02_functions.pl.md} (100%) create mode 100644 module1/03_branches.en.md rename module1/{presentation_branches.md => 03_branches.pl.md} (100%) create mode 100644 module1/04_loops.en.md rename module1/{presentation_loops.md => 04_loops.pl.md} (100%) create mode 100644 module1/05_arrays.en.md rename module1/{presentation_arrays.md => 05_arrays.pl.md} (100%) create mode 100644 module1/06_homework.en.md rename module1/{presentation_homework.md => 06_homework.pl.md} (100%) rename module1/{index.html => index.en.html} (100%) create mode 100644 module1/index.pl.html diff --git a/module1/01_types.en.md b/module1/01_types.en.md new file mode 100644 index 00000000..01bc5457 --- /dev/null +++ b/module1/01_types.en.md @@ -0,0 +1,205 @@ + + +# C ++ basics + +## Data types + + + Coders School + + +___ + +## Simple math + +* 1 byte == 8 bits +* In a binary lottery, randomly selected numbers may have `0` or `1` +* Thus, when drawing 8 numbers, we can get, for example: `1 0 1 0 1 0 1 0` +* There are exactly such combinations `256 -> (2^8)` +* Thus, in 1 byte (8 bits) we can write 256 numbers, e.g. from 0 to 255 +* If we draw 32 numbers in the lottery, (32/8 = 4), i.e. 4 bytes, there are such combinations `2^32` (i.e. over 4 billion) + +___ + +## Empty type - `void` + +* Objects of type cannot be created `void` +* It is used to indicate that the function returns nothing +* You can create pointers `void*` (bad practice in C ++) +* NOT is used to indicate that the function takes no arguments + +```cpp +int fun(void) { /* ... */ } // bad practice, C style +int fun() { /* ... */ } // good practice, C++ style +``` + + +___ + +## Boolean - `bool` + +* Size: at least 1 byte (usually equal to just 1) + * `sizeof(bool) >= 1` +* 2 possible values + * `false` + * `true` + +___ + +## Character types + +* Size: 1 byte +* 256 possible values +* `char` -> from `-128` down `127` +* `unsigned char` -> from `0` down `255` + +Prefix `unsigned` means the type is unsigned (no negative numbers), that is, from 0 to some positive value. + + +The size of character types is always 1 byte. + + +The sizes of further types are platform dependent e.g. 32 bits, 64 bits. + + +___ + +## Integer types + +* `short (unsigned short)` - at least 2 bytes +* `int (unsigned int)` - at least 2 bytes +* `long (unsigned long)` - at least 4 bytes +* `long long (unsigned long long)` - at least 8 bytes + +___ + +## Floating-point types + +* `float` - usually 4 bytes +* `double` - usually 8 bytes +* `long double` - usually 10 bytes (rarely used) +* Floating point types can always be negative (unsigned versions do not exist) +* They have special values: + * `0`, `-0` (negative zero) + * `-Inf`, `+Inf` (Infinity, infinity) + * `NaN` (Not a Number) + +Warning! Comparison `NaN == NaN` gives `false` + + +Advanced Reading: [The IEEE754 standard that defines floating point types](https://en.wikipedia.org/wiki/IEEE_754) + + +___ + +## Type aliases + +There are also types that are aliases (different nomenclature for better understanding of type). + +`std::size_t` depending on the compiler it may be of the type (`unsigned short`, `unsigned int`, `unsigned long`, `unsigned long long`). Usually it is of the type `unsigned int`. It is worth using it when our variable will refer to some size, e.g. the size of an array. + + +We can create our own type aliases using `typedef` or `using` + + +```cpp +typedef int Number; +Number a = 5; // int a = 5; + +using Fraction = double; +Fraction b = 10.2; // double b = 10.2; +``` + + +___ + +## Type `auto` + +In some places we can use type `auto`. The compiler will deduce the type itself, e.g. based on the assigned value. + +```cpp + auto num = 5; // int + auto num = 5u; // unsigned int + auto num = 5.5; // double + auto num = 5.f; // float + auto letter = 'a'; // char + auto num = false; // bool + auto sth; // compilation error, unable to deduce type +``` + +___ + +## Type Sizes + +The C ++ standard defines such a relationship between the sizes of integer types + +```cpp +1 == sizeof(char) \ + <= sizeof(short) \ + <= sizeof(int) \ + <= sizeof(long) \ + <= sizeof(long long); +``` + +___ + +## Arithmetic operations + +* Basic: + - * / +* Modifying a variable: + = - = * = / = +* Incrementing (+1) variable: ++ +* Decrementing (-1) variable: - + +### Examples + +```cpp +int a = 5 + 7; // a = 12 +``` + + +```cpp +int a = 5; +a += 7; // a = 12 +``` + + +```cpp +int a = 5; +++a; // a = 6 +a--; // a = 5 +``` + + +___ + +## Questions + +```cpp +int i = 5; +auto j = i++ - 1; +``` + +How much are the values `i` and `j`? + +`i = 6` + +`j = 4` + +What type is `j`? + +`int` + +___ + +## A little biscuit + +Who is the Hobbit? + +It is 1/8 Hobbyte :) + +___ + +## Links for further knowledge + +* [Fundamental types on cppreference.com](https://en.cppreference.com/w/cpp/language/types) +* [The IEEE754 standard that defines floating point types](https://en.wikipedia.org/wiki/IEEE_754) diff --git a/module1/presentation_types.md b/module1/01_types.pl.md similarity index 100% rename from module1/presentation_types.md rename to module1/01_types.pl.md diff --git a/module1/02_functions.en.md b/module1/02_functions.en.md new file mode 100644 index 00000000..fe3d37af --- /dev/null +++ b/module1/02_functions.en.md @@ -0,0 +1,67 @@ + + +# C ++ basics + +## Functions + + + Coders School + + +___ + +## Functions + +A function is a part of a program that has been given a name and that we can execute by giving its name and any arguments. + +Function == subroutine == routine + +For example, when cycling, our main function is to move from point a to b. However, we also perform several subroutines such as gear shifting, braking, acceleration, turning. Similarly, in a program, we can isolate specific behaviors and transfer them to functions that we will name to suggest what they do. It is important that the function only does one thing. One function changes gears, the other brakes, the third turns. + +___ + +## Function signatures (declarations) + +`void fun(int)` - the function is named fun, returns nothing, and takes one int. + +### Guess signatures by description + +A function called foo that returns nothing and takes one argument of type double. + +`void foo(double)` + +A function called bar that returns type double and takes 2 arguments. The first is float and the second is const int (const means the value cannot be modified). + +`double bar(float, const int)` + +___ + +## Function calls + +`foo(5.0)` -> we call the function `foo` with an argument `double`which is equal to `5.0` + + +`double result = bar(5.4f, 10)` -> we call the function `bar` with an argument `float (5.4f)` and `int (10)` and we assign its result to a variable of type `double` named `result`. + + +___ + +## Task + +Add the missing function `multiply`. It is to multiply the two numbers given as its parameters. [Download the task][homework] + +```cpp +#include + +// Write missing function here + +int main() { + std::cout << "4 * 5: " << multiply(4, 5) << "\n"; + std::cout << "10 * 5: " << multiply(10, 5) << "\n"; + std::cout << "-5 * 5: " << multiply(-5, 5) << "\n"; + + return 0; +} +``` + +[homework]: https://github.com/coders-school/cpp-fundamentals/blob/master/module1/task1.cpp \ No newline at end of file diff --git a/module1/presentation_functions.md b/module1/02_functions.pl.md similarity index 100% rename from module1/presentation_functions.md rename to module1/02_functions.pl.md diff --git a/module1/03_branches.en.md b/module1/03_branches.en.md new file mode 100644 index 00000000..e8bb7939 --- /dev/null +++ b/module1/03_branches.en.md @@ -0,0 +1,111 @@ + + +# C ++ basics + +## Conditional statements + + + Coders School + + +___ + +## Manual `if` + +A conditional instruction is nothing more than asking the program a question, for example: + +* Have you received all the data? +* Has the boss's life dropped to 0? +* Has the achievement been earned by the player? +* Is the number greater than the maximum allowed? + +___ + +## Construction `if` + +```cpp +if (condition) { + // do sth +} +``` + +___ + +## Combining conditions + +What if a lot of information has to be fulfilled? +We can combine conditions with an operator **or** (`||`, `or`) be **and** (`&&`, `and`) + +```cpp +if (are_potatoes_eatten && is_meat_eatten && is_salad_eatten) +``` + + +All 3 conditions must be met + +```cpp +if (player_has_20_dex || player_has_18_int || player_has_22_str) +``` + + +In this case, it is enough to meet one of 3 conditions. They can all be met, but it is enough for any one to be met. + +___ + +## Manual `else` + +If the program can react differently to meeting certain conditions, we can use constructions `if else` + +```cpp +if (number < 2) { + critical_miss(); +} else if (number < 18) { + hit(); +} else { + critical_hit(); +} +``` + +___ + +## Manual `switch/case` + +```cpp +char option = getInput(); +switch (option) { +case 'l': + goLeft(); + break; +case 'r': + goRight(); + break; +default: + exit(); +} +``` + +* `case` stands for a specific case +* `break` announces that we are exiting the conditional statement `switch` and we continue to constitute the program. Its absence will result in the execution of the instructions from the next one `case`. +* `deafult` this is where the program will arrive if no other condition is met + +___ + +## Task + +Add a function `max`. It is supposed to return the maximum of the three given values. [Download the task][homework] + +```cpp +#include + +// Write your function here + +int main() { + std::cout << "max (1, 2, 3): " << max(1, 2, 3) << "\n"; + std::cout << "max (2, 3, 1): " << max(2, 3, 1) << "\n"; + std::cout << "max (3, 2, 1): " << max(3, 2, 1) << "\n"; + + return 0; +} +``` + +[homework]: https://github.com/coders-school/cpp-fundamentals/blob/master/module1/task2.cpp diff --git a/module1/presentation_branches.md b/module1/03_branches.pl.md similarity index 100% rename from module1/presentation_branches.md rename to module1/03_branches.pl.md diff --git a/module1/04_loops.en.md b/module1/04_loops.en.md new file mode 100644 index 00000000..23fa44d1 --- /dev/null +++ b/module1/04_loops.en.md @@ -0,0 +1,125 @@ + + +# C ++ basics + +## Loops + + + Coders School + + +___ + +## Loops + +A loop is used to repeat statements that we want to execute more than once without having to write them over and over in the code. + +Basic loops: `while`, `for` + +___ + +## Loop `while` + +`while` we use when we want to do something until some condition is met. Usually we have no idea when the sequences (we don't know the number of steps), e.g .: + +* We browse the shirts on the Internet until we find a match for us +* We repeat the fight with the same boss until we defeat him +* We eat the soup until the plate is empty +* We search the contacts on the phone until we find the person we are interested in + +___ + +### Loop construction `while` + +```cpp +while (condition) { + // Do sth +} +``` + +### Example + +```cpp +while (a == b) { + std::cin >> a; + std::cin >> b; +} +``` + + +___ + +## Loop `for` + +`for` we use when we want to do something a certain number of times. We usually know the number of steps, e.g. + +* We fill out a questionnaire consisting of 10 questions -> number of steps 10 +* We move from A to B -> number of steps = distance / stride length +* We are writing an exam consisting of 4 tasks -> the number of steps (if we can, 4, if not, we do the subroutine `ściągaj`) +* We fasten our shirts (as long as we don't tear any button out) + +___ + +### Loop construction `for` + +```cpp +for (variable = initial_value; condition; variable_change) { + // Do sth +} +``` + +### Example + +```cpp +for (size_t i = 0 ; i < 10 ; i+=2) { + std::cout << "i: " << i << '\n'; +} +``` + + +___ + +Every loop `for` can be changed to `while` and vice versa. We choose the more convenient notation for us, usually depending on the knowledge of the number of steps. + +There is another type of loop. What? + +___ + +## Loop `do/while` + +```cpp +do { + // Do sth +} while(condition) +``` + +Code in loops `while` or `for` it may not be fulfilled even once the condition is never met. + +Loop code `do/while` will be performed at least once. + +___ + +## Task + +Add a function `printString`. It is to print the text given as the first argument as many times as the value of the number given as the second argument. [Download the task][homework] + +```cpp +#include + +// Write your function here + +int main() { + printString("Hello", 5); + std::cout << "\n"; + + printString("AbC", 2); + std::cout << "\n"; + + printString("HiHi ", 6); + std::cout << "\n"; + + return 0; +} +``` + +[homework]: https://github.com/coders-school/cpp-fundamentals/blob/master/module1/task3.cpp \ No newline at end of file diff --git a/module1/presentation_loops.md b/module1/04_loops.pl.md similarity index 100% rename from module1/presentation_loops.md rename to module1/04_loops.pl.md diff --git a/module1/05_arrays.en.md b/module1/05_arrays.en.md new file mode 100644 index 00000000..791dc3d5 --- /dev/null +++ b/module1/05_arrays.en.md @@ -0,0 +1,84 @@ + + +# C ++ basics + +## Tables + + + Coders School + + +___ + +## Introduction to arrays + +# 🚃🚃🚃🚃🚃🚃🚃🚃🚃🚃 + +* The boards can be treated like wagons in a train +* Arranged one by one and connected to each other +* They can hold different types like human, coal, etc. +* We can write 10 coal wagons as `Coal tab[10]` - it means that we create an array that stores 10 elements of type Coal (coal). + +___ + +Tablica w pamięci + +* In C ++, the array is in one contiguous area in memory and is inseparable (its elements cannot be removed) +* All items are of the same type +* The array is always indexed from 0 +* `tab[0]` - the first element of the array `tab` +* `tab[9]` - the last element of a 10-element array `tab` + +___ + +## Example of array modification + +```cpp +int tab[10]; +tab[0] = 1; +tab[1] = 2; +// ... +tab[9] = 10; +``` + +This could be done better with a loop. + +___ + +### `operator[]` + +We refer to an array element with `operator[]`. We must remember to always refer to an existing array element. Otherwise the program will have undefined behavior as we will try to access memory that is not in the array. We say there is garbage there. At best, the operating system will detect it and we'll get it **crash** (segmentation fault). At worst, we will run on incorrect random data. The effects can be very serious (space shuttle crashes, irradiation from medical apparatus). + +```cpp +int tab[10]; +tab[10] = 42; // !!! undefined behavior (UB) +``` + + +___ + +## Task + +Modify the program so that it fills the array with the following odd numbers: 1, 3, 5, 7, ... [Download the task][homework] + +```cpp +#include + +constexpr size_t tab_size = 100; + +int main() { + int tab[tab_size]; + + for (size_t i = 0; i < tab_size; ++i) { + tab[i] = i; + } + + for (size_t i = 0; i < tab_size; ++i) { + std::cout << tab[i] << "\n"; + } + + return 0; +} +``` + +[homework]: https://github.com/coders-school/cpp-fundamentals/blob/master/module1/task4.cpp diff --git a/module1/presentation_arrays.md b/module1/05_arrays.pl.md similarity index 100% rename from module1/presentation_arrays.md rename to module1/05_arrays.pl.md diff --git a/module1/06_homework.en.md b/module1/06_homework.en.md new file mode 100644 index 00000000..1c1b2313 --- /dev/null +++ b/module1/06_homework.en.md @@ -0,0 +1,133 @@ + + +# C ++ basics + +## Summary + + + Coders School + + +___ + +## What do you remember from today? + +### Write as many passwords as possible in the chat + + +1. Data types + * `void`, `bool`, `char`, `int`, `double` + their varieties +1. Functions + * signature (declaration) = return type, name, arguments +1. Conditional statements + * `if`, `switch/case` +1. Loops + * `for`, `while`, `do/while` +1. Tables + * `Type t[N]`, `operator[]` + +___ + + +## Homework + +### Post-work + + +* Read the documentation [std :: string](https://en.cppreference.com/w/cpp/string/basic_string). You will find there, among others description of the function `std::to_string`. Will be usefull :) +* Task 1 - Calculate (5 points) +* Task 2 - Fibonacci - recursion and iteration (6 points) + + +#### Bonus for punctuality + +For delivering each task before May 24, 2020 (Sunday) until 23:59 you will get 2 bonus points (4 points in total for 2 tasks). + +### Pre-work + +* Read the type documentation [std :: vector](https://en.cppreference.com/w/cpp/container/vector). Click on the different functions and look mainly at the usage examples at the bottom of the pages. +* You can look at the test files in the tasks and try to add your own test cases + +#### [Repo jobs](https://github.com/coders-school/cpp-fundamentals/tree/master/module1/homework) + +___ + + +## Task 1 - Calculate + +Implement a function whose task is to perform arithmetic operations on two numbers. + +Signature - `std::string calculate(const std::string& command, int first, int second)`. + +### Parameters + +* `const std::string& command` - type of action. One of `add`, `subtract`, `multiply`, `divide` +* `int first` - the first number +* `int second` - second number + +### Return value + +* `std::string` - the result of the action as text + +In case of a wrong parameter `command` the function should return the string "Invalid data". + +### Examples of use + +```cpp +auto result = calculate("add", 2, 3); // result = "5" +result = calculate("multiply", 2, 3); // result = "6" +result = calculate("hello", 2, 3); // result = "Invalid data" +``` + +___ + +## Task 2 - Fibonacci + +Implement two functions. Both are to count the nth number [Fibonacci sequence](https://pl.wikipedia.org/wiki/Ciąg_Fibonacci), but in different ways. + +* iterative (using loops) +* recursively (the function is supposed to call itself) + +Functions must have specific signatures: + +```cpp +int fibonacci_iterative(int sequence); +int fibonacci_recursive(int sequence); +``` + +___ + + +## Task delivery + +1. Make a fork repo [c ++ - fundamentals](https://github.com/coders-school/cpp-fundamentals) +2. Get your fork - `git clone https://github.com/YOURNICK/cpp-fundamentals.git` +3. Change to the cpp-fundamentals directory - `cd cpp-fundamentals` +4. Create a branch named `calculate` to solve the problem calculate - `git checkout -b calculate` +5. Go to the directory module1 / homework / calculate - `cd module1/homework/calculate` +6. Here is the skeleton of the program that you must complete. The backbone of the program already includes tests to verify that your implementation is correct. Before starting the implementation, enter the following spells: + +```bash +mkdir build # tworzy katalog build +cd build # przechodzi do katalogu build +cmake .. # generuje system budowania wg przepisu z pliku ../CMakeLists.txt +make # kompiluje +ctest -V # odpala testy +``` + +7. Implement the functionality (preferably piecewise, e.g. start by adding only) +8. Check if the implementation passes the tests - `make` (compilation) and `ctest -V` (test launch) +9. Make a commit with a description of the functionality - `git commit -am"adding works"` +10. Go back to step 7 and implement the next piece. If the solution passes all the tests, go to the next step +11. Push changes to your fork - `git push origin calculate` +12. Click on Pull Request on GitHub. +13. Wait a moment for the Continuous Integration (CI) report to see if the solution compiles and tests on GitHub as well. +14. If there is ✅ - bravo, the solution is correct. If there is ❌ click on it and check the error description. Correct it (points 7-11) and wait for the next CI report. + +___ + +## Delivery of subsequent tasks + +First, go back to the main branch - `git checkout master` and proceed from step 4 for the next task (creating a new branch with a different name) + +You may observe that switching to a different branch has resulted in you missing the solution for the first task. Relax, it's just on a different branch. You can return to it by going to the branch of this quest - `git checkout nazwa`. diff --git a/module1/presentation_homework.md b/module1/06_homework.pl.md similarity index 100% rename from module1/presentation_homework.md rename to module1/06_homework.pl.md diff --git a/module1/index.html b/module1/index.en.html similarity index 100% rename from module1/index.html rename to module1/index.en.html diff --git a/module1/index.pl.html b/module1/index.pl.html new file mode 100644 index 00000000..9fb36ba3 --- /dev/null +++ b/module1/index.pl.html @@ -0,0 +1,137 @@ + + + + + + + C++ - podstawy - Coders School + + + + + + + + + + + + + + + +
+
+
+
+ +

Podstawy C++

+ + Coders School + +

Mateusz Adamski

+

Łukasz Ziobroń

+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+ +

Coders School

+ Coders School + +
+
+
+ + + + + + From 6829b4e07f2ff3a2f53ba3a73f090fefa1866775 Mon Sep 17 00:00:00 2001 From: MrMijagi Date: Wed, 26 Aug 2020 20:39:46 +0200 Subject: [PATCH 2/7] module1 finished --- module1/01_types.en.md | 55 ++++++++++++++++++----------------- module1/01_types.pl.md | 12 ++++---- module1/02_functions.en.md | 28 ++++++++++-------- module1/02_functions.pl.md | 16 ++++++---- module1/03_branches.en.md | 28 +++++++++--------- module1/03_branches.pl.md | 2 +- module1/04_loops.en.md | 38 ++++++++++++------------ module1/04_loops.pl.md | 4 +-- module1/05_arrays.en.md | 18 ++++++------ module1/05_arrays.pl.md | 4 +-- module1/06_homework.en.md | 58 ++++++++++++++++++------------------- module1/img/array.gif | Bin 1042 -> 0 bytes module1/img/array.png | Bin 0 -> 3086 bytes module1/index.en.html | 28 +++++++++--------- module1/index.pl.html | 12 ++++---- 15 files changed, 156 insertions(+), 147 deletions(-) delete mode 100644 module1/img/array.gif create mode 100644 module1/img/array.png diff --git a/module1/01_types.en.md b/module1/01_types.en.md index 01bc5457..d0319145 100644 --- a/module1/01_types.en.md +++ b/module1/01_types.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## Data types @@ -10,23 +10,23 @@ ___ -## Simple math +## Some simple math * 1 byte == 8 bits -* In a binary lottery, randomly selected numbers may have `0` or `1` -* Thus, when drawing 8 numbers, we can get, for example: `1 0 1 0 1 0 1 0` -* There are exactly such combinations `256 -> (2^8)` +* In a binary lottery, randomly selected numbers may have values 0 or 1 +* Thus, when drawing 8 numbers, we can get, for example: 1 0 1 0 1 0 1 0 +* There are exactly 256 -> (2^8) such combinations * Thus, in 1 byte (8 bits) we can write 256 numbers, e.g. from 0 to 255 -* If we draw 32 numbers in the lottery, (32/8 = 4), i.e. 4 bytes, there are such combinations `2^32` (i.e. over 4 billion) +* If we draw 32 numbers in the lottery, (32/8 = 4), i.e. 4 bytes, there are 2^32 such combinations (i.e. over 4 billion) ___ ## Empty type - `void` -* Objects of type cannot be created `void` -* It is used to indicate that the function returns nothing -* You can create pointers `void*` (bad practice in C ++) -* NOT is used to indicate that the function takes no arguments +* Objects of void type cannot be created +* It is used to indicate that the function does not return anything +* You can create void* pointers (bad practice in C++) +* It is NOT used to indicate that the function takes no arguments ```cpp int fun(void) { /* ... */ } // bad practice, C style @@ -50,16 +50,16 @@ ___ * Size: 1 byte * 256 possible values -* `char` -> from `-128` down `127` -* `unsigned char` -> from `0` down `255` +* `char` -> from `-128` to `127` +* `unsigned char` -> from `0` to `255` -Prefix `unsigned` means the type is unsigned (no negative numbers), that is, from 0 to some positive value. +Prefix `unsigned` means that there are no negative numbers i.e. from 0 to some positive value. The size of character types is always 1 byte. -The sizes of further types are platform dependent e.g. 32 bits, 64 bits. +The sizes of further types are platform dependent e.g. 32 bits or 64 bits. ___ @@ -81,7 +81,7 @@ ___ * Floating point types can always be negative (unsigned versions do not exist) * They have special values: * `0`, `-0` (negative zero) - * `-Inf`, `+Inf` (Infinity, infinity) + * `-Inf`, `+Inf` (infinity) * `NaN` (Not a Number) Warning! Comparison `NaN == NaN` gives `false` @@ -94,9 +94,9 @@ ___ ## Type aliases -There are also types that are aliases (different nomenclature for better understanding of type). +There are also types that are aliases (different naming for better understanding of type). -`std::size_t` depending on the compiler it may be of the type (`unsigned short`, `unsigned int`, `unsigned long`, `unsigned long long`). Usually it is of the type `unsigned int`. It is worth using it when our variable will refer to some size, e.g. the size of an array. +`std::size_t` depending on the compiler may be the type (`unsigned short`, `unsigned int`, `unsigned long`, `unsigned long long`). Usually it is the type `unsigned int`. It is worth using it when our variable will refer to some size, e.g. the size of an array. We can create our own type aliases using `typedef` or `using` @@ -113,9 +113,9 @@ Fraction b = 10.2; // double b = 10.2; ___ -## Type `auto` +## `auto` type -In some places we can use type `auto`. The compiler will deduce the type itself, e.g. based on the assigned value. +In some places we can use `auto` type. The compiler will deduce the type itself, e.g. based on the assigned value. ```cpp auto num = 5; // int @@ -131,7 +131,7 @@ ___ ## Type Sizes -The C ++ standard defines such a relationship between the sizes of integer types +The C++ standard defines such a relationship between the sizes of integer types ```cpp 1 == sizeof(char) \ @@ -146,9 +146,9 @@ ___ ## Arithmetic operations * Basic: + - * / -* Modifying a variable: + = - = * = / = +* Modifying a variable: += -= *= /= * Incrementing (+1) variable: ++ -* Decrementing (-1) variable: - +* Decrementing (-1) variable: -- ### Examples @@ -179,7 +179,7 @@ int i = 5; auto j = i++ - 1; ``` -How much are the values `i` and `j`? +What are the values `i` and `j`? `i = 6` @@ -191,15 +191,16 @@ auto j = i++ - 1; ___ -## A little biscuit +## A little joke -Who is the Hobbit? +What do you call 8 hobbits? -It is 1/8 Hobbyte :) +A Hobbyte :) + ___ -## Links for further knowledge +## Links for extending knowledge * [Fundamental types on cppreference.com](https://en.cppreference.com/w/cpp/language/types) * [The IEEE754 standard that defines floating point types](https://en.wikipedia.org/wiki/IEEE_754) diff --git a/module1/01_types.pl.md b/module1/01_types.pl.md index eb48d726..bbd704ec 100644 --- a/module1/01_types.pl.md +++ b/module1/01_types.pl.md @@ -13,19 +13,19 @@ ___ ## Prosta matematyka * 1 bajt == 8 bitów -* W binarnym totolotku wylosowane liczby mogą mieć `0` lub `1` -* Zatem podczas losowania 8 numerków możemy otrzymać przykładowo: `1 0 1 0 1 0 1 0` -* Takich kombinacji jest dokładnie `256 -> (2^8)` +* W binarnym totolotku wylosowane liczby mogą mieć 0 lub 1 +* Zatem podczas losowania 8 numerków możemy otrzymać przykładowo: 1 0 1 0 1 0 1 0 +* Takich kombinacji jest dokładnie 256 -> (2^8) * Zatem na 1 bajcie (8 bitach) możemy zapisać 256 liczb, np. od 0 do 255 -* Jeżeli w totolotku losujemy 32 numerki, (32/8 = 4) czyli 4 bajty to takich kombinacji jest `2^32` (czyli ponad 4 miliardy) +* Jeżeli w totolotku losujemy 32 numerki, (32/8 = 4) czyli 4 bajty to takich kombinacji jest 2^32 (czyli ponad 4 miliardy) ___ ## Typ pusty - `void` -* Nie można tworzyć obiektów typu `void` +* Nie można tworzyć obiektów typu void * Służy do zaznaczenia, że funkcja nic nie zwraca -* Można tworzyć wskaźniki `void*` (zła praktyka w C++) +* Można tworzyć wskaźniki void* (zła praktyka w C++) * NIE służy do oznaczania, że funkcja nie przyjmuje argumentów ```cpp diff --git a/module1/02_functions.en.md b/module1/02_functions.en.md index fe3d37af..61ad7691 100644 --- a/module1/02_functions.en.md +++ b/module1/02_functions.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## Functions @@ -12,11 +12,11 @@ ___ ## Functions -A function is a part of a program that has been given a name and that we can execute by giving its name and any arguments. +A function is a fragment of a program that was given a name and we can execute it by calling its name and pass it possible arguments. -Function == subroutine == routine +Function == subprogram == procedure -For example, when cycling, our main function is to move from point a to b. However, we also perform several subroutines such as gear shifting, braking, acceleration, turning. Similarly, in a program, we can isolate specific behaviors and transfer them to functions that we will name to suggest what they do. It is important that the function only does one thing. One function changes gears, the other brakes, the third turns. +For example, when cycling, our main function is to move from point A to B. However, we also perform several subroutines such as gear shifting, braking, accelerating, turning. Similarly, in a program, we can isolate specific behaviors and transfer them to functions that we will name to suggest what they do. It is important that the function only does one thing. One function changes gears, the other brakes, the third turns. ___ @@ -26,19 +26,23 @@ ___ ### Guess signatures by description -A function called foo that returns nothing and takes one argument of type double. +A function called `foo` that returns nothing and takes one argument of type `double`. + -`void foo(double)` +`void foo(double)` + -A function called bar that returns type double and takes 2 arguments. The first is float and the second is const int (const means the value cannot be modified). +A function called `bar` that returns type double and takes 2 arguments. The first is `float` and the second is `const int` (`const` means the value cannot be modified). + -`double bar(float, const int)` +`double bar(float, const int)` + ___ ## Function calls -`foo(5.0)` -> we call the function `foo` with an argument `double`which is equal to `5.0` +`foo(5.0)` -> we call the function `foo` with an argument `double` which is equal to `5.0` `double result = bar(5.4f, 10)` -> we call the function `bar` with an argument `float (5.4f)` and `int (10)` and we assign its result to a variable of type `double` named `result`. @@ -46,9 +50,9 @@ ___ ___ -## Task +## Exercise -Add the missing function `multiply`. It is to multiply the two numbers given as its parameters. [Download the task][homework] +Add the missing function `multiply`. It is supposed to multiply two numbers given as its parameters. [Download the exercise][homework] ```cpp #include @@ -64,4 +68,4 @@ int main() { } ``` -[homework]: https://github.com/coders-school/cpp-fundamentals/blob/master/module1/task1.cpp \ No newline at end of file +[homework]: https://github.com/coders-school/cpp-fundamentals/blob/master/module1/task1.cpp diff --git a/module1/02_functions.pl.md b/module1/02_functions.pl.md index c863d617..54003cd1 100644 --- a/module1/02_functions.pl.md +++ b/module1/02_functions.pl.md @@ -16,7 +16,7 @@ Funkcja jest to fragment programu, któremu nadano nazwę i który możemy wykon Funkcja == podprogram == procedura -Przykładowo, w trakcie jazdy na rowerze naszą główną funkcją jest przemieszczanie się z punktu a do b. Jednak wykonujemy także kilka podprogramów, jak zmiana biegów, hamowanie, rozpędzanie, skręcanie. Podobnie w programie możemy wydzielić konkretne zachowania i przenieść je do funkcji, które nazwiemy tak, by sugerowały co robią. Ważne, aby funkcja robiła tylko jedną rzecz. Jedna funkcja zmienia biegi, druga hamuje, trzecia skręca. +Przykładowo, w trakcie jazdy na rowerze naszą główną funkcją jest przemieszczanie się z punktu A do B. Jednak wykonujemy także kilka podprogramów, jak zmiana biegów, hamowanie, rozpędzanie, skręcanie. Podobnie w programie możemy wydzielić konkretne zachowania i przenieść je do funkcji, które nazwiemy tak, by sugerowały co robią. Ważne, aby funkcja robiła tylko jedną rzecz. Jedna funkcja zmienia biegi, druga hamuje, trzecia skręca. ___ @@ -26,13 +26,17 @@ ___ ### Odgadnijcie sygnatury po opisie -Funkcja o nazwie foo, która nic nie zwraca a przyjmuje jeden argument typu double. +Funkcja o nazwie `foo`, która nic nie zwraca a przyjmuje jeden argument typu `double`. + -`void foo(double)` +`void foo(double)` + -Funkcja o nazwie bar, która zwraca typ double a przyjmuje 2 argumenty. Pierwszy to float, a drugi to const int (const oznacza, że wartość ta nie może zostać zmodyfikowana). +Funkcja o nazwie `bar`, która zwraca typ double a przyjmuje 2 argumenty. Pierwszy to `float`, a drugi to `const int` (`const` oznacza, że wartość ta nie może zostać zmodyfikowana). + -`double bar(float, const int)` +`double bar(float, const int)` + ___ @@ -64,4 +68,4 @@ int main() { } ``` -[zadanie-domowe]: https://github.com/coders-school/cpp-fundamentals/blob/master/module1/task1.cpp \ No newline at end of file +[zadanie-domowe]: https://github.com/coders-school/cpp-fundamentals/blob/master/module1/task1.cpp diff --git a/module1/03_branches.en.md b/module1/03_branches.en.md index e8bb7939..78d5df4f 100644 --- a/module1/03_branches.en.md +++ b/module1/03_branches.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## Conditional statements @@ -10,9 +10,9 @@ ___ -## Manual `if` +## `if` statement -A conditional instruction is nothing more than asking the program a question, for example: +A conditional statement is nothing more than asking the program a question, for example: * Have you received all the data? * Has the boss's life dropped to 0? @@ -21,7 +21,7 @@ A conditional instruction is nothing more than asking the program a question, fo ___ -## Construction `if` +## `if` construction ```cpp if (condition) { @@ -33,8 +33,8 @@ ___ ## Combining conditions -What if a lot of information has to be fulfilled? -We can combine conditions with an operator **or** (`||`, `or`) be **and** (`&&`, `and`) +What if a lot of conditions have to be met? +We can combine conditions with an operator **or** (`||`, `or`) or **and** (`&&`, `and`) ```cpp if (are_potatoes_eatten && is_meat_eatten && is_salad_eatten) @@ -48,13 +48,13 @@ if (player_has_20_dex || player_has_18_int || player_has_22_str) ``` -In this case, it is enough to meet one of 3 conditions. They can all be met, but it is enough for any one to be met. +In this case, it is enough to meet one of 3 conditions. They can all be met, but it is enough for any of them to be met. ___ -## Manual `else` +## `else` statement -If the program can react differently to meeting certain conditions, we can use constructions `if else` +If the program can react differently to meeting certain conditions, we can use `if else` constructions ```cpp if (number < 2) { @@ -68,7 +68,7 @@ if (number < 2) { ___ -## Manual `switch/case` +## `switch/case` statement ```cpp char option = getInput(); @@ -85,14 +85,14 @@ default: ``` * `case` stands for a specific case -* `break` announces that we are exiting the conditional statement `switch` and we continue to constitute the program. Its absence will result in the execution of the instructions from the next one `case`. -* `deafult` this is where the program will arrive if no other condition is met +* `break` announces that we are exiting the conditional statement `switch` and we continue with the rest of the program. Its absence will result in the execution of the instructions from the next `case`. +* `default` is place where program will end up if no other condition is met ___ -## Task +## Exercise -Add a function `max`. It is supposed to return the maximum of the three given values. [Download the task][homework] +Add a function `max`. It is supposed to return the maximum of the three given values. [Download the exercise][homework] ```cpp #include diff --git a/module1/03_branches.pl.md b/module1/03_branches.pl.md index e23fe615..f27cec64 100644 --- a/module1/03_branches.pl.md +++ b/module1/03_branches.pl.md @@ -86,7 +86,7 @@ default: * `case` oznacza konkretny przypadek * `break` informuje, że wychodzimy z instrukcji warunkowej `switch` i konstytuujemy dalej program. Jego brak spowoduje, że wykonają się instrukcje z kolejnego `case`. -* `deafult` jest to miejsce gdzie program dotrze, gdy żaden inny warunek nie zostanie spełniony +* `default` jest to miejsce gdzie program dotrze, gdy żaden inny warunek nie zostanie spełniony ___ diff --git a/module1/04_loops.en.md b/module1/04_loops.en.md index 23fa44d1..02bb6a5f 100644 --- a/module1/04_loops.en.md +++ b/module1/04_loops.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## Loops @@ -18,18 +18,18 @@ Basic loops: `while`, `for` ___ -## Loop `while` +## `while` loop -`while` we use when we want to do something until some condition is met. Usually we have no idea when the sequences (we don't know the number of steps), e.g .: + We use `while` when we want to do something until some condition is met. Usually we have no idea when it is going to happen (we don't know the number of steps), e.g .: * We browse the shirts on the Internet until we find a match for us * We repeat the fight with the same boss until we defeat him * We eat the soup until the plate is empty -* We search the contacts on the phone until we find the person we are interested in +* We search through the contacts on the phone until we find the person we want to talk to ___ -### Loop construction `while` +### `while` loop construction ```cpp while (condition) { @@ -49,18 +49,18 @@ while (a == b) { ___ -## Loop `for` +## `for` loop -`for` we use when we want to do something a certain number of times. We usually know the number of steps, e.g. +We use `for` when we want to do something a certain number of times. We usually know the number of steps, e.g. -* We fill out a questionnaire consisting of 10 questions -> number of steps 10 -* We move from A to B -> number of steps = distance / stride length -* We are writing an exam consisting of 4 tasks -> the number of steps (if we can, 4, if not, we do the subroutine `ściągaj`) +* We fill out a questionnaire consisting of 10 questions -> number of steps: 10 +* We move from point A to B -> number of steps = distance / step length +* We are writing an exam consisting of 4 tasks -> the number of steps (if we are prepared, 4, if not, we do the subroutine `cheat`) * We fasten our shirts (as long as we don't tear any button out) ___ -### Loop construction `for` +### `for` loop construction ```cpp for (variable = initial_value; condition; variable_change) { @@ -79,13 +79,13 @@ for (size_t i = 0 ; i < 10 ; i+=2) { ___ -Every loop `for` can be changed to `while` and vice versa. We choose the more convenient notation for us, usually depending on the knowledge of the number of steps. +Every loop `for` can be changed to `while` and vice versa. We choose the more convenient notation for us, usually depending if we know the number of steps. -There is another type of loop. What? +But there is another type of loop. ___ -## Loop `do/while` +## `do/while` loop ```cpp do { @@ -93,15 +93,15 @@ do { } while(condition) ``` -Code in loops `while` or `for` it may not be fulfilled even once the condition is never met. +Code in `while` or `for` loops may not be executed even once if the condition is never met. -Loop code `do/while` will be performed at least once. +Code in `do/while` loop will be performed at least once. ___ -## Task +## Exercise -Add a function `printString`. It is to print the text given as the first argument as many times as the value of the number given as the second argument. [Download the task][homework] +Add a function `printString`. It is supposed to print the text given in the first argument as many times as the value of the number given in the second argument. [Download the exercise][homework] ```cpp #include @@ -122,4 +122,4 @@ int main() { } ``` -[homework]: https://github.com/coders-school/cpp-fundamentals/blob/master/module1/task3.cpp \ No newline at end of file +[homework]: https://github.com/coders-school/cpp-fundamentals/blob/master/module1/task3.cpp diff --git a/module1/04_loops.pl.md b/module1/04_loops.pl.md index 827b545c..066e9862 100644 --- a/module1/04_loops.pl.md +++ b/module1/04_loops.pl.md @@ -20,7 +20,7 @@ ___ ## Pętla `while` -`while` używamy, gdy chcemy coś wykonać dopóki nie zostanie spełniony jakiś warunek. Przeważnie nie mamy pojęcia, kiedy to następy (nie znamy liczby kroków) np: +`while` używamy, gdy chcemy coś wykonać dopóki nie zostanie spełniony jakiś warunek. Przeważnie nie mamy pojęcia, kiedy to nastąpi (nie znamy liczby kroków) np: * Przeglądamy koszule w Internecie dopóki nie znajdziemy pasującej do nas * Powtarzamy walkę z tym samym bossem aż go nie pokonamy @@ -122,4 +122,4 @@ int main() { } ``` -[zadanie-domowe]: https://github.com/coders-school/cpp-fundamentals/blob/master/module1/task3.cpp \ No newline at end of file +[zadanie-domowe]: https://github.com/coders-school/cpp-fundamentals/blob/master/module1/task3.cpp diff --git a/module1/05_arrays.en.md b/module1/05_arrays.en.md index 791dc3d5..5ace110e 100644 --- a/module1/05_arrays.en.md +++ b/module1/05_arrays.en.md @@ -1,8 +1,8 @@ -# C ++ basics +# C++ basics -## Tables +## Arrays Coders School @@ -14,16 +14,16 @@ ___ # 🚃🚃🚃🚃🚃🚃🚃🚃🚃🚃 -* The boards can be treated like wagons in a train +* Arrays can be treated like wagons in a train * Arranged one by one and connected to each other * They can hold different types like human, coal, etc. -* We can write 10 coal wagons as `Coal tab[10]` - it means that we create an array that stores 10 elements of type Coal (coal). +* We can write 10 coal wagons as Coal tab[10] - it means that we create an array that stores 10 elements of type Coal. ___ -Tablica w pamięci +Array in memory -* In C ++, the array is in one contiguous area in memory and is inseparable (its elements cannot be removed) +* In C++, the array is in one continuous area in memory and is inseparable (its elements cannot be removed) * All items are of the same type * The array is always indexed from 0 * `tab[0]` - the first element of the array `tab` @@ -47,7 +47,7 @@ ___ ### `operator[]` -We refer to an array element with `operator[]`. We must remember to always refer to an existing array element. Otherwise the program will have undefined behavior as we will try to access memory that is not in the array. We say there is garbage there. At best, the operating system will detect it and we'll get it **crash** (segmentation fault). At worst, we will run on incorrect random data. The effects can be very serious (space shuttle crashes, irradiation from medical apparatus). +We refer to an array element with `operator[]`. We must remember to always refer to an existing array element. Otherwise the program will have undefined behavior as we will try to access memory that is not in the array. It's called garbage. At best, the operating system will detect it and we'll get a **crash** (segmentation fault). At worst, we will work on some incorrect random data. The effects can be very serious (space shuttle crashes, irradiation from medical apparatus). ```cpp int tab[10]; @@ -57,9 +57,9 @@ tab[10] = 42; // !!! undefined behavior (UB) ___ -## Task +## Exercise -Modify the program so that it fills the array with the following odd numbers: 1, 3, 5, 7, ... [Download the task][homework] +Modify the program so that it fills the array with the following odd numbers: 1, 3, 5, 7, ... [Download the exercise][homework] ```cpp #include diff --git a/module1/05_arrays.pl.md b/module1/05_arrays.pl.md index 1f82087a..f01c93b0 100644 --- a/module1/05_arrays.pl.md +++ b/module1/05_arrays.pl.md @@ -17,11 +17,11 @@ ___ * Tablice można traktować jak wagony w pociągu * Ustawione kolejno jeden po drugim i połączone ze sobą * Mogą pomieścić różne typy, jak człowiek, węgiel, itp. -* 10 wagonów z węglem możemy zapisać jako `Coal tab[10]` - oznacza to, że tworzymy tablicę, która przechowuje 10 elementów typu Coal (węgiel). +* 10 wagonów z węglem możemy zapisać jako Coal tab[10] - oznacza to, że tworzymy tablicę, która przechowuje 10 elementów typu Coal (węgiel). ___ -Tablica w pamięci +Tablica w pamięci * W C++ tablica znajduje się w jednym, ciągłym obszarze w pamięci i jest nierozłączna (nie można usuwać jej elementów) * Wszystkie elementy są tego samego typu diff --git a/module1/06_homework.en.md b/module1/06_homework.en.md index 1c1b2313..12e071bc 100644 --- a/module1/06_homework.en.md +++ b/module1/06_homework.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## Summary @@ -12,7 +12,7 @@ ___ ## What do you remember from today? -### Write as many passwords as possible in the chat +### Write as many keywords as possible in the chat 1. Data types @@ -23,7 +23,7 @@ ___ * `if`, `switch/case` 1. Loops * `for`, `while`, `do/while` -1. Tables +1. Arrays * `Type t[N]`, `operator[]` ___ @@ -33,11 +33,11 @@ ___ ### Post-work - -* Read the documentation [std :: string](https://en.cppreference.com/w/cpp/string/basic_string). You will find there, among others description of the function `std::to_string`. Will be usefull :) + +* Read about [std::string](https://en.cppreference.com/w/cpp/string/basic_string) in the documentation. You will find there, among others, description of `std::to_string` function. It will be useful 🙂 * Task 1 - Calculate (5 points) * Task 2 - Fibonacci - recursion and iteration (6 points) - + #### Bonus for punctuality @@ -45,10 +45,10 @@ For delivering each task before May 24, 2020 (Sunday) until 23:59 you will get 2 ### Pre-work -* Read the type documentation [std :: vector](https://en.cppreference.com/w/cpp/container/vector). Click on the different functions and look mainly at the usage examples at the bottom of the pages. +* Read about the [std :: vector](https://en.cppreference.com/w/cpp/container/vector) type documentation. Click on the different functions and look mainly at the usage examples at the bottom of the pages. * You can look at the test files in the tasks and try to add your own test cases -#### [Repo jobs](https://github.com/coders-school/cpp-fundamentals/tree/master/module1/homework) +#### [Repo tasks](https://github.com/coders-school/cpp-fundamentals/tree/master/module1/homework) ___ @@ -61,17 +61,17 @@ Signature - `std::string calculate(const std::string& command, int first, int se ### Parameters -* `const std::string& command` - type of action. One of `add`, `subtract`, `multiply`, `divide` -* `int first` - the first number +* `const std::string& command` - type of arithmetic operation. One of `add`, `subtract`, `multiply`, `divide` +* `int first` - first number * `int second` - second number ### Return value -* `std::string` - the result of the action as text +* `std::string` - the result of the operation as text In case of a wrong parameter `command` the function should return the string "Invalid data". -### Examples of use +### Examples ```cpp auto result = calculate("add", 2, 3); // result = "5" @@ -83,7 +83,7 @@ ___ ## Task 2 - Fibonacci -Implement two functions. Both are to count the nth number [Fibonacci sequence](https://pl.wikipedia.org/wiki/Ciąg_Fibonacci), but in different ways. +Implement two functions. Both are supposed to count the n-th number of [Fibonacci sequence](https://pl.wikipedia.org/wiki/Ciąg_Fibonacci), but in different ways. * iterative (using loops) * recursively (the function is supposed to call itself) @@ -100,34 +100,34 @@ ___ ## Task delivery -1. Make a fork repo [c ++ - fundamentals](https://github.com/coders-school/cpp-fundamentals) +1. Fork a repo [cpp-fundamentals](https://github.com/coders-school/cpp-fundamentals) 2. Get your fork - `git clone https://github.com/YOURNICK/cpp-fundamentals.git` -3. Change to the cpp-fundamentals directory - `cd cpp-fundamentals` -4. Create a branch named `calculate` to solve the problem calculate - `git checkout -b calculate` -5. Go to the directory module1 / homework / calculate - `cd module1/homework/calculate` -6. Here is the skeleton of the program that you must complete. The backbone of the program already includes tests to verify that your implementation is correct. Before starting the implementation, enter the following spells: +3. Go to the cpp-fundamentals directory - `cd cpp-fundamentals` +4. Create a branch named `calculate` for calculate problem solution - `git checkout -b calculate` +5. Go to the directory module1/homework/calculate - `cd module1/homework/calculate` +6. Here is the backbone of the program that you must complete. It already includes tests to verify that your implementation is correct. Before starting the implementation, enter the following commands: ```bash -mkdir build # tworzy katalog build -cd build # przechodzi do katalogu build -cmake .. # generuje system budowania wg przepisu z pliku ../CMakeLists.txt -make # kompiluje -ctest -V # odpala testy +mkdir build # creates build directory +cd build # change directory to build +cmake .. # generates Makefile by following instructions from ../CMakeLists.txt +make # compilation +ctest -V # running tests ``` -7. Implement the functionality (preferably piecewise, e.g. start by adding only) +7. Implement the functionality (piece by piece, e.g. start from adding operation only) 8. Check if the implementation passes the tests - `make` (compilation) and `ctest -V` (test launch) 9. Make a commit with a description of the functionality - `git commit -am"adding works"` -10. Go back to step 7 and implement the next piece. If the solution passes all the tests, go to the next step +10. Go back to step 7 and implement next functionality. If the solution passes all tests, go to the next step 11. Push changes to your fork - `git push origin calculate` 12. Click on Pull Request on GitHub. -13. Wait a moment for the Continuous Integration (CI) report to see if the solution compiles and tests on GitHub as well. -14. If there is ✅ - bravo, the solution is correct. If there is ❌ click on it and check the error description. Correct it (points 7-11) and wait for the next CI report. +13. Wait a moment for the Continuous Integration (CI) report to see if the solution compiles and tests pass on GitHub as well. +14. If there is ✅ - good job, the solution is correct. If there is ❌ click on it and check the error description. Correct it (points 7-11) and wait for the next CI report. ___ -## Delivery of subsequent tasks +## Delivery of remaining tasks First, go back to the main branch - `git checkout master` and proceed from step 4 for the next task (creating a new branch with a different name) -You may observe that switching to a different branch has resulted in you missing the solution for the first task. Relax, it's just on a different branch. You can return to it by going to the branch of this quest - `git checkout nazwa`. +You may notice that switching to a different branch has resulted in you missing the solution for the first task. Don't worry, it's just on a different branch. You can return to it by going to the branch of this task - `git checkout nazwa`. diff --git a/module1/img/array.gif b/module1/img/array.gif deleted file mode 100644 index 74352787009db56af2c24725b49da2c36d8c030a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1042 zcmV+t1nv7rNk%w1VSNF500000EC2ui0DS>^0HFW>{{R300{?`MsmtvTqnxzbi?iOm z`wxcVNS5Y_rs~SJ?hD8AOxN~}=lag~{tpZahs2`sh)gP%%%<}RjY_A~sudT=2Cm$$ zSG7HazvQwRqs^Yz>~>-dfV=1P>sVdS>!sSbd=D5XI7nD%c!-#&xX9S(_y`#(IZ0V* zd5M{+xyjk-`3V{-I!cO=c8Z#+y2{%6R|WkhGJ;INP3h>09Yl3Fqu zCsSGi*0MrOmy>GbKxs8T0Vt@`gO zR)AZ(M$qb2W7x3^z>-yYHm%vT+l=@mm(b7Jw?yH(pewiA+_-s7@xArekKeWLia@NZ z@NU__bDxQE+~RQJH;T)~foy{?L&}d4gDK3Jg)YgW9gtpO@p9;2JkqS53_JEwytrN= zb?rH~>Jhj*GdMk)uWi}8S?hp<9CPvI*bvvY%-cC=-57l{S2#Sn_3XfJ?&wH7IdyZr zuM;; z8OSIicKRJR#6y)$&=>_p5;>#d4Zi3@&vkrpst*DWac}&}pfl7J6!?EtMK-52lLx%b#BzMe8@R z5_!_Cv)a0;t+o zDWFW2(uYd8C}Ddoc_40UY_7hVi=<%#ty*ll@T?0$vfnyutdH*^v5>vM_M5Fe)1G^w zy9Cd;qY~aoDsH~$Vngr54MU9U!jCHHFk|&{n{d7r3w!~?>JDsj$yDfjaKr{HOmVU? z1G=Mo`x@v3tEj@-TB=d#?5fY-3H=1nJ@Y&?(nVLgv#YJPwldQ}D@`KNIZJ)C(@jG? zh0#fCJvG=rWBoPPVVnK4pK7nocH3^h4fon_&P{jScHfP6-g@uNci(>h4S3*!4^DXD Mh98djJOuy%J6p#ZbN~PV diff --git a/module1/img/array.png b/module1/img/array.png new file mode 100644 index 0000000000000000000000000000000000000000..0c26cf444cb498a508c81cb6ed0b58f38dcb2d89 GIT binary patch literal 3086 zcmZuz2T+sQ7EWLZN_9n1kh1CzxFDb+RUjZzeig8V78Dc(A=D6hNyHT!BK}c8Bp|B- zhTdUmaTR${X#znA30XHvO(8S`A-wFHH@k1%?wxz@x$~Ww@18UFe0R?6Q*O?Ra_Vw0 z7)%j#Id%pHgQrN&iJK6T{jB`;^Ag}ju!F-X(81w{NNhx4aOf2nY~O>F2R1IR?RKV5 z6yI^wPm9g^yydx-_m=HZ5A{`F9St_9pYg{|Yab4FIpeD#Gm>^4c^4(SBj~)QuZ%rk z_6>Ca9B@1?GWxOp);x==#av_NwDMp@r!SI6P2r_^SDt@9c<>2&d(wsP?RHAnXS#eC zQkm{juZcpZhd%fB9#^gzMZ$hEPo8!>YWH;;Zewo|a zEk>=Pw=GlE6cYz0T~l|BJ*sy#_s1PDP}8439Chrp>AM}ZMh5v!7G;mrF$`kof!q;~ zkG>_A85Y@Dc3byc9y;YDqxy3_=6SBmK*ERD+OZ-KOJ(a{e-Hpim1b!mziErO72dgd zIAYqtr)yn}NT+KB=bw5vad-jr@B)}Ph;^_AUb^GC_EndEaDyfdXpV5kKRPHbkim%EQJUW78c*Vz4Nf0JI}QXnh;k6FY#n! zj$=zFj!i+5cR^e_;e1SDB}3@YikFzpkuKiRFqpi`9}5o4%ik#hWpSXZqbz%q`qm%x zE()hdVK6y4@RA50}I48 z6Do~*uOq+4_S*7RQy~(mZh16kB5@>fxs|!jZLo&`@E<2}KQ#|92Ohf#W`RPt+A-6; zU`o393+U!vdx$!!CalIdLFx0l)t1zIm7Bpa{0UtPcAtxY19ZA>Wo`0*>8cBoZlpqb zuo3B20+CE6tc4nZGj%0+pjzS6cXKY-?;{`f=zyB(sVIh=FCrfyQm|0^Rw;r07EbV) zA>WM}(ng?#K_G5M7E~|ZeM8*OWC4oZTRpDp~VIY*b&uzFeryJ`NRiK8=O@AsX)+(wW(uS}G8%wVxu};;B12 zYUH_UUkSwQTn%`I$3e1VU#5g|$qs&J`gE};JA1k(4mMuB87(0m?9chXi2sQ8`hm$7 zp2L&Y3#cz&cY_N6b?8%0U9s<82*=W3KKO_9(mMd^KQjI47<&Rd5o9f`#ZNQ{Q}E$E zG)x68WXiq6edu47b!Hhz7r_?*4UIoy{|;v6wzQMY>iw3iUgqSX8GY`xH5>(l?g;c7 zQ>5>%PBUscK!?U3uz6OcE5C&>`o|Vu0Z3N?_X0+8rnAp_E-SxYjLY4%-1FoWH;1F+8SNnd$M zK@$v>cnW&WBS6b;Dh~3~6XKxZ=(aUW%5BOG)Y1ZZbx)*8WH=OHRgoYQsn5?-C7f@H zLfLqss!GY2vJm;|N(S!u&9EaERvJ}TVHm5*B`iyebv9ibDRP|csz5M@ew|CRWUfqe zR+B)b6M|UQXa%WYAfN}eWQS_6CU+djGArOvIjflk7+36mz9+?lwabQ<$HuYtvq%-a zx9dM-*iPN7o4mI!d<39#*LE`JIf-Gj+ZhO7x#TUmGxcAK8s_6&$`MA0RO#fl5g%eG z#u*1IgmdRAXl9{tGLa`xDP~mpxoPE~_{j`l!c9O2E*{Qq!DYr3hL7Y(MPRhIg%$7% zSl4LQ^=1VL8L!dzSG-umsF;YV29M!)v7I?h?9Y|0XV!O_dS3LV7xu+v9a2Q7D`K;2sA|0F0nD(j^GUcNNT zilxtzZl{e)T|6t;HCL|-Gi!w7Xi0{*9)Bhzskz#xDnC=kwbC<-^0gL{`ir)dSxFV_;Z7Cn%b&-&7K_#yYiQOs+N>WuFvo@0mWOA zFXS&7;lWII>=md2NVJyzGdHFuUVl443F0~4PH-&uTG zQeRC<&3^&*2H)e40?vBgrtl&>NLS*50y6w3@j*~*L)`^gTTxGg%!ilbFu!lN89uU{ z|DG6nwJ82#NfG`+5*dHB{kPYUwJjCd_+`>q&_7WkxuAiA@5o_~FBdm2o*KeT@q|&? z4No73w`bBJ(LU-7V6fxBVqp%O$my<`wpm;esEb?LGxTEAS9dg+Hx3fp8V39Eeo17{ z4?be3QPk$BwHnRzB7usn;>0JVs=-(a2^5=C4J$@kLW(@u1c!~U zjYQnYV1$E@vTh4`oq?G`zTlLs=p}g0ayGzOwFwfthBVyT)Q?BEu0IsUYpz9ib_wjc z=aN)DP0AmT*{_{cereH_twIQr-asUmD6W+sTTuJfEo}^=c@8i4hM+emOEoLTd-id> zP)N9&3>RSp=Stab7HzS3K{ivoT4(!s;C`7liH+vmi^M=1F4(s~8>K5!J^e@4q-;^| zm%1jDzfLvc+rdb~>TNxq`;6c;_#i3$a~I_-VbXJ$20uKlNpUBrbZ2WSTc;01^eS~7 zG;|KnZ4g;f%!zIFB zIeUqs>GElhR=U@0Hh?^d#Xte{lk(k*%ADv*7lDwbWz4Bzn%%u(#H54mCUrRGL5%Q4 zm@tOaz+=8$-1w22d9x)f09sS}Iy)5}UqUWc{`HQxT&ULUylivMfENZHB#pinhWfIi zr^M;S0@Vcr&6DrRGrA+kcesU*c=q|EZsxnOp2I8d(g}l*HAb|rN|T|b6dD(8xoBTk zpJEdJOONiiLRu?+@u=IVhL1av8U>0CsJyQMfv=xyjDAQIUkKuj4;9R$nMDVAKY1c% zHj3n>XQm5B!#DbXz7Rh-l2A7h@@?(6S>OGWq{0N|Kuc6wM}ExLy&9_%L+{-_7R(Bq zOINzn#Xl>)LKax|P_#nb1RuJ5c^%xcFj{ZHI5V)^@aj|?o=YN+DTewVHs#NeR~dGJ zXHTm4Ee!E&V@>#bSY;W3^P$paQX?=-*-WQwa~+NCoR> - C++ - podstawy - Coders School + C++ - basics - Coders School @@ -31,7 +31,7 @@
-

Podstawy C++

+

C++ basics

Coders School @@ -44,18 +44,18 @@

Łukasz Ziobroń

## Agenda - 1. Typy danych - 1. Funkcje - 1. Instrukcje warunkowe - 1. Pętle - 1. Tablice + 1. Data types + 1. Functions + 1. Conditional statements + 1. Loops + 1. Arrays
+
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ +

Coders School

+ Coders School + +
+ + + + + + + + diff --git a/module2/index.html b/module2/index.pl.html similarity index 93% rename from module2/index.html rename to module2/index.pl.html index 794535cd..2ccc89e1 100644 --- a/module2/index.html +++ b/module2/index.pl.html @@ -93,31 +93,31 @@

Łukasz Ziobroń

You can change the port by using npm start -- --port=8001. --> -
-
-
-
-
-
-
From d01feac34960bdd6702809ff2097f665b3748fd6 Mon Sep 17 00:00:00 2001 From: MrMijagi Date: Thu, 27 Aug 2020 16:08:28 +0200 Subject: [PATCH 4/7] module2 finished --- module1/06_homework.en.md | 2 +- module2/02_vector.en.md | 10 +++---- module2/03_range_for.en.md | 20 ++++++------- module2/03_range_for.pl.md | 4 +-- module2/04_string.en.md | 16 +++++----- module2/05_list.en.md | 18 ++++++------ module2/05_list.pl.md | 4 +-- module2/06_map.en.md | 27 +++++++++-------- module2/06_map.pl.md | 11 ++++--- module2/07_homework.en.md | 60 +++++++++++++++++++------------------- module2/index.en.html | 2 +- 11 files changed, 86 insertions(+), 88 deletions(-) diff --git a/module1/06_homework.en.md b/module1/06_homework.en.md index 12e071bc..fcd81823 100644 --- a/module1/06_homework.en.md +++ b/module1/06_homework.en.md @@ -34,7 +34,7 @@ ___ ### Post-work -* Read about [std::string](https://en.cppreference.com/w/cpp/string/basic_string) in the documentation. You will find there, among others, description of `std::to_string` function. It will be useful 🙂 +* Read about [std::string](https://en.cppreference.com/w/cpp/string/basic_string) in the documentation. You will find there, among others, description of `std::to_string` function. It will be useful 🙂 * Task 1 - Calculate (5 points) * Task 2 - Fibonacci - recursion and iteration (6 points) diff --git a/module2/02_vector.en.md b/module2/02_vector.en.md index 6c870fc5..fdd88bd6 100644 --- a/module2/02_vector.en.md +++ b/module2/02_vector.en.md @@ -14,15 +14,15 @@ ___ * very widely used * dynamic array -* we do not have to specify in advance how many elements there should be -* is in one contiguous memory area (like an array) +* we do not have to specify how many elements we want in advance +* it is in one continuous memory area (like an array) * it manages the memory itself - * will take care of allocating new memory when it is needed - * will take care of memory deallocation when we no longer need it + * it will take care of allocating new memory when it is needed + * it will take care of memory deallocation when we no longer need it ___ -## Create a vector +## Creating a vector ```cpp std::vector numbers; diff --git a/module2/03_range_for.en.md b/module2/03_range_for.en.md index 42b37bdb..f0967c2b 100644 --- a/module2/03_range_for.en.md +++ b/module2/03_range_for.en.md @@ -1,8 +1,8 @@ -# C ++ basics +# C++ basics -## Loop `for` after collection +## `for` loop over container Coders School @@ -15,13 +15,13 @@ ___ * Each container (including an array or vector) has its end and beginning * function `begin()` returns the beginning of the container * function `end()` returns the end of the container - * (in a very simplified way, we will extend the topic with iterators) + * (in a very simplified way, we will elaborate on this topic with iterators) ___ ## Range based `for` loop -Thanks to the start and end of range information, we can write a loop iterating through the entire scope of the container. +Thanks to the information about start and end of range, we can write a loop iterating through the entire scope of the container. ```cpp @@ -32,10 +32,10 @@ for (auto i = vec.begin(); i != vec.end(); ++i) { ``` -However, such a notation is unnecessarily complex and not readable. -That is why they were created `range loop` that allow easy writing `for (typ nazwa : kontener)`. +However, this notation is unnecessarily complex and unreadable. +That is why `range loop` were created which allow easy notation `for (type name : container)`. -The compiler can generate it by itself, if we use the notation below. +The compiler can generate code above, if we use the notation below. ```cpp for (auto element : vec) { @@ -48,7 +48,7 @@ ___ ## Task -Write a function `printVector`which he will take as an argument `std::vector` and print its contents using a for loop on the collection. +Write a function `printVector` which will take `std::vector` as an argument and print its contents using a `for` loop over the collection. Each item on a new line. [Download the task][task1] @@ -76,8 +76,8 @@ ___ ## Task -Write a function `concatenateVector`which will take 2 vectors as arguments and then return one which will contain alternating elements from the first and second vector. -For example, for the following vec1 and vec2 it should return: `{1, 11, 2, 12, 3, 13, 4, 14, 5, 15}` +Write a function `concatenateVector` which will take 2 vectors as arguments and then return one which will contain alternating elements from the first and second vector. +For example, for the following `vec1` and `vec2` it should return: `{1, 11, 2, 12, 3, 13, 4, 14, 5, 15}` [Download the task][task2] ```cpp diff --git a/module2/03_range_for.pl.md b/module2/03_range_for.pl.md index 2088d2f8..c00eee93 100644 --- a/module2/03_range_for.pl.md +++ b/module2/03_range_for.pl.md @@ -48,7 +48,7 @@ ___ ## Zadanie -Napisz funkcję `printVector`, która przyjmie jako argument `std::vector` i wypisze jego zawartość przy użyciu pętli for przy kolekcji. +Napisz funkcję `printVector`, która przyjmie jako argument `std::vector` i wypisze jego zawartość przy użyciu pętli `for` przy kolekcji. Każdy element w nowej linii. [Pobierz zadanie][task1] @@ -77,7 +77,7 @@ ___ ## Zadanie Napisz funkcję `concatenateVector`, która przyjmie jako argumenty 2 wektory a następnie zwróci jeden, który będzie zawierał naprzemiennie elementy z pierwszego i drugiego wektora. -Np. dla poniższych vec1 i vec2 powinna zwrócić: `{1, 11, 2, 12, 3, 13, 4, 14, 5, 15}` +Np. dla poniższych `vec1` i `vec2` powinna zwrócić: `{1, 11, 2, 12, 3, 13, 4, 14, 5, 15}` [Pobierz zadanie][task2] ```cpp diff --git a/module2/04_string.en.md b/module2/04_string.en.md index 2b1223aa..513c16ff 100644 --- a/module2/04_string.en.md +++ b/module2/04_string.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## `std::string` @@ -13,23 +13,23 @@ ___ ## Character container - `std::string` * a special container that stores characters -* std::string it also has a beginning and an end, like any container -* similar functions as std::vector +* std::string also has a beginning and an end, like any container +* similar functions to std::vector ___ ## Operations on `std::string` -* adding a mark at the end - * `str.push_back('a')` (nobody does that :)) +* adding a character at the end + * `str.push_back('a')` (nobody does that 🙂) * we recommend `str += 'a';` * reading a single character * `str[1]` * initialization - * `std::string str("Witam")` - * `std::string str = "Witam"` + * `std::string str("Hello")` + * `std::string str = "Hello"` * assigning the entire string - * `str = "Witam"` + * `str = "Hello"` * getting the first character * `str.front()` * getting the last character diff --git a/module2/05_list.en.md b/module2/05_list.en.md index 33bfe3f4..250de094 100644 --- a/module2/05_list.en.md +++ b/module2/05_list.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## `std::list` @@ -12,7 +12,7 @@ ___ ## List -### Question: what features did he have `std::vector`? +### Question: what features did `std::vector` have? Unlike a vector, the list is scattered around the memory. Which is sometimes convenient, because we can use fragments of memory, @@ -22,7 +22,7 @@ that could be inaccessible to the vector. ### Question: How do list elements know about each other's existence? -Each list item stores a pointer to either the next item (one-way list) or the next and previous item (two-way list). +Each list item stores a pointer to either the next item (one-way linked list) or the next and previous item (two-way linked list). ___ @@ -42,9 +42,9 @@ ___ * `empty()` * adding an item to the end of the list * `push_back()` -* NEW adds an item to the top of the list +* NEW adds an item to the beginning of the list * `push_front()` -* NEW sorting of list items (can't use std::sort for list) +* NEW sorting list items (can't use std::sort for list) * `sort()` [Documentation on cppreference.org](https://en.cppreference.com/w/cpp/container/list) @@ -54,7 +54,7 @@ ___ ## Question: how do I get to the 10th list item? -Since each list item only knows about the previous and next items, we can't get to the 10th item that easily. +Since each list item knows only about the previous and next items, we can't get to the 10th item that easily. We can access the first item via `front()` or `*begin()` @@ -67,7 +67,7 @@ int main() { std::cout << list.front(); } ``` - + ___ @@ -85,7 +85,7 @@ int main() { ``` -It takes more time than getting into the 10th element in `std::vector`. +It takes more time than getting to the 10th element in `std::vector`. ___ @@ -117,4 +117,4 @@ int main() { ___ -## Question: when is it profitable to use `std::list`, when `std::vector`? +## Question: when is it profitable to use `std::list` and when `std::vector`? diff --git a/module2/05_list.pl.md b/module2/05_list.pl.md index 7bc09a4e..52736dc0 100644 --- a/module2/05_list.pl.md +++ b/module2/05_list.pl.md @@ -16,7 +16,7 @@ ___ Lista w przeciwieństwie do wektora jest porozrzucana po pamięci. Co czasami jest wygodne, gdyż możemy wykorzystać fragmenty pamięci, -które mogłyby, by być niedostępne dla wektora. +które mogłyby być niedostępne dla wektora. ### Pytanie: skąd elementy listy wiedzą o swoim wzajemnym istnieniu? @@ -67,7 +67,7 @@ int main() { std::cout << list.front(); } ``` - + ___ diff --git a/module2/06_map.en.md b/module2/06_map.en.md index f364d9b8..51b8e905 100644 --- a/module2/06_map.en.md +++ b/module2/06_map.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## `std::map` @@ -12,15 +12,15 @@ ___ ## Map, dictionary -* map is a set of pairs (key - Key, value - Value) -* `std::map` in C ++ it is equivalent to `dict` from Python +* map is a set of pairs (key, value) +* `std::map` in C++ is equivalent to `dict` from Python -For example, we create a collection of favorite records and put them in a cupboard. - +For example, we create a collection of favorite CDs and arrange them on a shelf. + Of course, we have a huge number of these CDs and we would like to be able to find the CD easily when we search for it. - -For this purpose, we number all the discs and write down on a piece of paper information under which number the title is placed. This is how we create a map. - + +For this purpose, we number all the CDs and write down information on a piece of paper under which number which title is placed. This is how we create a map. + ```cpp std::map discs { @@ -29,10 +29,10 @@ std::map discs { {3, "The Lord of the Rings: The Return of the King"} }; ``` - + The key here is the number, while the value is the title of the movie. - + ___ @@ -47,13 +47,12 @@ ___ * `empty()` * access to the item for the specified key * `operator[key]` -* adding a pair (key, value) to the map if such a pair is not present in it yet +* adding a pair (key, value) to the map if such a pair does not exist in it yet * `insert({key, value})` [Documentation on cppreference.org](https://en.cppreference.com/w/cpp/container/map) - ___ ## Question @@ -64,11 +63,11 @@ What will happen when we call on the mentioned map: discs[4] = "Harry Potter"; ``` -Assigning something to a map element with `operator[]` makes: +Assigning something to a map element with `operator[]` makes it so: * if there is already a value for a given key, we will replace it. -* when there is no value for a given key, we will create a new pair (key, value) +* if there is no value for a given key, we will create a new pair (key, value) ___ diff --git a/module2/06_map.pl.md b/module2/06_map.pl.md index 4ac90e17..ae418c1c 100644 --- a/module2/06_map.pl.md +++ b/module2/06_map.pl.md @@ -16,11 +16,11 @@ ___ * `std::map` w C++ to odpowiednik `dict` z Pythona Przykładowo tworzymy kolekcję ulubionych płyt i układamy je w szafce. - + Oczywiście płyt tych mamy ogromną liczbę i chcielibyśmy móc łatwo odnaleźć płytę, gdy będziemy jej poszukiwać. - + W tym celu numerujemy sobie wszystkie płyty i zapisujemy sobie na kartce informacje, pod jakim numerem znajduje się określony tytuł. W ten sposób tworzymy właśnie mapę. - + ```cpp std::map discs { @@ -29,10 +29,10 @@ std::map discs { {3, "The Lord of the Rings: The Return of the King"} }; ``` - + Kluczem jest tutaj numer, natomiast wartością jest tytuł filmu. - + ___ @@ -53,7 +53,6 @@ ___ [Dokumentacja na cppreference.org](https://en.cppreference.com/w/cpp/container/map) - ___ ## Pytanie diff --git a/module2/07_homework.en.md b/module2/07_homework.en.md index ef903417..8708943d 100644 --- a/module2/07_homework.en.md +++ b/module2/07_homework.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## Summary @@ -12,12 +12,12 @@ ___ ## What do you remember from today? -### Write as many passwords as possible in the chat +### Write as many keywords as possible in the chat -1. STL - what is it? +1. What is STL? 2. std::vector -3. Loop for after collection +3. for loop over collection 4. std::string 5. std::list 6. std::map @@ -29,9 +29,9 @@ ___ ### Post-work -* If you don't know what it is `operator%` so find out. It will be useful for homework :) +* If you don't know what `operator %` is then you have to read about it. It will prove useful in homework 🙂 * Task 1 - AddEven (4 points) -* Task 2 - GCD (LCM) and NWW (GCD) (6 points) +* Task 2 - LCM and GCD (6 points) * Task 3 - MaxOfVector (5 points) * Task 4 - GenerateSequence (5 points) @@ -39,28 +39,28 @@ ___ For delivering each task before 31/05/2020 (Sunday) until 23:59 you will get 2 bonus points (a total of 8 points for 4 tasks). -#### [Repo jobs](https://github.com/coders-school/cpp-fundamentals/tree/master/module2/homework) +#### [Repo tasks](https://github.com/coders-school/cpp-fundamentals/tree/master/module2/homework) ___ ### Pre-work -* Remember information about indicators, e.g. from [Mr. Zelent's video](https://www.youtube.com/watch?v=0DQl74alJzw) -* [Read about `enum`ah](http://cpp0x.pl/kursy/Kurs-C++/Typ-wyliczeniowy-enum/318) -* Get interested in the topic of smart pointers and look for information about what it is `std::shared_ptr` and `std::unique_ptr` +* Recall information about pointers, e.g. from [Mr. Zelent's video](https://www.youtube.com/watch?v=0DQl74alJzw) +* [Read about `enum`](http://cpp0x.pl/kursy/Kurs-C++/Typ-wyliczeniowy-enum/318) +* Get interested in the topic of smart pointers and look for information about what is `std::shared_ptr` and `std::unique_ptr` * Take a look at the files with tests in homework and try to add your own test cases ___ ## Task 1 - AddEven -Write a function to adopt `std::vector` and will return the sum of all its even elements. +Write a function that takes `std::vector` and returns the sum of its all even elements. -Declaration - `int addEven(const std::vector& numbers)` +Signature - `int addEven(const std::vector& numbers)` If you don't know what the function should return in some cases, read the tests. -### Example of use +### Example ```cpp std::vector vec{1, 2, 3, 4, 5}; @@ -69,12 +69,12 @@ auto result = addEven(vec); // result = 6; ___ -## Task 2 - GCD (LCM) and NWW (GCD) +## Task 2 - LCM and GCD -Implement two functions - GCD, which is to count the Greatest Common Divisor, and GCD, which is to count the Least Common Multiple of 2 numbers. -Watch out for unusual cases like 0 or negative numbers :) +Implement two functions - GCD, which finds Greatest Common Divisor, and LCM, which finds the Least Common Multiple of 2 numbers. +Watch out for unusual cases like 0 or negative numbers 🙂 -### Example of use +### Example ```cpp std::cout << "NWW(255, 15) = " << NWW(255, 15) << "\n"; @@ -87,7 +87,7 @@ ___ Write a function that takes `std::vector` and returns the largest element of this vector. -### Example of use +### Example ```cpp std::vector numbers = {6, 78, 12, 54, -11, 0}; @@ -103,9 +103,9 @@ Write a function that takes 2 arguments: * `int count` * `int step` -and returns `std::vector` having `count` elements and each of them is greater than the previous by `step`. The first is to be equal to `step`. +and returns `std::vector` which has `count` elements and each of them is greater than the previous by `step`. The first element is equal to `step`. -### Example of use +### Example ```cpp auto result = generateSequence(5, 3); // result = {3, 6, 9, 12, 15} @@ -117,13 +117,13 @@ ___ For delivering tasks together with someone else, you will get an additional 3 points (per person). The commits of both people must be visible in the PR and it must be properly described: -Title: `Homework Podstawy C++ #2` +Title: `Homework C++ basics #2` Description: `Authors: @github_nick1, @github_nick2 \n Some additional info` All tasks should be delivered on one branch this time. The reporting person will get 2 points for the PR submission alone, but I will compensate this by adding 2 extra points to the other person. The easiest way is for the second person to clone the repository of the former and the former to write permission to the latter. -You can also add a new remote repository in your previously cloned fork using `git remote add nazwa adres`. +You can also add a new remote repository in your previously cloned fork using `git remote add name address`. ___ @@ -135,9 +135,9 @@ ___ -## Task delivery (different to Basics # 1) +## Task delivery (difference from Basics #1) -1. You already have a fork repo [c ++ - fundamentals](https://github.com/coders-school/cpp-fundamentals), can't fork again +1. You already have a fork repo [cpp-fundamentals](https://github.com/coders-school/cpp-fundamentals), you can't fork again 2. If you're going to work in a pair, it's easiest if you give the other person permission to push into your repo. Choose `Role: Write` 3. You have already pulled your fork 4. Go to the repo directory - `cd cpp-fundamentals` @@ -147,9 +147,9 @@ ___ 8. You can now send the newly downloaded branch to your repo on GH - `git push origin module2` 9. Create a separate branch for homework - `git checkout -b homework2` 10. Send this branch to GitHub right away, before implementing anything - `git push origin homework2` -11. Implement (alone or together) solutions, making lots of tiny commits. In group work, you can share tasks so as not to get into a parade and create conflicts, but if you want to try the hardcore version right away, do the same task together :) +11. Implement (alone or together) solutions, making lots of tiny commits. In group work, you can share tasks so as not to get into a parade and create conflicts, but if you want to try the hardcore version right away, do the same task together 🙂 12. When submitting changes to GitHub, use the command `git push origin homework2` -13. When submitting a Pull Request, click that you want to deliver it to `coders-school/cpp-fundamentals` branch `module2` +13. When submitting a Pull Request, select that you want to deliver it to `coders-school/cpp-fundamentals` branch `module2` ___ @@ -157,11 +157,11 @@ ___ ## Version for a person using a colleague's fork 1. Wait for your coworker to complete steps 1-10 -2. Select a variant: - * Make `git clone adres_repo_współpracownika` and work on it - * Add a colleague's repo address to your clone repo `git remote add nick adres` and download changes from it - `git fetch nick` +2. Select an option: + * Make `git clone address_repo_coworker` and work on it + * Add a colleague's repo address to your clone repo `git remote add nick address` and download changes from it - `git fetch nick` 3. Switch to the homework2 branch - `git checkout homework2` 4. Build projects, share the work, implement the solution. 5. Send changes to a colleague's GH - `git push nick homework2` -6. A co-worker will report a PR, you don't have to click anything :) +6. A co-worker will report a PR, you don't have to click anything 🙂 7. In case of problems, you can always switch to independent work diff --git a/module2/index.en.html b/module2/index.en.html index 8ac2bb81..a60b83ad 100644 --- a/module2/index.en.html +++ b/module2/index.en.html @@ -69,7 +69,7 @@

Łukasz Ziobroń

## Short reminder - ### What do already know + ### What do we already know * what do you remember from previous lesson? * what was the most difficult thing? From dd0b7d3d52bf1a00b25de8d284316e4ed2da722c Mon Sep 17 00:00:00 2001 From: MrMijagi Date: Thu, 27 Aug 2020 16:55:14 +0200 Subject: [PATCH 5/7] added automaticly translated presentations in module3 --- module3/01_scopes.en.md | 87 ++++++ ...presentation_scopes.md => 01_scopes.pl.md} | 0 module3/02_references.en.md | 129 ++++++++ ...tion_references.md => 02_references.pl.md} | 0 module3/03_pointers.en.md | 275 ++++++++++++++++++ ...entation_pointers.md => 03_pointers.pl.md} | 0 module3/04_hazards.en.md | 251 ++++++++++++++++ ...esentation_hazards.md => 04_hazards.pl.md} | 0 module3/05_enums.en.md | 160 ++++++++++ .../{presentation_enums.md => 05_enums.pl.md} | 0 module3/06_stl_algo_iter.en.md | 209 +++++++++++++ ...tl_algo_iter.md => 06_stl_algo_iter.pl.md} | 0 module3/07_homework.en.md | 146 ++++++++++ ...entation_homework.md => 07_homework.pl.md} | 0 module3/index.en.html | 154 ++++++++++ module3/{index.html => index.pl.html} | 14 +- 16 files changed, 1418 insertions(+), 7 deletions(-) create mode 100644 module3/01_scopes.en.md rename module3/{presentation_scopes.md => 01_scopes.pl.md} (100%) create mode 100644 module3/02_references.en.md rename module3/{presentation_references.md => 02_references.pl.md} (100%) create mode 100644 module3/03_pointers.en.md rename module3/{presentation_pointers.md => 03_pointers.pl.md} (100%) create mode 100644 module3/04_hazards.en.md rename module3/{presentation_hazards.md => 04_hazards.pl.md} (100%) create mode 100644 module3/05_enums.en.md rename module3/{presentation_enums.md => 05_enums.pl.md} (100%) create mode 100644 module3/06_stl_algo_iter.en.md rename module3/{presentation_stl_algo_iter.md => 06_stl_algo_iter.pl.md} (100%) create mode 100644 module3/07_homework.en.md rename module3/{presentation_homework.md => 07_homework.pl.md} (100%) create mode 100644 module3/index.en.html rename module3/{index.html => index.pl.html} (93%) diff --git a/module3/01_scopes.en.md b/module3/01_scopes.en.md new file mode 100644 index 00000000..f01c7199 --- /dev/null +++ b/module3/01_scopes.en.md @@ -0,0 +1,87 @@ + + +# C ++ basics + +## Scope of variables + +
+ Coders School + + +___ + +## Local variables + +Local variables are variables that are viewed within a scope. + + +```cpp +{ + int local_variable = 5; + // ... +} +local_variable = 10; // error -> local_variable doesn't exists +``` + + +The range is always formed by curly braces, including: + +* same parentheses - { /* ... */ } +* function body - void fun() { /* ... */ } +* conditional statements - if (condition) { /* ... */ } +* loops - while (condition) { /* ... */ } + +___ + +## Global variables + +A global variable, it is visible to all scopes. We can always refer to it. + + +```cpp +int global_value = 5; + +void foo() { + std::cout << global_value; +} + +int main() { + std::cout << global_value; +} +``` + + +Generating global variables is usually bad practice. + + +___ + +## What will appear on the screen? + +```cpp +int number = 1; + +int main() { + int number = 2; + { + int number = 3; + std::cout << number; + std::cout << ::number; + } + std::cout << number; + std::cout << ::number; +} +``` + + +### 3121 + + +___ + +## Overriding names + +* we can have many variables with the same name if they are in different ranges + * to avoid ambiguity this is rather not recommended +* a name from the local scope always overrides the name from a wider scope (e.g. global) +* you can refer to names from global scope using :: (range operator) diff --git a/module3/presentation_scopes.md b/module3/01_scopes.pl.md similarity index 100% rename from module3/presentation_scopes.md rename to module3/01_scopes.pl.md diff --git a/module3/02_references.en.md b/module3/02_references.en.md new file mode 100644 index 00000000..8344fa61 --- /dev/null +++ b/module3/02_references.en.md @@ -0,0 +1,129 @@ + + +# C ++ basics + +## References + + + Coders School + + +___ + +## & + +Magic badge `&` stands for reference. + +```cpp +int value = 5; +int & number = value; +``` + +The above notation denotes a variable `num` type `int&`, which is a reference to a type `int`. + + +It doesn't matter if we stick the reference to the type or name of the variable, but the reference is a separate type, so we suggest not to stick it to the variable name. + + +```cpp +int& number = value; // lewak +int &number = value; // prawak (odradzane) +int & number = value; // neutralny +``` + +___ + +### What is a reference? + +Let's look at a code snippet. + +```cpp +int number = 5; +int& refer = number; + +std::cout << refer << '\n'; // 5 +std::cout << ++refer << "\n"; // 6 +std::cout << number << "\n"; // 6 +``` + +* The reference refers to an existing object +* If we create an object int value it through references int& reference = value we will be able to refer to it directly. +* Reference is another, additional name for the same variable (alias) +* Modifying a reference = modifying the original object + +___ + +### What do we gain in this way? + +* We don't need to copy items. It is enough for us to provide references. + * This way, we can freely read the value of this variable in many places in the program, without unnecessary copying it. +* A reference takes up as much in memory as an address (4 or 8 bytes). +* Building a reference to a type int (usually 4 bytes) does not always make optimization sense, unless you want to modify this element inside a function. +* Passing arguments by reference will make more sense when we get to know classes and objects :) + +[How much space does a reference take? - stackoverflow.com](https://stackoverflow.com/questions/1179937/how-does-a-c-reference-look-memory-wise) + + +___ + +### How to pass an element by reference? + +```cpp +void foo(int& num) { + std::cout << num; // good + num += 2; // good +} +``` + + +If we want to be sure that the function will not modify the value (we want to pass it read-only), we add `const`. + + +```cpp +void bar(const int& num) { + std::cout << num; // good + num += 2; // compilation error, num is const reference +} +``` + + +A function call is simply: + + +```cpp +int num = 5; +foo(num); +bar(num); +``` + + +___ + +## Task + +Implement the function `foo()`. It is to accept and modify the text provided. We want to see on the screen `"Other string"`. + +```cpp +#include +#include + +// TODO: Implement foo() +// It should modify passed string to text "Other string" + +int main() { + std::string str("Some string"); + foo(str); + std::cout << str << '\n'; + return 0; +} +``` + +___ + +## Summary + +* reference is an alias (another name for a variable) +* a reference modification is a modification of the original object +* when passing a parameter by reference: + * we avoid unnecessary copies + * object modification will result in modification of the original passed to the function diff --git a/module3/presentation_references.md b/module3/02_references.pl.md similarity index 100% rename from module3/presentation_references.md rename to module3/02_references.pl.md diff --git a/module3/03_pointers.en.md b/module3/03_pointers.en.md new file mode 100644 index 00000000..49050269 --- /dev/null +++ b/module3/03_pointers.en.md @@ -0,0 +1,275 @@ + + +# C ++ basics + +## Pointers + + + Coders School + + +___ + +## Indicators - an analogy + +In addition to references, there are also pointers. Pointers work much like references. + + +Imagine you are planning a trip to Majorca. We get on the plane and fly. +On the spot, it turns out that we have forgotten the hotel address :( +In order to find it, we have to call the travel agency, wait for the service, explain the whole complex story, and finally, after a long time, we get the address of our hotel. +The process of obtaining this information was time-consuming for us. + + +Let's imagine, however, that we have previously saved the address of our hotel on our phone. To remember where it was, we just need to check the phone and we know. The process took much less time. + + +___ + +## Pointers in C ++ + +It is similar in C ++. Pointers are used to indicate the location in memory where the desired object is located. + + +The processor does not have to ask the memory bus each time where the given variable is, but it knows immediately what its address is (we avoid intermediaries like a phone call to the service office). + + +Also, if a function takes a pointer, it doesn't have to copy the entire contents of the object, which is time consuming. You can indicate where this object already exists much faster. + + +___ + +### How do I pass an element by a pointer? + +```cpp +void foo (int* num) { + std::cout << *num; // good + *num += 2; // good +} +``` + + +When we want to be sure that no one will modify the value for us (we want to pass it read-only), we add `const`. + + +```cpp +void bar (int const* num) { + std::cout << *num; // good + *num += 2; // compilation error, num is a pointer to const +} +``` + + +The function call is: + + +```cpp + int num = 5; + foo(&num); + bar(&num); +``` + + +___ + +## Where to put const? + +### What is this? + +```cpp +const int * ptr; +``` + + +A pointer to a constant (`const int`). + + +```cpp +int const * ptr; +``` + + +Also the pointer to the constant (`const int = int const`). + + +```cpp +int * const ptr; +``` + + +A constant pointer to a variable (`int`). + + +___ + +## Fixed pointers versus pointers fixed + +```cpp +int const * const ptr; +const int * const ptr; +``` + + +Constant pointer to constant (`int const = const int`). + + +This is a common question from job interviews. So that the indicator is constant, `const` must be after the asterisk. + + +___ + +## Differences + +### Pointer to a constant + +```cpp +const int * ptr = new int{42}; +*ptr = 43; // compilation error: assignment of read-only location ‘* ptr’ +ptr = nullptr; // ok +``` + +* We cannot modify the object pointed to by the pointer + * Appeals from `*` they cannot modify the object +* We can modify the pointer itself, e.g. to point to another object + * Appeals without `*` can modify the pointer + +___ + +## Differences + +### Constant indicator + +```cpp +int * const ptr = new int{42}; +*ptr = 43; // ok +ptr = nullptr; // compilation error: assignment of read-only variable ‘ptr’ +``` + +* We can modify the object pointed to by the pointer + * Appeals from `*` can modify the object +* We cannot modify the pointer itself, e.g. to point to another object + * Appeals without `*` they cannot modify the pointer + +___ + +### Constant pointer to constant + +```cpp +const int * const ptr = new int{42}; +*ptr = 43; // compilation error: assignment of read-only location ‘* ptr’ +ptr = nullptr; // compilation error: assignment of read-only variable ‘ptr’ +``` + +* We cannot modify the object pointed to by the pointer + * Appeals from `*` they cannot modify the object +* We cannot modify the pointer itself, e.g. to point to another object + * Appeals without `*` they cannot modify the pointer + +___ + + +## Task + +Implement the functions `foo()` and `bar()`. + +`foo()` should modify the value passed by the pointer to 10, a `bar()` on 20. + +Whether `foo()` or `bar()` can I take the pointer to a constant or constant pointer? + +```cpp +#include + +// TODO: Implement foo() and bar() +// foo() should modify value under passed pointer to 10 +// bar() should modify value under passed pointer to 20 +// Can we have a pointer to const or a const pointer? +int main() { + int number = 5; + int* pointer = &number; + std::cout << number << '\n'; + foo(&number); + std::cout << number << '\n'; + bar(pointer); + std::cout << number << '\n'; + + return 0; +} +``` + +___ + + +## Differences between pointer and reference + +### References + +* We refer to references in the same way as to an ordinary object - by name +* To get the item pointed to by the pointer we need to add * before the name of the indicator + +### Passing as an argument + +* The argument is a reference or a regular variable (copy) - we pass the name +* The argument is a pointer and we pass the variable - we have to add & before the variable name. + +### Signs + +* Symbol * (dereference operator) denotes access to the referenced object +* If we don't * at the pointer we get the address of the pointed object +* Symbol & means getting the address of our variable +* The above makes sense because the pointer points to a memory location (the address of the pointed object) + +___ + +## Differences in the code + +```cpp +void copy(int a) { a += 2; } +void ref(int& a) { a += 2; } +void ptr(int* a) ( *a += 2; ) + +void example() { + int c = 10; + int& r = a; + int* p = &a; // typically int* p = new int{10}; + copy(c); + copy(r); + copy(*p); + ref(c); + ref(r); + ref(*p); + ptr(&c); + ptr(&r); + ptr(p); +} +``` + +___ + +## Which means `*` in code? + +```cpp +int a = 5 * 4; // jako operacja arytmetyczna - mnożenie +int* b = &a; // przy typie - wskaźnik na ten typ +int *c = &a; // przy typie - wskaźnik na ten typ +std::cout << *b; // przy zmiennej wskaźnikowej - dostęp do obiektu +int fun(int* wsk); // w argumencie funkcji - przekazanie wskaźnika (adresu) +``` + + +## Which means `&` in code? + + +```cpp +int a = 5 & 4; // jako operacja arytmetyczna - suma bitowa +int& b = a; // przy typie - referencja na ten typ +int &c = a; // przy typie - referencja na ten typ +std::cout << &a; // przy zmiennej - adres tej zmiennej w pamięci +int fun(int& ref); // w argumencie funkcji - przekazanie adresu +``` + + +___ + +## Important rule + +Unless absolutely necessary, then we don't use pointers at all. diff --git a/module3/presentation_pointers.md b/module3/03_pointers.pl.md similarity index 100% rename from module3/presentation_pointers.md rename to module3/03_pointers.pl.md diff --git a/module3/04_hazards.en.md b/module3/04_hazards.en.md new file mode 100644 index 00000000..348f219c --- /dev/null +++ b/module3/04_hazards.en.md @@ -0,0 +1,251 @@ + + +# C ++ basics + +## Threats + +### in the use of references and pointers + + + Coders School + + +___ + +## Empty indicators + +```cpp +int* a = nullptr; +std::cout << *a; +``` + +Accessing a variable pointed to by an empty pointer is undefined behavior. + + +Always mark an empty pointer with `nullptr`. + + +We do not use `NULL` known from the C language or earlier standards, because it is less secure. + + +```cpp +void foo(int); +foo(NULL); // bad - no error +foo(nullptr); // good - compilation error +``` + + +___ + +## Uninitialized pointers + +```cpp +int* a; +std::cout << *a; +``` + +Indicator `a` contains the so-called rubbish. +Accessing the object pointed to by such a pointer is undefined behavior. + + +___ + +## References to deleted variables + +As we already well know, local variables are removed when they are out of the scope we created them. +You can already guess what problems pointers and references will cause us when they still exist and the object they refer to is already destroyed. +It will be at best "Crash"at worst "Undefined behavior". + +### How to prevent such cases? + + +We must always ensure that the lifetime of the variable is longer than the lifetime of its indicator or reference. + + +___ + +## Removed variables - example + +```cpp +std::vector vec; + +void createAndAddToVec(int amount) { + for (int i = 0 ; i < amount ; ++i) { + vec.push_back(&i); + } + // local variable i does not exist here anymore + // vec contains addresses to not existing local variables +} + +int main() { + createAndAddToVec(5); + for (const auto& el : vec) { + std::cout << *el << '\n'; // UB + } +} +``` + +___ + +## How to deal with such a problem? + +The answer may be dynamically allocated memory. + + +The easiest way to do this is by using a library `#include `that has `std::shared_ptr`. + + +This indicator is called _intelligent_ for a reason. It is responsible for managing dynamic memory and releases the resource itself when we no longer need it. + + +### How to create such an indicator? + + +```cpp +auto ptr = std::make_shared(5); // preferred +auto ptr = std::shared_ptr(new int{5}); +``` + + +___ + +## Corrected listing + +```cpp +std::vector> vec; // previously: std::vector vec; + +void createAndAddToVec(int amount) { + for (int i = 0 ; i < amount ; ++i) { + vec.push_back(std::make_shared(i)); + // previously: vec.push_back(&i); + + // the same in 2 lines: + // auto num = std::make_shared(i); + // vec.push_back(num); + } +} + +int main() { + createAndAddToVec(5); + for (const auto& el : vec) { + std::cout << *el << '\n'; + } +} +``` + +___ + + +## Task + +Write a function `foo()`. It is supposed to accept shared_ptr on int and assign value 20 to the object pointed to by it. + +also `foo()` is to display the value of the int pointed to by the pointer and the number of shared_pts that point to this object. + +Also display the same in `main()` before and after the call `foo()`. + +```cpp +#include +#include + +// TODO: Implement foo() +// It should take shared_ptr to int and assign value 20 to the pointed int. +// It should also display the value of this int and the number of how many pointers are pointing to it - use `use_count()`. +// Display the same information in main() before and after calling foo() + +int main() { + std::shared_ptr number = std::make_shared(10); + // display the value under number pointer and use_count() of it + foo(number); + // display the value under number pointer and use_count() of it + + return 0; +} +``` + +___ + +## Task + +Write a function `foo()`. It is supposed to take 2 values ​​of the type `int` and return their product as `shared_ptr`. Check how many owners it has `shared_ptr`. + +```cpp +#include + +// TODO: Implement foo() +// It should take 2 int values and return their product as a shared_ptr. +// Additionally, check how many owners are there. + +int main() { + auto number = foo(10, 20); + std::cout << "num: " << *number << " | owners: " << number.use_count() << "\n"; + + return 0; +} +``` + +___ + +## Intelligent pointers the solution to all problems? + +Now that we've created a smart pointer, we don't have to worry about the variable's lifetime. +We can safely print these values ​​after exiting the function. + + +If a function needs to accept a raw pointer, i.e. `int* i` we can do it +using the function `std::shared_ptr::get()` as in the example: + + +```cpp +void foo(int* num) { + do_sth(num); +} + +int main() { + auto ptr = std::make_shared(5); + foo(ptr.get()) +} +``` + + +___ + + +## The trap returns + +```cpp +void foo(int* num) { + if (num) { + do_sth(num); + } +} + +int main() { + auto ptr = std::make_shared(5); + int* raw = ptr.get(); + ptr.reset(); // delete object, deallocate memory + foo(raw); // problem, dangling pointer is passed + foo(ptr.get()); // not a problem, nullptr is passed +} +``` + +If all objects `shared_ptr` references to this variable are deleted, the resource is released. + + +Our usual indicator we downloaded earlier with `get()`, will have an address for a resource that no longer exists. + + +Attempting to use it will result in an UB or a crash. Be very careful with the usual pointers. + + +___ + +## Conclusions + +* indicators may not point to anything (nullptr), the references must point to some previously created object +* pointers and references can be dangerous (more often pointers) if they are associated with objects that no longer exist + * these are the so-called dangling pointers / references, dangling pointers / references +* The reference cannot be assigned an object other than the one specified during its initialization +* pointers can be assigned new addresses to point to other objects (except fixed pointers) +* better by default not to use raw pointers +* it's better to use smart pointers diff --git a/module3/presentation_hazards.md b/module3/04_hazards.pl.md similarity index 100% rename from module3/presentation_hazards.md rename to module3/04_hazards.pl.md diff --git a/module3/05_enums.en.md b/module3/05_enums.en.md new file mode 100644 index 00000000..6b0a560c --- /dev/null +++ b/module3/05_enums.en.md @@ -0,0 +1,160 @@ + + +# C ++ basics + +## `enum` and `enum class` + + + Coders School + + +___ + +## Enumerated type + +`enum` is an enumerated type in Polish. +Also introduced in C ++ 11 `enum class` called a strong enumeration type. + +### Example + +Suppose we write washing machine software. +We would also like to create an interface that returns an error number, e.g .: + + +* lack of water +* too heavy a load +* problem with bearings +* pump lock + +In order to use type `enum` or better - `enum class`. + + +___ + +### Example implementation + +```cpp +enum ErrorCode { + lack_of_water; + too_much_load; + bearing_problem; + block_of_pump; +}; + +// or better ↓ + +enum class ErrorCode { + lack_of_water; + too_much_load; + bearing_problem; + block_of_pump; +}; +``` + +___ + +## Numbering + +Type `enum` underneath it is numbered from `0` down `n - 1`where `n` is the number of elements. + + +If we want to set different values, we have to do it manually: + + +```cpp +enum class ErrorCode { + lack_of_water = 333; + to_much_load; // will be 334 + bearing_problem = 600; + block_of_pump; // will be 601 +} +``` + + +___ + +## `enum` vs `enum class` + +`enum` from `enum class` the main difference is that we can implicitly convert the type `enum` on `int` (it's an enumerated type after all). + +However, type `enum class` we can convert to `int`, only by explicit casting. We are not going to discuss casting for now. It's just worth it +remember that we do this by calling: + + +```cpp +int num = static_cast(ErrorCode::lack_of_water) +``` + + +In what other cases would you use the enumeration type? + + +___ + + +## `enum` vs `enum class` + +The second difference - for `enum` we may have a name conflict for `enum class` no. + +```cpp +enum Color { + RED, // 0 + GREEN, // 1 + BLUE // 2 +}; +``` + + +```cpp +enum TrafficLight { + GREEN, // 0 + YELLOW, // 1 + RED // 2 +}; +``` + + +```cpp +auto lightColor = getColor(); +if (lightColor == RED) { // 0 or 2? + stop(); +} else { + go(); +} +``` + + +___ + + +## Use the value of z `enum class` + +To avoid a name conflict, we use `enum class`. + +```cpp +enum class Color { + RED, + GREEN, + BLUE, +} +``` + + +```cpp +enum class TrafficLight { + GREEN, + YELLOW, + RED +} +``` + + +```cpp +auto lightColor = getColor(); +if (lightColor == TrafficLight::RED) { + stop(); +} else { + go(); +} +``` + diff --git a/module3/presentation_enums.md b/module3/05_enums.pl.md similarity index 100% rename from module3/presentation_enums.md rename to module3/05_enums.pl.md diff --git a/module3/06_stl_algo_iter.en.md b/module3/06_stl_algo_iter.en.md new file mode 100644 index 00000000..fcc56b2a --- /dev/null +++ b/module3/06_stl_algo_iter.en.md @@ -0,0 +1,209 @@ + + +# C ++ basics + +## Introduction to STL + +### Algorithms and iterators + + + Coders School + + +___ + +Let's go back to the begin and end iterators for a moment. As we remember, they returned the beginning and the end of our container, e.g. std :: vector. +in fact, begin and end returns to us an iterator pointing to 1 element of our container and to the element immediately after the last element. (here a photo of a few squares and marked as indicated by the begin and the end). + +What is an iterator? The easiest way is an element that points to a container element. We can freely increment it, i.e. move to the next elements of the container. We distinguish several types of iterators, but at the moment we will only deal with one. +It is called random acces iterator. It is important to us that such an iterator can freely refer to any element in our container. We get the random itarator when we call begin or end for std :: vector. To refer to the element the iterator points to, we use `*`. + +What will be listed in the following lines? +``` + std::vector vec {1, 2, 3, 4, 5, 6}; + auto random_iterator = vec.begin(); + std::cout << *random_iterator; + ++random_iterator; + std::cout << *random_iterator; + random_iterator += 2; + std::cout << *random_iterator; +``` + +The STL library has over 100 algorithms, one of them are: + * std :: sort, + * find, + * all_of, + * any_off, + * fill, + * min_max_element; + * for_each. + + All algorithms work for iterators, e.g .: + ``` + template< class RandomIt > + void sort( RandomIt first, RandomIt last ); +``` +The sort algorithm requires 2 iterators to sort a container. Most often the beginning and the end of the range. Such an algorithm is called as follows: +``` + int main() + { + std::vector vec = {5, 7, 4, 2, 8, 6, 1, 9, 0, 3}; + + std::sort(vec.begin(), vec.end()); + for (auto element : vev) { + std::cout << element << " "; + } + std::cout << '\n'; + } +``` +Sorting is really easy. Fun fact for those wondering why you can't just give std :: sort (vec). +It took several years for the standardization committee to notice that this option was useful and that it was only available in the C ++ 20 standard. + +- Question: What construction can std :: find have? + +``` +template< class InputIt, class T > +InputIt find( InputIt first, InputIt last, const T& value ); +``` + +- Question: How to invoke such an algorithm? + +``` +int main() +{ + int n1 = 3; + int n2 = 5; + + std::vector v{0, 1, 2, 3, 4}; + + auto result1 = std::find(std::begin(v), std::end(v), n1); + auto result2 = std::find(std::begin(v), std::end(v), n2); + + if (result1 != std::end(v)) { + std::cout << "v contains: " << n1 << '\n'; + } else { + std::cout << "v does not contain: " << n1 << '\n'; + } + + if (result2 != std::end(v)) { + std::cout << "v contains: " << n2 << '\n'; + } else { + std::cout << "v does not contain: " << n2 << '\n'; + } +} +``` + +You can see a line in the code above `result1 != std::end(v)` this is nothing but checking whether a number has been found. +The algorithm returns `std::end` when no item is found. + +- Question: What design can it have `all_of` and `any_of` ? + +``` +template< class InputIt, class UnaryPredicate > +bool all_of( InputIt first, InputIt last, UnaryPredicate p ); +``` +``` +template< class InputIt, class UnaryPredicate > +bool any_of( InputIt first, InputIt last, UnaryPredicate p ); +``` + +UnaryPredicate -> specifies the condition that must be met. For example, we want to check if all numbers are less than 10, we can write a function: `bool isLessThen5(int num) { return num < 5; }` +When we want to check if no number is greater than 10, we can write a function: `bool isGreaterThen10(int num) { return num > 10; }` + +Example of use: +``` +#include +#include +#include +#include + +bool isLessThen5(int num) { return num < 5; } +bool isGreaterThen10(int num) { return num > 10; } + +int main() { + std::vector vec{1, 2, 3, 4, 5, 6}; + + if (std::all_of(vec.begin(), vec.end(), isLessThen5)) { + std::cout << "Every numbers in vector are less then 5\n"; + } else { + std::cout << "Some numbers in vector aren't less then 5\n"; + } + + if (std::none_of(vec.begin(), vec.end(), isGreaterThen10)) { + std::cout << "None of numbers in vector are grater then 10\n"; + } else { + std::cout << "Some numbers in vector are grater then 10\n"; + } + +} +``` + +- Question: What can the std :: fill algorithm have? +``` +template< class ForwardIt, class T > +void fill( ForwardIt first, ForwardIt last, const T& value ); +``` + +The fill algorithm fills the entire range of a container with some number. +- Question: How to fill a vector with 10 elements equal to 5? +``` + int main() { + std::vector v(10); + std::fill(v.begin(), v.end(), 5); + + for (auto elem : v) { + std::cout << elem << " "; + } + std::cout << "\n"; + } +``` + +- Question: What construction can the min_max_element algorithm have? +``` +template< class ForwardIt > +std::pair + minmax_element( ForwardIt first, ForwardIt last ); +``` +- Question: How do I find the smallest and largest element in std :: vector? +``` + int main() { + const auto v = { 3, 9, 1, 4, 2, 5, 9 }; + const auto [min, max] = std::minmax_element(begin(v), end(v)); + + std::cout << "min = " << *min << ", max = " << *max << '\n'; + } +``` + +- Question: What can the std :: for_each algorithm have? +``` +template< class InputIt, class UnaryFunction > +UnaryFunction for_each( InputIt first, InputIt last, UnaryFunction f ); +``` +- Question: What could the predicate for such an algorithm look like? +``` +void(Type& element) { + do_sth_with_element(element); +} +``` +- Question: How do I add the number 1 to each vector element? +``` + +void plus1(int& element) { element += 1; } + +int main() { + std::vector vec {1,2,3,4,5}; + std::for_each(vec.begin(), vec.end(), plus1); +} +``` +- The question and how to list its elements? +``` + +void plus1(int& element) { element += 1; } +void print(const int& element) { std::cout << element << '\n'; } + +int main() { + std::vector vec {1,2,3,4,5}; + std::for_each(vec.begin(), vec.end(), plus1); + std::for_each(vec.begin(), vec.end(), print); +} +``` diff --git a/module3/presentation_stl_algo_iter.md b/module3/06_stl_algo_iter.pl.md similarity index 100% rename from module3/presentation_stl_algo_iter.md rename to module3/06_stl_algo_iter.pl.md diff --git a/module3/07_homework.en.md b/module3/07_homework.en.md new file mode 100644 index 00000000..bf264755 --- /dev/null +++ b/module3/07_homework.en.md @@ -0,0 +1,146 @@ + + +# C ++ basics + +## Summary + + + Coders School + + +___ + +## What do you remember from today? + +### Write as many passwords as possible in the chat + + +1. Scopes +2. Reference +3. Indicators +4. Threats when using references and indicators +5. Enumerated type enum and enum class + +___ + + +## Homework + +### Post-work + +* Task 1 - PasswordCheck +* Task 2 - VectorOfSharedPointers + +#### Bonus for punctuality + +For delivering each task before 07/06/2020 (Sunday) until 23:59 you will get 2 bonus points for each task + +#### [Repo jobs](https://github.com/coders-school/cpp-fundamentals/tree/master/module3/homework) + +___ + +### Pre-work + +* [Playlist on YT regarding STL](https://www.youtube.com/playlist?list=PL5jc9xFGsL8G3y3ywuFSvOuNm3GjBwdkb) - watch as much as you can :) +* Recall what a class is and how it is written - [watch the video of Mirosław Zelent](https://www.youtube.com/watch?v=aDXjubGK0jU). WARNING! From the 22nd minute you can observe some bad practices: D Try to guess which ones. + +___ + +## The PasswordCheck task + +You create a password rule checker that receives data from a front-end contact form. The entire module is a set of several functions. Their declarations are to be included in the header file `validation.hpp`and the implementations in the source file `validation.cpp`. Your tasks are: + +1. Define a new type in the header file `ErrorCode` with possible values ​​for errors when setting a new password (1 point) + + * Ok + * PasswordNeedsAtLeastNineCharacters + * PasswordNeedsAtLeastOneNumber + * PasswordNeedsAtLeastOneSpecialCharacter + * PasswordNeedsAtLeastOneUppercaseLetter + * PasswordsDoesNotMatch + +___ + + +## PasswordCheck Task continued. + +2. Write a function `getErrorMessage()`which will take the defined type of error code and return the appropriate message as a string. (1 point) +3. Write a function `doesPasswordsMatch()`which will receive two passwords and check if they are identical. Should return an appropriate bool value. (1 point) +4. Write a function `checkPasswordRules()`which will accept one password and randomly return one of the codes `PasswordNeedsAtLeast*` or `Ok`. (2 points) +5. Write a function `checkPassword()`. It should accept two passwords and use the function `doesPasswordsMatch()` to determine if the passwords match. If they do not match, it will return the code `PasswordsDoesNotMatch`otherwise, it should return the error code returned by the function call `checkPasswordRules()`. (2 points) +6. For ambitious (optional) - implement it in the function `checkPasswordRules()` true validation of the remaining cases which are given as error codes. Ideally, you should use the features of z [ header](https://en.cppreference.com/w/cpp/header/cctype) and the algorithm `std::any_of`. Add / modify appropriate tests. (4 points) + +Total: 7 points (+4 for ambitious, +2 for delivery before 07/06/2020 23:59, +3 points / person for working in a pair) + +___ + +## PasswordCheck Task - Usage Example + +```cpp +int main() { + std::string password; + std::string repeatedPassword; + std::cout << "Set new password: "; + std::cin >> password; + std::cout << "Repeat password: "; + std::cin >> repeatedPassword; + auto result = checkPassword(password, repeatedPassword); + std::cout << getErrorMessage(result) << '\n'; + + return 0; +} +``` + +___ + + +## The VectorOfSharedPointers task + +Write a program that will contain 5 functions. Declarations should be included in the header file `vectorFunctions.hpp`and the implementations in the source file `vectorFunctions.cpp`. Create these files. + +* `std::vector> generate(int count)` which will generate a vector of shared pointers to numbers from `0` down `count` +* `void print()` which will print all the elements from the vector pointers +* `void add10()` which will take a vector and add it to each number `10` +* `void sub10()` which will take a constant pointer to `int` and subtract from this element `10` +* `void sub10();` Which will take a vector of shared pointers and call the above function overload for each element `sub10()` + +Total: 5 points (1 for each function) (+2 for delivery before 07/06/2020 11:59 pm, +3 points / person for working in a pair) + +### Example of use + +```cpp +int main() { + auto vec = generate(10); + print(vec); + add10(vec); + print(vec); + sub10(vec); + print(vec); +} +``` + +___ + + +## Task delivery + +1. If you don't already have the cpp-fundamentals repo fork and remote coders attached to it, see the earlier C ++ Basics # 2 and # 1 homework. +2. Update your repo from remote coders - `git fetch coders` +3. Switch to branch module3 - `git checkout module3` +4. Send branch module 3 to your photo - `git push origin module3` +5. Create a separate branch for homework - `git checkout -b homework3` +6. Send this branch to the fork right away, before starting the implementation - `git push origin homework3` +7. Start the implementation alone or in pair. +8. Before you submit your changes with `git push origin homework3` sync with the fork to check if the other person has already delivered something - `git pull --rebase origin homework3`. If there are conflicts, resolve them. +9. When submitting a Pull Request, click that you want to deliver it to `coders-school/cpp-fundamentals` branch `module3`. Describe it appropriately adding information about the authors of the code. + +___ + +## Next classes + +* Review of C ++ basics and tools +* Discussion of solutions to previous tasks +* Overview of the most common errors based on Code Review +* Q&A +* Comments +* Group consultation on Discord diff --git a/module3/presentation_homework.md b/module3/07_homework.pl.md similarity index 100% rename from module3/presentation_homework.md rename to module3/07_homework.pl.md diff --git a/module3/index.en.html b/module3/index.en.html new file mode 100644 index 00000000..00addc21 --- /dev/null +++ b/module3/index.en.html @@ -0,0 +1,154 @@ + + + + + + + C++ - basics - Coders School + + + + + + + + + + + + + + + +
+
+
+
+ +

C++ basics #3

+ + Coders School + +

Mateusz Adamski

+

Łukasz Ziobroń

+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+
+
+
+
+
+ +
+
+
+ +

Coders School

+ Coders School + +
+
+
+ + + + + + diff --git a/module3/index.html b/module3/index.pl.html similarity index 93% rename from module3/index.html rename to module3/index.pl.html index f9cb57ce..ee830c8b 100644 --- a/module3/index.html +++ b/module3/index.pl.html @@ -92,31 +92,31 @@

Łukasz Ziobroń

You can change the port by using npm start -- --port=8001. --> -
-
-
-
-
- -
From d38e30b51e42d026cd9f422381d1d5469679c189 Mon Sep 17 00:00:00 2001 From: MrMijagi Date: Fri, 28 Aug 2020 20:24:06 +0200 Subject: [PATCH 6/7] module3 finished --- README.md | 96 +++++++++++++++++++++++++--------- module3/01_scopes.en.md | 10 ++-- module3/02_references.en.md | 28 +++++----- module3/02_references.pl.md | 4 +- module3/03_pointers.en.md | 76 +++++++++++++-------------- module3/03_pointers.pl.md | 4 +- module3/04_hazards.en.md | 50 +++++++++--------- module3/04_hazards.pl.md | 2 +- module3/05_enums.en.md | 21 ++++---- module3/05_enums.pl.md | 2 +- module3/06_stl_algo_iter.en.md | 6 +-- module3/06_stl_algo_iter.pl.md | 2 +- module3/07_homework.en.md | 56 ++++++++++---------- module3/07_homework.pl.md | 4 +- 14 files changed, 205 insertions(+), 156 deletions(-) diff --git a/README.md b/README.md index f75f857f..87e75b2c 100644 --- a/README.md +++ b/README.md @@ -1,49 +1,97 @@ -# Podstawy C++ #1 - Coders School -## [Moduł 1](module1/) +# Podstawy C++ #1 + +## [Moduł 1](module1/index.pl.html) + +### [Typy](module1/01_types.pl.md) + +### [Funkcje](module1/02_functions.pl.md) + +### [Instrukcje warunkowe](module1/03_branches.pl.md) + +### [Pętle](module1/04_loops.pl.md) + +### [Tablice](module1/05_arrays.pl.md) + +### [Praca domowa](module1/06_homework.pl.md) + +## [Moduł 2](module2/index.pl.html) + +### [STL](module2/01_stl_intro.pl.md) + +### [`std::vector`](module2/02_vector.pl.md) + +### [`for` po kolekcji](module2/03_range_for.pl.md) + +### [`std::string`](module2/04_string.pl.md) + +### [`std::list`](module2/05_list.pl.md) + +### [`std::map`](module2/06_map.pl.md) + +### [Praca domowa](module2/07_homework.pl.md) + +## [Moduł 3](module3/index.pl.html) + +### [Zasięg zmiennych](module3/01_scopes.pl.md) + +### [Referencje](module3/02_references.pl.md) + +### [Wskaźniki](module3/03_pointers.pl.md) + +### [Zagrożenia](module3/04_hazards.pl.md) + +### [`enum` i `enum class`](module3/05_enums.pl.md) + +### [Praca domowa](module3/07_homework.pl.md) + +___ + +# C++ basics #1 + +## [Module 1](module1/index.en.html) -### [Typy](module1/presentation_types.md) +### [Types](module1/01_types.en.md) -### [Funkcje](module1/presentation_functions.md) +### [Functions](module1/02_functions.en.md) -### [Instrukcje warunkowe](module1/presentation_branches.md) +### [Conditional statements](module1/03_branches.en.md) -### [Pętle](module1/presentation_loops.md) +### [Loops](module1/04_loops.en.md) -### [Tablice](module1/presentation_arrays.md) +### [Arrays](module1/05_arrays.en.md) -### [Praca domowa](module1/presentation_homework.md) +### [Homework](module1/06_homework.en.md) -## [Moduł 2](module2/) +## [Module 2](module2/index.en.html) -### [STL](module2/presentation_stl_intro.md) +### [STL](module2/01_stl_intro.en.md) -### [`std::vector`](module2/presentation_vector.md) +### [`std::vector`](module2/02_vector.en.md) -### [`for` po kolekcji](module2/presentation_range_for.md) +### [`for` over collection](module2/03_range_for.en.md) -### [`std::string`](module2/presentation_string.md) +### [`std::string`](module2/04_string.en.md) -### [`std::list`](module2/presentation_list.md) +### [`std::list`](module2/05_list.en.md) -### [`std::map`](module2/presentation_map.md) +### [`std::map`](module2/06_map.en.md) -### [Praca domowa](module2/presentation_homework.md) +### [Homework](module2/07_homework.en.md) -## [Moduł 3](module3/) +## [Module 3](module3/index.en.html) -### [Zasięg zmiennych](module3/presentation_scopes.md) +### [Variables scope](module3/01_scopes.en.md) -### [Referencje](module3/presentation_references.md) +### [References](module3/02_references.en.md) -### [Wskaźniki](module3/presentation_pointers.md) +### [Pointers](module3/03_pointers.en.md) -### [Zagrożenia](module3/presentation_hazards.md) +### [Threats](module3/04_hazards.en.md) -### [`enum` i `enum class`](module3/presentation_enums.md) +### [`enum` and `enum class`](module3/05_enums.en.md) -### [Praca domowa](module3/presentation_homework.md) +### [Homework](module3/07_homework.en.md) diff --git a/module3/01_scopes.en.md b/module3/01_scopes.en.md index f01c7199..ef845ba5 100644 --- a/module3/01_scopes.en.md +++ b/module3/01_scopes.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## Scope of variables @@ -26,7 +26,7 @@ local_variable = 10; // error -> local_variable doesn't exists The range is always formed by curly braces, including: -* same parentheses - { /* ... */ } +* only parentheses - { /* ... */ } * function body - void fun() { /* ... */ } * conditional statements - if (condition) { /* ... */ } * loops - while (condition) { /* ... */ } @@ -35,7 +35,7 @@ ___ ## Global variables -A global variable, it is visible to all scopes. We can always refer to it. +A global variable is visible to all scopes. We can always refer to it. ```cpp @@ -81,7 +81,7 @@ ___ ## Overriding names -* we can have many variables with the same name if they are in different ranges +* we can have many variables with the same name if they are in different scopes * to avoid ambiguity this is rather not recommended * a name from the local scope always overrides the name from a wider scope (e.g. global) -* you can refer to names from global scope using :: (range operator) +* you can refer to names from global scope using :: (scope resolution operator) diff --git a/module3/02_references.en.md b/module3/02_references.en.md index 8344fa61..aaf98c99 100644 --- a/module3/02_references.en.md +++ b/module3/02_references.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## References @@ -12,23 +12,23 @@ ___ ## & -Magic badge `&` stands for reference. +Magic symbol `&` stands for reference. ```cpp int value = 5; int & number = value; ``` -The above notation denotes a variable `num` type `int&`, which is a reference to a type `int`. +The above notation gives a variable `number` type `int&`, which is a reference to a type `int`. It doesn't matter if we stick the reference to the type or name of the variable, but the reference is a separate type, so we suggest not to stick it to the variable name. ```cpp -int& number = value; // lewak -int &number = value; // prawak (odradzane) -int & number = value; // neutralny +int& number = value; // left +int &number = value; // right (not recommended) +int & number = value; // neutral ``` ___ @@ -47,19 +47,19 @@ std::cout << number << "\n"; // 6 ``` * The reference refers to an existing object -* If we create an object int value it through references int& reference = value we will be able to refer to it directly. +* If we create an object int value through references int& reference = value we will be able to refer to it directly. * Reference is another, additional name for the same variable (alias) * Modifying a reference = modifying the original object ___ -### What do we gain in this way? +### What do we gain this way? -* We don't need to copy items. It is enough for us to provide references. - * This way, we can freely read the value of this variable in many places in the program, without unnecessary copying it. +* We don't need to copy variables. It is enough to provide references. + * This way, we can freely read the value of this variable in many places in the program, without unnecessarily copying it. * A reference takes up as much in memory as an address (4 or 8 bytes). -* Building a reference to a type int (usually 4 bytes) does not always make optimization sense, unless you want to modify this element inside a function. -* Passing arguments by reference will make more sense when we get to know classes and objects :) +* Building a reference to a type int (usually 4 bytes) does not always make sense from optimization point, unless you want to modify this element inside a function. +* Passing arguments by reference will make more sense when we get to know classes and objects 🙂 [How much space does a reference take? - stackoverflow.com](https://stackoverflow.com/questions/1179937/how-does-a-c-reference-look-memory-wise) @@ -87,7 +87,7 @@ void bar(const int& num) { ``` -A function call is simply: +We call function simply like this: ```cpp @@ -101,7 +101,7 @@ ___ ## Task -Implement the function `foo()`. It is to accept and modify the text provided. We want to see on the screen `"Other string"`. +Implement the function `foo()`. It has to modify the text provided. On the screen we want to see `"Other string"`. ```cpp #include diff --git a/module3/02_references.pl.md b/module3/02_references.pl.md index eb39a760..7a2b1003 100644 --- a/module3/02_references.pl.md +++ b/module3/02_references.pl.md @@ -19,7 +19,7 @@ int value = 5; int & number = value; ``` -Powyższy zapis oznacza zmienną `num` typu `int&`, czyli referencję na typ `int`. +Powyższy zapis oznacza zmienną `number` typu `int&`, czyli referencję na typ `int`. Nie ma znaczenia, czy referencję dokleimy do typu, czy nazwy zmiennej, ale referencja jest oddzielnym typem, więc sugerujemy nie doklejać jej do nazwy zmiennej. @@ -59,7 +59,7 @@ ___ * W ten sposób możemy swobodnie w wielu miejscach programu odczytywać wartość tej zmiennej, bez zbędnego jej kopiowania. * Referencja zajmuje w pamięci tyle, ile zajmuje adres (4 lub 8 bajtów). * Tworzenie referencji do typu int (zazwyczaj 4 bajty) nie zawsze ma sens optymalizacyjny, chyba, że chcemy zmodyfikować ten element wewnątrz funkcji. -* Przekazywanie argumentów przez referencje nabierze więcej sensu, kiedy poznamy już klasy i obiekty :) +* Przekazywanie argumentów przez referencje nabierze więcej sensu, kiedy poznamy już klasy i obiekty 🙂 [Ile miejsca zajmuje referencja? - stackoverflow.com](https://stackoverflow.com/questions/1179937/how-does-a-c-reference-look-memory-wise) diff --git a/module3/03_pointers.en.md b/module3/03_pointers.en.md index 49050269..d3ede7c7 100644 --- a/module3/03_pointers.en.md +++ b/module3/03_pointers.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## Pointers @@ -10,28 +10,28 @@ ___ -## Indicators - an analogy +## Pointers - an analogy In addition to references, there are also pointers. Pointers work much like references. Imagine you are planning a trip to Majorca. We get on the plane and fly. -On the spot, it turns out that we have forgotten the hotel address :( +On the destination, it turns out that we have forgotten the hotel address 😦 In order to find it, we have to call the travel agency, wait for the service, explain the whole complex story, and finally, after a long time, we get the address of our hotel. The process of obtaining this information was time-consuming for us. -Let's imagine, however, that we have previously saved the address of our hotel on our phone. To remember where it was, we just need to check the phone and we know. The process took much less time. +Let's imagine, however, that we have previously saved the address of our hotel on our phone. To remember where it was, we just need to check the phone. The process took much less time. ___ -## Pointers in C ++ +## Pointers in C++ -It is similar in C ++. Pointers are used to indicate the location in memory where the desired object is located. +It is similar in C++. Pointers are used to indicate the location in memory where the desired object is located. -The processor does not have to ask the memory bus each time where the given variable is, but it knows immediately what its address is (we avoid intermediaries like a phone call to the service office). +The processor does not have to ask the memory bus each time where the given variable is because it knows immediately what its address is (we avoid intermediaries like a phone call to the service office). Also, if a function takes a pointer, it doesn't have to copy the entire contents of the object, which is time consuming. You can indicate where this object already exists much faster. @@ -39,7 +39,7 @@ Also, if a function takes a pointer, it doesn't have to copy the entire contents ___ -### How do I pass an element by a pointer? +### How do I pass a variable by a pointer? ```cpp void foo (int* num) { @@ -60,7 +60,7 @@ void bar (int const* num) { ``` -The function call is: +This is how you call this function: ```cpp @@ -72,7 +72,7 @@ The function call is: ___ -## Where to put const? +## Where to put `const`? ### What is this? @@ -102,7 +102,7 @@ A constant pointer to a variable (`int`). ___ -## Fixed pointers versus pointers fixed +## Constant pointers versus pointers on constant ```cpp int const * const ptr; @@ -113,7 +113,7 @@ const int * const ptr; Constant pointer to constant (`int const = const int`). -This is a common question from job interviews. So that the indicator is constant, `const` must be after the asterisk. +This is a common question from job interviews. For pointer to be constant, `const` must be after the asterisk. ___ @@ -129,15 +129,15 @@ ptr = nullptr; // ok ``` * We cannot modify the object pointed to by the pointer - * Appeals from `*` they cannot modify the object + * Referring with `*` cannot modify the object * We can modify the pointer itself, e.g. to point to another object - * Appeals without `*` can modify the pointer + * Referring without `*` can modify the pointer ___ ## Differences -### Constant indicator +### Constant pointer ```cpp int * const ptr = new int{42}; @@ -146,9 +146,9 @@ ptr = nullptr; // compilation error: assignment of read-only variable ‘ptr’ ``` * We can modify the object pointed to by the pointer - * Appeals from `*` can modify the object + * Referring with `*` can modify the object * We cannot modify the pointer itself, e.g. to point to another object - * Appeals without `*` they cannot modify the pointer + * Referring without `*` cannot modify the pointer ___ @@ -161,20 +161,20 @@ ptr = nullptr; // compilation error: assignment of read-only variable ‘ptr’ ``` * We cannot modify the object pointed to by the pointer - * Appeals from `*` they cannot modify the object + * Referring with `*` cannot modify the object * We cannot modify the pointer itself, e.g. to point to another object - * Appeals without `*` they cannot modify the pointer + * Referring without `*` cannot modify the pointer ___ ## Task -Implement the functions `foo()` and `bar()`. +Implement functions `foo()` and `bar()`. -`foo()` should modify the value passed by the pointer to 10, a `bar()` on 20. +`foo()` should modify the value passed by the pointer to 10, and `bar()` to 20. -Whether `foo()` or `bar()` can I take the pointer to a constant or constant pointer? +Can either `foo()` or `bar()` take the pointer to a constant or constant pointer? ```cpp #include @@ -211,10 +211,10 @@ ___ * The argument is a reference or a regular variable (copy) - we pass the name * The argument is a pointer and we pass the variable - we have to add & before the variable name. -### Signs +### Symbols -* Symbol * (dereference operator) denotes access to the referenced object -* If we don't * at the pointer we get the address of the pointed object +* Symbol * (dereference operator) gives access to the referenced object +* If we don't put * before the pointer we get the address of the pointed object * Symbol & means getting the address of our variable * The above makes sense because the pointer points to a memory location (the address of the pointed object) @@ -245,26 +245,26 @@ void example() { ___ -## Which means `*` in code? +## What does `*` mean in code? ```cpp -int a = 5 * 4; // jako operacja arytmetyczna - mnożenie -int* b = &a; // przy typie - wskaźnik na ten typ -int *c = &a; // przy typie - wskaźnik na ten typ -std::cout << *b; // przy zmiennej wskaźnikowej - dostęp do obiektu -int fun(int* wsk); // w argumencie funkcji - przekazanie wskaźnika (adresu) +int a = 5 * 4; // arithmetic operation - multiplying +int* b = &a; // next to type - pointer to the type +int *c = &a; // next to type - pointer to the type +std::cout << *b; // next to pointer - access to object +int fun(int* wsk); // in function argument - passing pointer (address) ``` -## Which means `&` in code? +## What does `&` mean in code? ```cpp -int a = 5 & 4; // jako operacja arytmetyczna - suma bitowa -int& b = a; // przy typie - referencja na ten typ -int &c = a; // przy typie - referencja na ten typ -std::cout << &a; // przy zmiennej - adres tej zmiennej w pamięci -int fun(int& ref); // w argumencie funkcji - przekazanie adresu +int a = 5 & 4; // as arithmetic operation - bitwise AND +int& b = a; // next to type - reference on type +int &c = a; // next to type - reference on type +std::cout << &a; // next to variable - address of this variable in memory +int fun(int& ref); // in function argument - passing the address ``` @@ -272,4 +272,4 @@ ___ ## Important rule -Unless absolutely necessary, then we don't use pointers at all. +Unless absolutely necessary, we don't use pointers at all. diff --git a/module3/03_pointers.pl.md b/module3/03_pointers.pl.md index 4e64fa30..052b0cc8 100644 --- a/module3/03_pointers.pl.md +++ b/module3/03_pointers.pl.md @@ -16,7 +16,7 @@ Poza referencjami istnieją także wskaźniki. Wskaźniki działają podobnie ja Wyobraźmy sobie, że planujemy wycieczkę na Majorkę. Wsiadamy do samolotu i lecimy. -Na miejscu okazuje się, ze zapomnieliśmy jaki jest adres hotelu :( +Na miejscu okazuje się, ze zapomnieliśmy jaki jest adres hotelu 😦 W celu znalezienia go musimy zadzwonić do biura podróży, poczekać na obsługę, wytłumaczyć całą zawiłą historię, aż w końcu po długim czasie otrzymujemy adres naszego hotelu. Proces zdobycia tych informacji był dla nas czasochłonny. @@ -72,7 +72,7 @@ Wywołanie funkcji to: ___ -## Gdzie dać const? +## Gdzie dać `const`? ### Co to jest? diff --git a/module3/04_hazards.en.md b/module3/04_hazards.en.md index 348f219c..e94bdc46 100644 --- a/module3/04_hazards.en.md +++ b/module3/04_hazards.en.md @@ -1,10 +1,10 @@ -# C ++ basics +# C++ basics ## Threats -### in the use of references and pointers +### while using references and pointers Coders School @@ -12,7 +12,7 @@ ___ -## Empty indicators +## Empty pointers ```cpp int* a = nullptr; @@ -44,22 +44,22 @@ int* a; std::cout << *a; ``` -Indicator `a` contains the so-called rubbish. -Accessing the object pointed to by such a pointer is undefined behavior. +Pointer `a` contains the so-called garbage. +Accessing the object pointed to it is undefined behavior. ___ ## References to deleted variables -As we already well know, local variables are removed when they are out of the scope we created them. +As we already know, local variables are removed when they are out of the scope we created them in. You can already guess what problems pointers and references will cause us when they still exist and the object they refer to is already destroyed. -It will be at best "Crash"at worst "Undefined behavior". +It will be at best "Crash" and "Undefined behavior" at worst. ### How to prevent such cases? -We must always ensure that the lifetime of the variable is longer than the lifetime of its indicator or reference. +We must always ensure that the lifetime of the variable is longer than the lifetime of its pointer or reference. ___ @@ -92,13 +92,13 @@ ___ The answer may be dynamically allocated memory. -The easiest way to do this is by using a library `#include `that has `std::shared_ptr`. +The easiest way to do this is by using a library `#include ` that has `std::shared_ptr`. -This indicator is called _intelligent_ for a reason. It is responsible for managing dynamic memory and releases the resource itself when we no longer need it. +This pointer is called _intelligent_ for a reason. It is responsible for managing dynamic memory and releases the resource itself when we no longer need it. -### How to create such an indicator? +### How to create such pointer? ```cpp @@ -109,7 +109,7 @@ auto ptr = std::shared_ptr(new int{5}); ___ -## Corrected listing +## Corrected code snippet ```cpp std::vector> vec; // previously: std::vector vec; @@ -138,11 +138,11 @@ ___ ## Task -Write a function `foo()`. It is supposed to accept shared_ptr on int and assign value 20 to the object pointed to by it. +Write a function `foo()`. It is supposed to accept `shared_ptr` on `int` and assign value 20 to the object pointed to by it. -also `foo()` is to display the value of the int pointed to by the pointer and the number of shared_pts that point to this object. +Also `foo()` has to display the value of the `int` pointed to by the pointer and the number of `shared_ptrs` that point to this object. -Also display the same in `main()` before and after the call `foo()`. +Also display above in `main()` before and after calling `foo()`. ```cpp #include @@ -167,7 +167,7 @@ ___ ## Task -Write a function `foo()`. It is supposed to take 2 values ​​of the type `int` and return their product as `shared_ptr`. Check how many owners it has `shared_ptr`. +Write a function `foo()`. It is supposed to take 2 values ​​of the type `int` and return their product as `shared_ptr`. Check how many owners `shared_ptr` has. ```cpp #include @@ -186,7 +186,7 @@ int main() { ___ -## Intelligent pointers the solution to all problems? +## Intelligent pointers as solution to all problems? Now that we've created a smart pointer, we don't have to worry about the variable's lifetime. We can safely print these values ​​after exiting the function. @@ -211,7 +211,7 @@ int main() { ___ -## The trap returns +## The danger returns ```cpp void foo(int* num) { @@ -229,23 +229,23 @@ int main() { } ``` -If all objects `shared_ptr` references to this variable are deleted, the resource is released. +If all objects of `shared_ptr` referencing to this variable are deleted, the resource is released. -Our usual indicator we downloaded earlier with `get()`, will have an address for a resource that no longer exists. +Our raw pointer we downloaded earlier with `get()` will have an address for a resource that no longer exists. -Attempting to use it will result in an UB or a crash. Be very careful with the usual pointers. +Attempting to use it will result in an UB or a crash. Be very careful with raw pointers. ___ ## Conclusions -* indicators may not point to anything (nullptr), the references must point to some previously created object +* pointers may not point to anything (nullptr), the references must point to some previously created object * pointers and references can be dangerous (more often pointers) if they are associated with objects that no longer exist - * these are the so-called dangling pointers / references, dangling pointers / references + * these are the so-called dangling pointers/references * The reference cannot be assigned an object other than the one specified during its initialization -* pointers can be assigned new addresses to point to other objects (except fixed pointers) -* better by default not to use raw pointers +* pointers can be assigned to new addresses to point to other objects (except constant pointers) +* it's better not to use raw pointers * it's better to use smart pointers diff --git a/module3/04_hazards.pl.md b/module3/04_hazards.pl.md index aeeb5bba..7e0f7c8e 100644 --- a/module3/04_hazards.pl.md +++ b/module3/04_hazards.pl.md @@ -138,7 +138,7 @@ ___ ## Zadanie -Napisz funkcję `foo()`. Ma ona przyjmować shared_ptr na int i ma przypisać wartość 20 do wskazywanego przez niego obiektu. +Napisz funkcję `foo()`. Ma ona przyjmować `shared_ptr` na `int` i ma przypisać wartość 20 do wskazywanego przez niego obiektu. Ponadto `foo()` ma wyświetlić wartość inta wskazywanego przez wskaźnik oraz liczbę shared_ptrów, które wskazują na ten obiekt. diff --git a/module3/05_enums.en.md b/module3/05_enums.en.md index 6b0a560c..81eb6f42 100644 --- a/module3/05_enums.en.md +++ b/module3/05_enums.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## `enum` and `enum class` @@ -12,8 +12,9 @@ ___ ## Enumerated type -`enum` is an enumerated type in Polish. -Also introduced in C ++ 11 `enum class` called a strong enumeration type. +`enum` is an enumerated type. + +Also `enum class` introduced in C++11, which is called a strong enumeration type. ### Example @@ -22,11 +23,11 @@ We would also like to create an interface that returns an error number, e.g .: * lack of water -* too heavy a load +* load is too heavy * problem with bearings * pump lock -In order to use type `enum` or better - `enum class`. +For this we use type `enum` or better - `enum class`. ___ @@ -55,7 +56,7 @@ ___ ## Numbering -Type `enum` underneath it is numbered from `0` down `n - 1`where `n` is the number of elements. +Type `enum` underneath is numbered from `0` to `n - 1`, where `n` is the number of elements. If we want to set different values, we have to do it manually: @@ -75,9 +76,9 @@ ___ ## `enum` vs `enum class` -`enum` from `enum class` the main difference is that we can implicitly convert the type `enum` on `int` (it's an enumerated type after all). +The main difference between `enum` and `enum class` is that we can implicitly convert the type `enum` to `int` (it's an enumerated type after all). -However, type `enum class` we can convert to `int`, only by explicit casting. We are not going to discuss casting for now. It's just worth it +However, type `enum class` we can convert to `int`, only by explicit casting. We are not going to discuss casting for now. It's just worth to remember that we do this by calling: @@ -94,7 +95,7 @@ ___ ## `enum` vs `enum class` -The second difference - for `enum` we may have a name conflict for `enum class` no. +The second difference - for `enum` we may have a name conflict, whereas for `enum class` not. ```cpp enum Color { @@ -127,7 +128,7 @@ if (lightColor == RED) { // 0 or 2? ___ -## Use the value of z `enum class` +## Example usage of `enum class` To avoid a name conflict, we use `enum class`. diff --git a/module3/05_enums.pl.md b/module3/05_enums.pl.md index 00b0b3f1..15ff4e6d 100644 --- a/module3/05_enums.pl.md +++ b/module3/05_enums.pl.md @@ -26,7 +26,7 @@ Chcielibyśmy utworzyć także interfejs zwracający numer błędu np: * problem z łożyskami * blokada pompy -W celu warto użyć typu `enum` lub lepiej - `enum class`. +W tym celu warto użyć typu `enum` lub lepiej - `enum class`. ___ diff --git a/module3/06_stl_algo_iter.en.md b/module3/06_stl_algo_iter.en.md index fcc56b2a..8f1e2e5e 100644 --- a/module3/06_stl_algo_iter.en.md +++ b/module3/06_stl_algo_iter.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## Introduction to STL @@ -12,11 +12,11 @@ ___ -Let's go back to the begin and end iterators for a moment. As we remember, they returned the beginning and the end of our container, e.g. std :: vector. +Let's go back to begin and end iterators for a moment. As we remember, they returned the beginning and the end of our container, e.g. std :: vector. in fact, begin and end returns to us an iterator pointing to 1 element of our container and to the element immediately after the last element. (here a photo of a few squares and marked as indicated by the begin and the end). What is an iterator? The easiest way is an element that points to a container element. We can freely increment it, i.e. move to the next elements of the container. We distinguish several types of iterators, but at the moment we will only deal with one. -It is called random acces iterator. It is important to us that such an iterator can freely refer to any element in our container. We get the random itarator when we call begin or end for std :: vector. To refer to the element the iterator points to, we use `*`. +It is called random access iterator. It is important to us that such an iterator can freely refer to any element in our container. We get the random iterator when we call begin or end for std :: vector. To refer to the element the iterator points to, we use `*`. What will be listed in the following lines? ``` diff --git a/module3/06_stl_algo_iter.pl.md b/module3/06_stl_algo_iter.pl.md index 043006e5..285a3f48 100644 --- a/module3/06_stl_algo_iter.pl.md +++ b/module3/06_stl_algo_iter.pl.md @@ -16,7 +16,7 @@ Wróćmy na chwilę do iteratorów begin oraz end. Jak pamiętamy zwracały one tak naprawdę to begin i end zwraca nam iterator wskazujący na 1 element naszego kontenera oraz na element znajdujący się tuż za ostatnim elementem. (tutaj zdjęcie kilku kwadracików i zaznaczone na co wskazuje begin a na co end). Czym jest iterator? Najprościej jest to element, który wskazuje nam na element kontenera. Możemy go swobodnie inkrementować, czyli przesuwać się do kolejnych elementów kontenera. Rozróżniamy kilka typów iteratorów ale na ten moment będziemy zajmować się tylko jednym. -Ma on nazwę random acces iterator. Dla nas ważne jest to, że taki iterator może swobodnie odwoływać się do dowolnego elementu w naszym kontenerze. Random itarator otrzymujemy między innymi gdy wywołamy begin lub end dla std::vector. Aby odwołać się do elementu, na który wskazuje iterator używamy `*`. +Ma on nazwę random access iterator. Dla nas ważne jest to, że taki iterator może swobodnie odwoływać się do dowolnego elementu w naszym kontenerze. Random iterator otrzymujemy między innymi gdy wywołamy begin lub end dla std::vector. Aby odwołać się do elementu, na który wskazuje iterator używamy `*`. Co zostanie wypisane w kolejnych linijkach? ``` diff --git a/module3/07_homework.en.md b/module3/07_homework.en.md index bf264755..3f791078 100644 --- a/module3/07_homework.en.md +++ b/module3/07_homework.en.md @@ -1,6 +1,6 @@ -# C ++ basics +# C++ basics ## Summary @@ -12,13 +12,13 @@ ___ ## What do you remember from today? -### Write as many passwords as possible in the chat +### Write as many keywords as possible in the chat 1. Scopes -2. Reference -3. Indicators -4. Threats when using references and indicators +2. References +3. Pointers +4. Threats while using references and pointers 5. Enumerated type enum and enum class ___ @@ -33,22 +33,22 @@ ___ #### Bonus for punctuality -For delivering each task before 07/06/2020 (Sunday) until 23:59 you will get 2 bonus points for each task +For delivering each task before 7 June 2020 (Sunday) until 23:59 you will get 2 bonus points for each task -#### [Repo jobs](https://github.com/coders-school/cpp-fundamentals/tree/master/module3/homework) +#### [Repo tasks](https://github.com/coders-school/cpp-fundamentals/tree/master/module3/homework) ___ ### Pre-work -* [Playlist on YT regarding STL](https://www.youtube.com/playlist?list=PL5jc9xFGsL8G3y3ywuFSvOuNm3GjBwdkb) - watch as much as you can :) -* Recall what a class is and how it is written - [watch the video of Mirosław Zelent](https://www.youtube.com/watch?v=aDXjubGK0jU). WARNING! From the 22nd minute you can observe some bad practices: D Try to guess which ones. +* [Playlist on YT regarding STL](https://www.youtube.com/playlist?list=PL5jc9xFGsL8G3y3ywuFSvOuNm3GjBwdkb) - watch as much as you can 🙂 +* Recall what a class is and how it is written - [watch the video of Mirosław Zelent](https://www.youtube.com/watch?v=aDXjubGK0jU). WARNING! From the 22nd minute you can observe some bad practices 😃. Try to guess which ones. ___ ## The PasswordCheck task -You create a password rule checker that receives data from a front-end contact form. The entire module is a set of several functions. Their declarations are to be included in the header file `validation.hpp`and the implementations in the source file `validation.cpp`. Your tasks are: +You create a password rule checker that receives data from a front-end contact form. The entire module exists of several functions. Their declarations are to be included in the header file `validation.hpp` and the implementations in the source file `validation.cpp`. Your tasks are: 1. Define a new type in the header file `ErrorCode` with possible values ​​for errors when setting a new password (1 point) @@ -62,19 +62,19 @@ You create a password rule checker that receives data from a front-end contact f ___ -## PasswordCheck Task continued. +## PasswordCheck Task continued -2. Write a function `getErrorMessage()`which will take the defined type of error code and return the appropriate message as a string. (1 point) -3. Write a function `doesPasswordsMatch()`which will receive two passwords and check if they are identical. Should return an appropriate bool value. (1 point) -4. Write a function `checkPasswordRules()`which will accept one password and randomly return one of the codes `PasswordNeedsAtLeast*` or `Ok`. (2 points) -5. Write a function `checkPassword()`. It should accept two passwords and use the function `doesPasswordsMatch()` to determine if the passwords match. If they do not match, it will return the code `PasswordsDoesNotMatch`otherwise, it should return the error code returned by the function call `checkPasswordRules()`. (2 points) -6. For ambitious (optional) - implement it in the function `checkPasswordRules()` true validation of the remaining cases which are given as error codes. Ideally, you should use the features of z [ header](https://en.cppreference.com/w/cpp/header/cctype) and the algorithm `std::any_of`. Add / modify appropriate tests. (4 points) +2. Write a function `getErrorMessage()` which will take the defined type of error code and return the appropriate message as a string. (1 point) +3. Write a function `doesPasswordsMatch()` which will receive two passwords and check if they are identical. It should return an appropriate bool value. (1 point) +4. Write a function `checkPasswordRules()` which will accept one password and randomly return one of the codes `PasswordNeedsAtLeast*` or `Ok`. (2 points) +5. Write a function `checkPassword()`. It should accept two passwords and use the function `doesPasswordsMatch()` to determine if the passwords match. If they do not match, it will return the code `PasswordsDoesNotMatch` otherwise, it should return the error code returned by the function call `checkPasswordRules()`. (2 points) +6. For ambitious (optional) - implement in function `checkPasswordRules()` with true validation of the remaining cases which are given as error codes. Ideally, you should use the features of [ header](https://en.cppreference.com/w/cpp/header/cctype) and the algorithm `std::any_of`. Add/modify appropriate tests. (4 points) -Total: 7 points (+4 for ambitious, +2 for delivery before 07/06/2020 23:59, +3 points / person for working in a pair) +Total: 7 points (+4 for ambitious, +2 for delivery before 7 June 2020 23:59, +3 points/person for working in a pair) ___ -## PasswordCheck Task - Usage Example +## PasswordCheck Task - Example ```cpp int main() { @@ -96,15 +96,15 @@ ___ ## The VectorOfSharedPointers task -Write a program that will contain 5 functions. Declarations should be included in the header file `vectorFunctions.hpp`and the implementations in the source file `vectorFunctions.cpp`. Create these files. +Write a program that will contain 5 functions. Declarations should be included in the header file `vectorFunctions.hpp` and the implementations in the source file `vectorFunctions.cpp`. Create these files. -* `std::vector> generate(int count)` which will generate a vector of shared pointers to numbers from `0` down `count` +* `std::vector> generate(int count)` which will generate a vector of shared pointers with numbers from `0` to `count` * `void print()` which will print all the elements from the vector pointers -* `void add10()` which will take a vector and add it to each number `10` -* `void sub10()` which will take a constant pointer to `int` and subtract from this element `10` +* `void add10()` which will take a vector and add `10` to each number +* `void sub10()` which will take a constant pointer to `int` and subtract `10` from this element * `void sub10();` Which will take a vector of shared pointers and call the above function overload for each element `sub10()` -Total: 5 points (1 for each function) (+2 for delivery before 07/06/2020 11:59 pm, +3 points / person for working in a pair) +Total: 5 points (1 for each function) (+2 for delivery before 7 June 2020 11:59 pm, +3 points/person for working in a pair) ### Example of use @@ -124,10 +124,10 @@ ___ ## Task delivery -1. If you don't already have the cpp-fundamentals repo fork and remote coders attached to it, see the earlier C ++ Basics # 2 and # 1 homework. -2. Update your repo from remote coders - `git fetch coders` +1. If you don't already have the cpp-fundamentals repo fork and coders remote attached to it, see the earlier C++ Basics #2 and #1 homeworks. +2. Update your repo from coders remote - `git fetch coders` 3. Switch to branch module3 - `git checkout module3` -4. Send branch module 3 to your photo - `git push origin module3` +4. Send branch module3 to your fork - `git push origin module3` 5. Create a separate branch for homework - `git checkout -b homework3` 6. Send this branch to the fork right away, before starting the implementation - `git push origin homework3` 7. Start the implementation alone or in pair. @@ -136,9 +136,9 @@ ___ ___ -## Next classes +## Next lessons -* Review of C ++ basics and tools +* Review of C++ basics and tools * Discussion of solutions to previous tasks * Overview of the most common errors based on Code Review * Q&A diff --git a/module3/07_homework.pl.md b/module3/07_homework.pl.md index 659ea77b..4b9cd651 100644 --- a/module3/07_homework.pl.md +++ b/module3/07_homework.pl.md @@ -41,8 +41,8 @@ ___ ### Pre-work -* [Playlista na YT odnośnie STLa](https://www.youtube.com/playlist?list=PL5jc9xFGsL8G3y3ywuFSvOuNm3GjBwdkb) - obejrzyj ile możesz :) -* Przypomnij sobie czym jest klasa i jak się ją pisze - [obejrzyj wideo Mirosława Zelenta](https://www.youtube.com/watch?v=aDXjubGK0jU). UWAGA! Od 22 minuty możesz zaobserwować trochę złych praktyk :D Spróbuj odgadnąć jakich. +* [Playlista na YT odnośnie STLa](https://www.youtube.com/playlist?list=PL5jc9xFGsL8G3y3ywuFSvOuNm3GjBwdkb) - obejrzyj ile możesz 🙂 +* Przypomnij sobie czym jest klasa i jak się ją pisze - [obejrzyj wideo Mirosława Zelenta](https://www.youtube.com/watch?v=aDXjubGK0jU). UWAGA! Od 22 minuty możesz zaobserwować trochę złych praktyk 😃 Spróbuj odgadnąć jakich. ___ From 95e295e5629f677a795736ae67fde4bcab25f469 Mon Sep 17 00:00:00 2001 From: MrMijagi Date: Fri, 28 Aug 2020 20:25:06 +0200 Subject: [PATCH 7/7] updated readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 87e75b2c..c3472373 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Coders School -# Podstawy C++ #1 +# Podstawy C++ ## [Moduł 1](module1/index.pl.html) @@ -50,7 +50,7 @@ ___ -# C++ basics #1 +# C++ basics ## [Module 1](module1/index.en.html)