260731_111605

This commit is contained in:
Maciej J. Bowszys 2026-07-31 11:16:05 +02:00
parent c61d385ca7
commit eae49b7dc9
15 changed files with 483 additions and 0 deletions

8
01_cout/code/1_cout.cpp Normal file
View File

@ -0,0 +1,8 @@
#include <iostream>
int main(){
std::cout << "Hello world!" << std::endl;
return 0;
}

11
02_cin/code/2_cin.cpp Normal file
View File

@ -0,0 +1,11 @@
#include <iostream>
int main(){
int a;
std::cin >> a;
std::cout << "Napisales: " << a << std::endl;
return 0;
}

18
03_if/code/3_if.cpp Normal file
View File

@ -0,0 +1,18 @@
#include <iostream>
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;
}

21
04_while/code/4_while.cpp Normal file
View File

@ -0,0 +1,21 @@
#include <iostream>
#include <string>
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;
}

View File

@ -0,0 +1,24 @@
#include <iostream>
#include <string>
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;
}

26
06_for/code/6_for.cpp Normal file
View File

@ -0,0 +1,26 @@
#include <iostream>
#include <string>
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;
}

View File

@ -0,0 +1,40 @@
#include <iostream>
#include <string>
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;
}

View File

@ -0,0 +1,38 @@
#include <iostream>
#include <string>
// 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;
}

27
09_maths/code/9_maths.cpp Normal file
View File

@ -0,0 +1,27 @@
#include <iostream>
#include <cmath>
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;
}

View File

@ -0,0 +1,44 @@
#include <iostream>
#include <cmath>
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;
}

View File

@ -0,0 +1,48 @@
#include <iostream>
#include <cmath>
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;
}

View File

@ -0,0 +1,68 @@
#include <iostream>
#include <cmath>
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;
}

View File

@ -0,0 +1,35 @@
#include <iostream>
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;
}
}
}

View File

@ -0,0 +1,61 @@
#include <iostream>
#include <string>
#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<LICZBA_BELEK;++i){
std::cout << "Belka numer " << i << " ma długość " << belki[i].dlugosc << "m i jest "
<< kolor_to_string(belki[i].kolor) << "." << std::endl;
}
return 0;
}

View File

@ -0,0 +1,14 @@
#include <iostream>
#include <cmath>
#include <string>
int main(){
float previousNumber = 0;
float newNumber;
std::string userInput;
std::cin >> userInput
return 0;
}