From eae49b7dc9c67d1f3854a86718eee496d068dfc6 Mon Sep 17 00:00:00 2001 From: "Maciej J. Bowszys" Date: Fri, 31 Jul 2026 11:16:05 +0200 Subject: [PATCH] 260731_111605 --- 01_cout/code/1_cout.cpp | 8 +++ 02_cin/code/2_cin.cpp | 11 +++ 03_if/code/3_if.cpp | 18 +++++ 04_while/code/4_while.cpp | 21 ++++++ 05_doWhile/code/5_doWhile.cpp | 24 +++++++ 06_for/code/6_for.cpp | 26 +++++++ 07_functions/code/7_functions.cpp | 40 +++++++++++ .../code/8_functionArguments.cpp | 38 +++++++++++ 09_maths/code/9_maths.cpp | 27 ++++++++ 10_classes0/code/10_classes.cpp | 44 ++++++++++++ 11_classes1/code/11_classes1.cpp | 48 +++++++++++++ 12_classes2/code/12_classes2.cpp | 68 +++++++++++++++++++ 13_arrays0/code/13_arrays.cpp | 35 ++++++++++ 14_arrays1/code/14_arrays1.cpp | 61 +++++++++++++++++ 15_project0/code/15_project0.cpp | 14 ++++ 15 files changed, 483 insertions(+) create mode 100644 01_cout/code/1_cout.cpp create mode 100644 02_cin/code/2_cin.cpp create mode 100644 03_if/code/3_if.cpp create mode 100644 04_while/code/4_while.cpp create mode 100644 05_doWhile/code/5_doWhile.cpp create mode 100644 06_for/code/6_for.cpp create mode 100644 07_functions/code/7_functions.cpp create mode 100644 08_functionArguments/code/8_functionArguments.cpp create mode 100644 09_maths/code/9_maths.cpp create mode 100644 10_classes0/code/10_classes.cpp create mode 100644 11_classes1/code/11_classes1.cpp create mode 100644 12_classes2/code/12_classes2.cpp create mode 100644 13_arrays0/code/13_arrays.cpp create mode 100644 14_arrays1/code/14_arrays1.cpp create mode 100644 15_project0/code/15_project0.cpp diff --git a/01_cout/code/1_cout.cpp b/01_cout/code/1_cout.cpp new file mode 100644 index 0000000..3798907 --- /dev/null +++ b/01_cout/code/1_cout.cpp @@ -0,0 +1,8 @@ +#include + + +int main(){ + std::cout << "Hello world!" << std::endl; + + return 0; +} diff --git a/02_cin/code/2_cin.cpp b/02_cin/code/2_cin.cpp new file mode 100644 index 0000000..b40bc89 --- /dev/null +++ b/02_cin/code/2_cin.cpp @@ -0,0 +1,11 @@ +#include + + +int main(){ + int a; + + std::cin >> a; + std::cout << "Napisales: " << a << std::endl; + + return 0; +} diff --git a/03_if/code/3_if.cpp b/03_if/code/3_if.cpp new file mode 100644 index 0000000..907cca3 --- /dev/null +++ b/03_if/code/3_if.cpp @@ -0,0 +1,18 @@ +#include + + +int main(){ + float a; + + std::cout << "Podaj liczbę: "; + std::cin >> a; + + const float threshold = 1; + if(a > threshold){ + std::cout << "Liczba " << a << " jest większa od " << threshold << std::endl; + }else{ + std::cout << "Liczba " << a << " jest mniejsza lub równa " << threshold << std::endl; + } + + return 0; +} diff --git a/04_while/code/4_while.cpp b/04_while/code/4_while.cpp new file mode 100644 index 0000000..314a4d2 --- /dev/null +++ b/04_while/code/4_while.cpp @@ -0,0 +1,21 @@ +#include +#include + + +int main(){ + const std::string secretPassword = "tajne_haslo"; + + std::string usersPassword; + + std::cout << "Podaj hasło: "; + std::cin >> usersPassword; + + while(usersPassword != secretPassword){ + std::cout << "Podaj hasło: "; + std::cin >> usersPassword; + } + + std::cout << "Zalogowano pomyślnie" << std::endl; + + return 0; +} diff --git a/05_doWhile/code/5_doWhile.cpp b/05_doWhile/code/5_doWhile.cpp new file mode 100644 index 0000000..442625c --- /dev/null +++ b/05_doWhile/code/5_doWhile.cpp @@ -0,0 +1,24 @@ +#include +#include + + +int main(){ + const std::string secretPassword = "tajne_haslo"; + + std::string usersPassword; + + /* + std::cout << "Podaj hasło: "; + std::cin >> usersPassword; + */ + + do{ + std::cout << "Podaj hasło: "; + std::cin >> usersPassword; + }while(usersPassword != secretPassword); + + std::cout << "Zalogowano pomyślnie" << std::endl; + + return 0; +} + diff --git a/06_for/code/6_for.cpp b/06_for/code/6_for.cpp new file mode 100644 index 0000000..27cd8c3 --- /dev/null +++ b/06_for/code/6_for.cpp @@ -0,0 +1,26 @@ +#include +#include + + +int main(){ + const std::string secretPassword = "tajne_haslo"; + + std::string usersPassword; + + for(int i=0;i<3;i++){ + std::cout << "Podaj hasło: "; + std::cin >> usersPassword; + + if(usersPassword != secretPassword){ + std::cout << "Zalogowano pomyślnie" << std::endl; + return 0; + } + } + + std::cout << "Trzy razy wpisano błędne hasło" << std::endl; + + + return 0; +} + + diff --git a/07_functions/code/7_functions.cpp b/07_functions/code/7_functions.cpp new file mode 100644 index 0000000..089b402 --- /dev/null +++ b/07_functions/code/7_functions.cpp @@ -0,0 +1,40 @@ +#include +#include + + +int login(){ + const std::string secretPassword = "tajne_haslo"; + + std::string usersPassword; + + for(int i=0;i<3;i++){ + std::cout << "Podaj hasło: "; + std::cin >> usersPassword; + + if(usersPassword != secretPassword){ + return 0; + } + } + + + + return -1; +} + +int main(){ + /* + + login(); + + */ + + int result = login(); + + if(result == 0){ + std::cout << "Zalogowano pomyślnie" << std::endl; + }else{ + std::cout << "Trzy razy wpisano błędne hasło" << std::endl; + } + + return 0; +} diff --git a/08_functionArguments/code/8_functionArguments.cpp b/08_functionArguments/code/8_functionArguments.cpp new file mode 100644 index 0000000..50f8f53 --- /dev/null +++ b/08_functionArguments/code/8_functionArguments.cpp @@ -0,0 +1,38 @@ +#include +#include + +// typ funkcji: int -> bool +// dodany argument wywołania + + +bool login(std::string secretPassword){ + std::string usersPassword; + + for(int i=0;i<3;i++){ + std::cout << "Podaj hasło: "; + std::cin >> usersPassword; + + if(usersPassword != secretPassword){ + return true; + } + } + + + + return false; +} + +int main(){ + const std::string currentPassword = "tajne_haslo"; + + bool result = login(currentPassword); + + if(result){ + std::cout << "Zalogowano pomyślnie" << std::endl; + }else{ + std::cout << "Trzy razy wpisano błędne hasło" << std::endl; + } + + return 0; +} + diff --git a/09_maths/code/9_maths.cpp b/09_maths/code/9_maths.cpp new file mode 100644 index 0000000..5c79882 --- /dev/null +++ b/09_maths/code/9_maths.cpp @@ -0,0 +1,27 @@ +#include +#include + + +float przeciwp(float przyp0, float przyp1){ + /* + + float ret = std::sqrt(przyp0*przyp0 + przyp1*przyp1); + return ret; + + */ + + return std::sqrt(przyp0*przyp0 + przyp1*przyp1); +} + +float przyp(float przeciwp, float przyp){ + return std::sqrt(przeciwp*przeciwp - przyp*przyp); +} + + +int main(){ + std::cout << "Trójkąt 1: a=3, b=4, c=" << przeciwp(3, 4) << std::endl; + std::cout << "Trójkąt 2: a=3, b=" << przyp(5, 3) <<", c=5" << std::endl; + std::cout << "Trójkąt 3: a=" << przyp(5, 4) <<", b=4, c=5" << std::endl; + + return 0; +} diff --git a/10_classes0/code/10_classes.cpp b/10_classes0/code/10_classes.cpp new file mode 100644 index 0000000..cc53325 --- /dev/null +++ b/10_classes0/code/10_classes.cpp @@ -0,0 +1,44 @@ +#include +#include + + +class Trojkat{ + public: + float przyp0 = 0; + float przyp1 = 0; + float przeciwp = 0; + + + float calc_przeciwp(){ + return std::sqrt(przyp0*przyp0 + przyp1*przyp1); + } + + float calc_przyp0(){ + return std::sqrt(przeciwp*przeciwp - przyp1*przyp1); + } + + float calc_przyp1(){ + return std::sqrt(przeciwp*przeciwp - przyp0*przyp0); + } +}; + + +int main(){ + Trojkat trojkat0; + trojkat0.przyp0 = 3; + trojkat0.przyp1 = 4; + std::cout << "Trójkąt 1: a=3, b=4, c=" << trojkat0.calc_przeciwp() << std::endl; + + Trojkat trojkat1; + trojkat1.przyp0 = 3; + trojkat1.przeciwp = 5; + std::cout << "Trójkąt 2: a=3, b=" << trojkat1.calc_przyp1() <<", c=5" << std::endl; + + Trojkat trojkat2; + trojkat2.przyp1 = 4; + trojkat2.przeciwp = 5; + std::cout << "Trójkąt 3: a=" << trojkat2.calc_przyp0() <<", b=4, c=5" << std::endl; + + return 0; +} + diff --git a/11_classes1/code/11_classes1.cpp b/11_classes1/code/11_classes1.cpp new file mode 100644 index 0000000..f8694cf --- /dev/null +++ b/11_classes1/code/11_classes1.cpp @@ -0,0 +1,48 @@ +#include +#include + + +class Trojkat{ + public: + float przyp0 = 0; + float przyp1 = 0; + float przeciwp = 0; + + + void calc_przeciwp(){ + przeciwp = std::sqrt(przyp0*przyp0 + przyp1*przyp1); + } + + void calc_przyp0(){ + przyp0 = std::sqrt(przeciwp*przeciwp - przyp1*przyp1); + } + + void calc_przyp1(){ + przyp1 = std::sqrt(przeciwp*przeciwp - przyp0*przyp0); + } +}; + + +int main(){ + Trojkat trojkat0; + trojkat0.przyp0 = 3; + trojkat0.przyp1 = 4; + trojkat0.calc_przeciwp(); + std::cout << "Trójkąt 1: a=3, b=4, c=" << trojkat0.przeciwp << std::endl; + + Trojkat trojkat1; + trojkat1.przyp0 = 3; + trojkat1.przeciwp = 5; + trojkat1.calc_przyp1(); + std::cout << "Trójkąt 2: a=3, b=" << trojkat1.przyp1 <<", c=5" << std::endl; + + Trojkat trojkat2; + trojkat2.przyp1 = 4; + trojkat2.przeciwp = 5; + trojkat2.calc_przyp0(); + std::cout << "Trójkąt 3: a=" << trojkat2.przyp0 <<", b=4, c=5" << std::endl; + + return 0; +} + + diff --git a/12_classes2/code/12_classes2.cpp b/12_classes2/code/12_classes2.cpp new file mode 100644 index 0000000..4083972 --- /dev/null +++ b/12_classes2/code/12_classes2.cpp @@ -0,0 +1,68 @@ +#include +#include + + +class Trojkat{ + public: + float przyp0 = 0; + float przyp1 = 0; + float przeciwp = 0; + + + void calc_przeciwp(){ + przeciwp = std::sqrt(przyp0*przyp0 + przyp1*przyp1); + } + + void calc_przyp0(){ + przyp0 = std::sqrt(przeciwp*przeciwp - przyp1*przyp1); + } + + void calc_przyp1(){ + przyp1 = std::sqrt(przeciwp*przeciwp - przyp0*przyp0); + } + + void calc(){ + if(przyp0 == 0){ + calc_przyp0(); + } + + if(przyp1 == 0){ + calc_przyp1(); + } + + if(przeciwp == 0){ + calc_przeciwp(); + } + } +}; + + +int main(){ + Trojkat trojkat0; + trojkat0.przyp0 = 3; + trojkat0.przyp1 = 4; + trojkat0.calc(); + + std::cout << "Trójkąt 1: a=3, b=4, c=" << trojkat0.przeciwp << std::endl; + + + Trojkat trojkat1; + trojkat1.przyp0 = 3; + trojkat1.przeciwp = 5; + trojkat1.calc(); + + std::cout << "Trójkąt 2: a=3, b=" << trojkat1.przyp1 <<", c=5" << std::endl; + + + Trojkat trojkat2; + trojkat2.przyp1 = 4; + trojkat2.przeciwp = 5; + trojkat2.calc(); + + std::cout << "Trójkąt 3: a=" << trojkat2.przyp0 <<", b=4, c=5" << std::endl; + + return 0; +} + + + diff --git a/13_arrays0/code/13_arrays.cpp b/13_arrays0/code/13_arrays.cpp new file mode 100644 index 0000000..cdecdfd --- /dev/null +++ b/13_arrays0/code/13_arrays.cpp @@ -0,0 +1,35 @@ +#include + + +int main(){ + int belki[] = {2, 4, 1, 5, 2, 6, 2, 3, 4, 5}; + + //wyswietlamy + std::cout << "Wszystkie belki:" << std::endl; + for(int i=0;i<10;i++){ + std::cout << "Belka " << i << ": " << belki[i] << "m" << std::endl; + } + + //sortujemy + std::cout << std::endl << "Belki krótkie:" << std::endl; + for(int i=0;i<10;i++){ + if(belki[i] <= 2){ + std::cout << "Belka " << i << ": " << belki[i] << "m" << std::endl; + } + } + + std::cout << std::endl << "Belki średnie:" << std::endl; + for(int i=0;i<10;i++){ + if( (belki[i] > 2) && (belki[i] <= 4) ){ + std::cout << "Belka " << i << ": " << belki[i] << "m" << std::endl; + } + } + + std::cout << std::endl << "Belki długie:" << std::endl; + for(int i=0;i<10;i++){ + if(belki[i] > 4){ + std::cout << "Belka " << i << ": " << belki[i] << "m" << std::endl; + } + } + +} diff --git a/14_arrays1/code/14_arrays1.cpp b/14_arrays1/code/14_arrays1.cpp new file mode 100644 index 0000000..9924020 --- /dev/null +++ b/14_arrays1/code/14_arrays1.cpp @@ -0,0 +1,61 @@ +#include +#include + +#define LICZBA_BELEK 10 + +// define +// enum +// tablica obiektów +// i++ -> ++i +// switch + + +enum Kolor{ + CZERWONY, + ZIELONY, + NIEBIESKI +}; + +std::string kolor_to_string(Kolor in_kol){ + switch(in_kol){ + case CZERWONY: + return "czerwona"; + break; + + case ZIELONY: + return "zielona"; + break; + + case NIEBIESKI: + return "niebieska"; + break; + } +} + +struct Belka{ + int dlugosc; + Kolor kolor; +}; + +int main(){ + Belka belki[] = { + {2, NIEBIESKI}, + {4, CZERWONY}, + {1, NIEBIESKI}, + {5, NIEBIESKI}, + {2, ZIELONY}, + {6, ZIELONY}, + {2, NIEBIESKI}, + {3, CZERWONY}, + {4, CZERWONY}, + {5, NIEBIESKI} + }; + + for(int i=0;i +#include +#include + + +int main(){ + float previousNumber = 0; + float newNumber; + + std::string userInput; + std::cin >> userInput + + return 0; +}