Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tłumaczenie #2

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 72 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,49 +1,97 @@
# Podstawy C++ #1

<a href="https://coders.school">
<img width="500" data-src="coders_school_logo.png" src="coders_school_logo.png" alt="Coders School" class="plain">
</a>

## [Moduł 1](module1/)
# Podstawy C++

## [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

## [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)
206 changes: 206 additions & 0 deletions module1/01_types.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
<!-- .slide: data-background="#111111" -->

# C++ basics

## Data types

<a href="https://coders.school">
<img width="500px" data-src="../coders_school_logo.png" alt="Coders School" class="plain">
</a>

___

## Some simple math

* <!-- .element: class="fragment fade-in" --> 1 byte == 8 bits
* <!-- .element: class="fragment fade-in" --> In a binary lottery, randomly selected numbers may have values <code>0</code> or <code>1</code>
* <!-- .element: class="fragment fade-in" --> Thus, when drawing 8 numbers, we can get, for example: <code>1 0 1 0 1 0 1 0</code>
* <!-- .element: class="fragment fade-in" --> There are exactly <code>256 -> (2^8)</code> such combinations
* <!-- .element: class="fragment fade-in" --> Thus, in 1 byte (8 bits) we can write 256 numbers, e.g. from 0 to 255
* <!-- .element: class="fragment fade-in" --> If we draw 32 numbers in the lottery, (32/8 = 4), i.e. 4 bytes, there are <code>2^32</code> such combinations (i.e. over 4 billion)

___

## Empty type - `void`

* <!-- .element: class="fragment fade-in" --> Objects of <code>void</code> type cannot be created
* <!-- .element: class="fragment fade-in" --> It is used to indicate that the function does not return anything
* <!-- .element: class="fragment fade-in" --> You can create <code>void*</code> pointers (bad practice in C++)
* <!-- .element: class="fragment fade-in" --> It is NOT used to indicate that the function takes no arguments

```cpp
int fun(void) { /* ... */ } // bad practice, C style
int fun() { /* ... */ } // good practice, C++ style
```
<!-- .element: class="fragment fade-in" -->

___

## 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` to `127`
* `unsigned char` -> from `0` to `255`

Prefix `unsigned` means that there are no negative numbers i.e. from 0 to some positive value.
<!-- .element: class="fragment fade-in" -->

The size of character types is always 1 byte.
<!-- .element: class="fragment fade-in" -->

The sizes of further types are platform dependent e.g. 32 bits or 64 bits.
<!-- .element: class="fragment fade-in" -->

___

## 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) <!-- .element: class="fragment fade-in" -->
* They have special values: <!-- .element: class="fragment fade-in" -->
* `0`, `-0` (negative zero)
* `-Inf`, `+Inf` (infinity)
* `NaN` (Not a Number)

Warning! Comparison `NaN == NaN` gives `false` <!-- .element: class="fragment highlight-red" -->
<!-- .element: class="fragment fade-in" -->

Advanced Reading: [The IEEE754 standard that defines floating point types](https://en.wikipedia.org/wiki/IEEE_754)
<!-- .element: class="fragment fade-in" -->

___

## Type aliases

There are also types that are aliases (different naming for better understanding of type).

`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.
<!-- .element: class="fragment fade-in" -->

We can create our own type aliases using `typedef` or `using`
<!-- .element: class="fragment fade-in" -->

```cpp
typedef int Number;
Number a = 5; // int a = 5;

using Fraction = double;
Fraction b = 10.2; // double b = 10.2;
```
<!-- .element: class="fragment fade-in" -->

___

## `auto` type

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
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: + - * / <!-- .element: class="fragment fade-in" -->
* Modifying a variable: += -= *= /= <!-- .element: class="fragment fade-in" -->
* Incrementing (+1) variable: ++ <!-- .element: class="fragment fade-in" -->
* Decrementing (-1) variable: -- <!-- .element: class="fragment fade-in" -->

### Examples <!-- .element: class="fragment fade-in" -->

```cpp
int a = 5 + 7; // a = 12
```
<!-- .element: class="fragment fade-in" -->

```cpp
int a = 5;
a += 7; // a = 12
```
<!-- .element: class="fragment fade-in" -->

```cpp
int a = 5;
++a; // a = 6
a--; // a = 5
```
<!-- .element: class="fragment fade-in" -->

___

## Questions

```cpp
int i = 5;
auto j = i++ - 1;
```

<span class="fragment fade-in">What are the values `i` and `j`?</span>

`i = 6` <!-- .element: class="fragment fade-in" -->

`j = 4` <!-- .element: class="fragment fade-in" -->

<span class="fragment fade-in">What type is `j`?</span>

`int` <!-- .element: class="fragment fade-in" -->

___

## A little joke

What do you call 8 hobbits? <!-- .element: class="fragment fade-in" -->

A Hobbyte :) <!-- .element: class="fragment fade-in" -->

<!-- I couldn't get translation with the original one, so I took this version from internet :P -->
___

## 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)
12 changes: 6 additions & 6 deletions module1/presentation_types.md → module1/01_types.pl.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ ___
## Prosta matematyka

* <!-- .element: class="fragment fade-in" --> 1 bajt == 8 bitów
* <!-- .element: class="fragment fade-in" --> W binarnym totolotku wylosowane liczby mogą mieć `0` lub `1`
* <!-- .element: class="fragment fade-in" --> Zatem podczas losowania 8 numerków możemy otrzymać przykładowo: `1 0 1 0 1 0 1 0`
* <!-- .element: class="fragment fade-in" --> Takich kombinacji jest dokładnie `256 -> (2^8)`
* <!-- .element: class="fragment fade-in" --> W binarnym totolotku wylosowane liczby mogą mieć <code>0</code> lub <code>1</code>
* <!-- .element: class="fragment fade-in" --> Zatem podczas losowania 8 numerków możemy otrzymać przykładowo: <code>1 0 1 0 1 0 1 0</code>
* <!-- .element: class="fragment fade-in" --> Takich kombinacji jest dokładnie <code>256 -> (2^8)</code>
* <!-- .element: class="fragment fade-in" --> Zatem na 1 bajcie (8 bitach) możemy zapisać 256 liczb, np. od 0 do 255
* <!-- .element: class="fragment fade-in" --> Jeżeli w totolotku losujemy 32 numerki, (32/8 = 4) czyli 4 bajty to takich kombinacji jest `2^32` (czyli ponad 4 miliardy)
* <!-- .element: class="fragment fade-in" --> Jeżeli w totolotku losujemy 32 numerki, (32/8 = 4) czyli 4 bajty to takich kombinacji jest <code>2^32</code> (czyli ponad 4 miliardy)

___

## Typ pusty - `void`

* <!-- .element: class="fragment fade-in" --> Nie można tworzyć obiektów typu `void`
* <!-- .element: class="fragment fade-in" --> Nie można tworzyć obiektów typu <code>void</code>
* <!-- .element: class="fragment fade-in" --> Służy do zaznaczenia, że funkcja nic nie zwraca
* <!-- .element: class="fragment fade-in" --> Można tworzyć wskaźniki `void*` (zła praktyka w C++)
* <!-- .element: class="fragment fade-in" --> Można tworzyć wskaźniki <code>void*</code> (zła praktyka w C++)
* <!-- .element: class="fragment fade-in" --> NIE służy do oznaczania, że funkcja nie przyjmuje argumentów

```cpp
Expand Down
Loading