260731_111605
This commit is contained in:
parent
c61d385ca7
commit
eae49b7dc9
8
01_cout/code/1_cout.cpp
Normal file
8
01_cout/code/1_cout.cpp
Normal 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
11
02_cin/code/2_cin.cpp
Normal 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
18
03_if/code/3_if.cpp
Normal 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
21
04_while/code/4_while.cpp
Normal 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;
|
||||||
|
}
|
||||||
24
05_doWhile/code/5_doWhile.cpp
Normal file
24
05_doWhile/code/5_doWhile.cpp
Normal 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
26
06_for/code/6_for.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
40
07_functions/code/7_functions.cpp
Normal file
40
07_functions/code/7_functions.cpp
Normal 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;
|
||||||
|
}
|
||||||
38
08_functionArguments/code/8_functionArguments.cpp
Normal file
38
08_functionArguments/code/8_functionArguments.cpp
Normal 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
27
09_maths/code/9_maths.cpp
Normal 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;
|
||||||
|
}
|
||||||
44
10_classes0/code/10_classes.cpp
Normal file
44
10_classes0/code/10_classes.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
48
11_classes1/code/11_classes1.cpp
Normal file
48
11_classes1/code/11_classes1.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
68
12_classes2/code/12_classes2.cpp
Normal file
68
12_classes2/code/12_classes2.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
35
13_arrays0/code/13_arrays.cpp
Normal file
35
13_arrays0/code/13_arrays.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
61
14_arrays1/code/14_arrays1.cpp
Normal file
61
14_arrays1/code/14_arrays1.cpp
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
14
15_project0/code/15_project0.cpp
Normal file
14
15_project0/code/15_project0.cpp
Normal 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;
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user