mirror of
https://github.com/szymon-jozef/ZUT-notatki.git
synced 2026-10-27 19:20:39 +01:00
bla bla
This commit is contained in:
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/1
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/1
Executable file
Binary file not shown.
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/10
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/10
Executable file
Binary file not shown.
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/11
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/11
Executable file
Binary file not shown.
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/12
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/12
Executable file
Binary file not shown.
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/2
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/2
Executable file
Binary file not shown.
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/3
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/3
Executable file
Binary file not shown.
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/4
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/4
Executable file
Binary file not shown.
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/5
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/5
Executable file
Binary file not shown.
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/6
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/6
Executable file
Binary file not shown.
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/7
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/7
Executable file
Binary file not shown.
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/8
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/8
Executable file
Binary file not shown.
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/9
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab6/out/9
Executable file
Binary file not shown.
20
uczelnia/2_semestr/programowanie/laby/lab6/zad1.cpp
Normal file
20
uczelnia/2_semestr/programowanie/laby/lab6/zad1.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
|
||||
class Prostokat {
|
||||
public:
|
||||
double szerokosc;
|
||||
double wysokosc;
|
||||
double pole() { return szerokosc * wysokosc; }
|
||||
double obwod() { return 2 * szerokosc + 2 * wysokosc; }
|
||||
};
|
||||
|
||||
int main() {
|
||||
Prostokat p1;
|
||||
p1.szerokosc = 2;
|
||||
p1.wysokosc = 2;
|
||||
double pole = p1.pole();
|
||||
double obwod = p1.obwod();
|
||||
printf(
|
||||
"Pole o szerokości %0.2f i wysokości %0.2f ma pole %0.2f i obwód %0.2f",
|
||||
p1.szerokosc, p1.wysokosc, pole, obwod);
|
||||
}
|
||||
35
uczelnia/2_semestr/programowanie/laby/lab6/zad10.cpp
Normal file
35
uczelnia/2_semestr/programowanie/laby/lab6/zad10.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
|
||||
class Konto {
|
||||
static int liczbaKont;
|
||||
float saldo;
|
||||
|
||||
public:
|
||||
Konto(int saldoPoczatkowe) : saldo(saldoPoczatkowe) { Konto::liczbaKont++; }
|
||||
void wplac(float pieniadze) { saldo += pieniadze; }
|
||||
void wyplac(float pieniadze) {
|
||||
if (saldo - pieniadze <= 0) {
|
||||
throw std::invalid_argument(
|
||||
"Saldo po wypłacie nie może być mniejsze niż 0!!!\n");
|
||||
}
|
||||
saldo -= pieniadze;
|
||||
}
|
||||
void pokazSaldo() { printf("Aktualne saldo to: %0.2f\n", saldo); }
|
||||
|
||||
static void ileKont() {
|
||||
printf("Aktualnie jest %d kont\n", Konto::liczbaKont);
|
||||
}
|
||||
};
|
||||
|
||||
int Konto::liczbaKont = 0;
|
||||
|
||||
int main() {
|
||||
Konto::ileKont();
|
||||
Konto k1 = Konto(20);
|
||||
Konto::ileKont();
|
||||
Konto k2 = Konto(20);
|
||||
Konto::ileKont();
|
||||
Konto k3 = Konto(20);
|
||||
Konto::ileKont();
|
||||
}
|
||||
69
uczelnia/2_semestr/programowanie/laby/lab6/zad11.cpp
Normal file
69
uczelnia/2_semestr/programowanie/laby/lab6/zad11.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
|
||||
class Produkt {
|
||||
public:
|
||||
std::string nazwa;
|
||||
float cena;
|
||||
Produkt(std::string nazwa, float cena) : nazwa(nazwa), cena(cena) {}
|
||||
Produkt() : nazwa(""), cena(0) {}
|
||||
|
||||
const Produkt &operator=(const Produkt *p) {
|
||||
if (this != p) {
|
||||
nazwa = p->nazwa;
|
||||
cena = p->cena;
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
class Magazyn {
|
||||
public:
|
||||
Produkt *produkty;
|
||||
size_t max_pojemnosc;
|
||||
size_t aktualna_pojemnosc;
|
||||
|
||||
Magazyn(size_t pojemnosc) {
|
||||
this->max_pojemnosc = pojemnosc;
|
||||
this->aktualna_pojemnosc = 0;
|
||||
produkty = new Produkt[pojemnosc];
|
||||
}
|
||||
~Magazyn() { delete[] produkty; }
|
||||
|
||||
void dodaj(const Produkt &p) {
|
||||
if (aktualna_pojemnosc >= max_pojemnosc) {
|
||||
printf("Nie można dołożyć elementu, za mało miejsca\n");
|
||||
return;
|
||||
}
|
||||
|
||||
produkty[aktualna_pojemnosc++] = p;
|
||||
}
|
||||
|
||||
Produkt *znajdz(std::string nazwa) {
|
||||
for (size_t i = 0; i < aktualna_pojemnosc; i++) {
|
||||
if (produkty[i].nazwa == nazwa) {
|
||||
return &produkty[i];
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void wypiszWszystkie() const {
|
||||
for (size_t i = 0; i < aktualna_pojemnosc; i++) {
|
||||
printf("Nazwa: %s | Cena: %0.2f\n", produkty[i].nazwa.c_str(),
|
||||
produkty[i].cena);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
Magazyn m(5);
|
||||
m.dodaj(Produkt("Laptop", 3500.0));
|
||||
m.dodaj(Produkt("Mysz", 49.99));
|
||||
m.dodaj(Produkt("Klawiatura", 129.0));
|
||||
Produkt *p = m.znajdz("Mysz");
|
||||
if (p != nullptr) {
|
||||
p->cena = 39.99; // zmiana przez wskaźnik
|
||||
}
|
||||
m.wypiszWszystkie();
|
||||
}
|
||||
60
uczelnia/2_semestr/programowanie/laby/lab6/zad12.cpp
Normal file
60
uczelnia/2_semestr/programowanie/laby/lab6/zad12.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <stdio.h>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class Student {
|
||||
std::string imie;
|
||||
std::vector<double> oceny;
|
||||
|
||||
public:
|
||||
Student(std::string imie) : imie(imie) {}
|
||||
|
||||
void dodajOcene(double ocena) { oceny.push_back(ocena); }
|
||||
double srednia() const {
|
||||
double sum = 0;
|
||||
for (double ocena : oceny) {
|
||||
sum += ocena;
|
||||
}
|
||||
double avg = sum / oceny.size();
|
||||
return avg;
|
||||
}
|
||||
|
||||
void wypisz() const {
|
||||
printf("Imie %s\n", imie.c_str());
|
||||
printf("Oceny:\n");
|
||||
for (double ocena : oceny) {
|
||||
printf("- %0.1f\n", ocena);
|
||||
}
|
||||
printf("Średnia: %0.2f\n", srednia());
|
||||
}
|
||||
};
|
||||
|
||||
class Dziennik {
|
||||
std::vector<std::reference_wrapper<Student>> studenci;
|
||||
|
||||
public:
|
||||
void zarejestruj(Student &s) { studenci.push_back(s); }
|
||||
void dodajOceneWszystkim(double ocena) {
|
||||
for (Student &student : studenci) {
|
||||
student.dodajOcene(ocena);
|
||||
}
|
||||
}
|
||||
|
||||
void raport() const {
|
||||
printf("--- Wszyscy studenci ---\n");
|
||||
for (const Student student : studenci) {
|
||||
student.wypisz();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
Student s1 = Student("Bogdan");
|
||||
Student s2 = Student("Wojciech");
|
||||
|
||||
Dziennik dziennik = Dziennik();
|
||||
dziennik.zarejestruj(s1);
|
||||
dziennik.zarejestruj(s2);
|
||||
dziennik.dodajOceneWszystkim(5);
|
||||
dziennik.raport();
|
||||
}
|
||||
22
uczelnia/2_semestr/programowanie/laby/lab6/zad2.cpp
Normal file
22
uczelnia/2_semestr/programowanie/laby/lab6/zad2.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
class Prostokat {
|
||||
private:
|
||||
double szerokosc;
|
||||
double wysokosc;
|
||||
|
||||
public:
|
||||
Prostokat(double szerokosc, double wysokosc)
|
||||
: szerokosc(szerokosc), wysokosc(wysokosc) {}
|
||||
double pole() { return szerokosc * wysokosc; }
|
||||
double obwod() { return 2 * szerokosc + 2 * wysokosc; }
|
||||
double getSzerokosc() { return szerokosc; }
|
||||
double getWysokosc() { return wysokosc; }
|
||||
};
|
||||
|
||||
int main() {
|
||||
Prostokat p1 = Prostokat(2, 2);
|
||||
// p1.szerokosc = 4; taka operacja jest nieakceptowalna albowiem skrajnie
|
||||
// nierozsądnym i można powiedzieć __nieakceptowalnym__ jest próba przypisania
|
||||
// wartości do pola oznaczonego mianem prywatnego. Na szczęście jaśnie
|
||||
// oświecony kompilator języka c++ powstrzymuje nas przed takim godnym
|
||||
// potępienia występkiem.
|
||||
}
|
||||
20
uczelnia/2_semestr/programowanie/laby/lab6/zad3.cpp
Normal file
20
uczelnia/2_semestr/programowanie/laby/lab6/zad3.cpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <iostream>
|
||||
|
||||
class Licznik {
|
||||
int wartosc;
|
||||
|
||||
public:
|
||||
Licznik() : wartosc(0) {}
|
||||
void dodaj() { wartosc++; }
|
||||
int ile() const { return wartosc; }
|
||||
};
|
||||
int main() {
|
||||
Licznik a; // 0
|
||||
Licznik b; // 0
|
||||
a.dodaj(); // 1
|
||||
a.dodaj(); // 2
|
||||
a.dodaj(); // 3
|
||||
b.dodaj(); // 1
|
||||
std::cout << a.ile() << " " << b.ile()
|
||||
<< "\n"; // a.ile() == 2 && b.ile() == 1
|
||||
}
|
||||
22
uczelnia/2_semestr/programowanie/laby/lab6/zad4.cpp
Normal file
22
uczelnia/2_semestr/programowanie/laby/lab6/zad4.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <iostream>
|
||||
|
||||
class Kalkulator {
|
||||
public:
|
||||
void podwoj(int x) { x *= 2; }
|
||||
void podwojRef(int &x) { x *= 2; }
|
||||
void zamien(int &a, int &b) {
|
||||
int tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
};
|
||||
int main() {
|
||||
Kalkulator k;
|
||||
int a = 5, b = 10;
|
||||
k.podwoj(a); // a = 5
|
||||
std::cout << a << std::endl;
|
||||
k.podwojRef(a); // a = 10
|
||||
std::cout << a << std::endl;
|
||||
k.zamien(a, b); // a = 10, b = 10
|
||||
std::cout << a << ' ' << b << std::endl;
|
||||
}
|
||||
52
uczelnia/2_semestr/programowanie/laby/lab6/zad5.cpp
Normal file
52
uczelnia/2_semestr/programowanie/laby/lab6/zad5.cpp
Normal file
@@ -0,0 +1,52 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
class Tablica {
|
||||
std::vector<int> tablica;
|
||||
|
||||
public:
|
||||
void dodaj(int x) { tablica.push_back(x); }
|
||||
|
||||
void wypelnij(std::vector<int> &cel) {
|
||||
cel.insert(cel.end(), tablica.begin(), tablica.end());
|
||||
}
|
||||
|
||||
int suma() const {
|
||||
int sum = 0;
|
||||
for (int element : tablica) {
|
||||
sum += element;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
void wyczysc() { tablica.clear(); }
|
||||
|
||||
void wyswietl() {
|
||||
for (int element : tablica) {
|
||||
std::cout << element << ' ';
|
||||
}
|
||||
|
||||
std::cout << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
Tablica t;
|
||||
t.dodaj(3);
|
||||
t.wyswietl();
|
||||
t.dodaj(7);
|
||||
t.wyswietl();
|
||||
t.dodaj(1);
|
||||
t.wyswietl();
|
||||
std::vector<int> kopia;
|
||||
t.wypelnij(kopia);
|
||||
std::cout << "Kopia: " << std::endl;
|
||||
for (int element : kopia) {
|
||||
std::cout << element << ' ';
|
||||
}
|
||||
std::cout << std::endl;
|
||||
// kopia zawiera: 3, 7, 1
|
||||
int suma = t.suma();
|
||||
std::cout << "Suma wynosi: " << suma << std::endl;
|
||||
t.wyczysc();
|
||||
t.wyswietl();
|
||||
}
|
||||
25
uczelnia/2_semestr/programowanie/laby/lab6/zad6.cpp
Normal file
25
uczelnia/2_semestr/programowanie/laby/lab6/zad6.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <iostream>
|
||||
|
||||
class Licznik {
|
||||
int wartosc;
|
||||
|
||||
public:
|
||||
Licznik(int w) : wartosc(w) {}
|
||||
void zwieksz() { wartosc++; }
|
||||
int pobierz() const { return wartosc; }
|
||||
void resetuj() { wartosc = 0; }
|
||||
};
|
||||
int main() {
|
||||
Licznik a(10);
|
||||
Licznik *wsk = &a;
|
||||
wsk->zwieksz();
|
||||
std::cout << a.pobierz() << '\n'; // 11 (linia A)
|
||||
std::cout << wsk->pobierz() << '\n'; // 11 (linia B)
|
||||
Licznik b(100);
|
||||
wsk = &b;
|
||||
wsk->zwieksz();
|
||||
std::cout << a.pobierz() << '\n'; // 11 (linia C)
|
||||
std::cout << b.pobierz() << '\n'; // 101 (linia D)
|
||||
a.resetuj();
|
||||
std::cout << a.pobierz(); // 0
|
||||
}
|
||||
48
uczelnia/2_semestr/programowanie/laby/lab6/zad7.cpp
Normal file
48
uczelnia/2_semestr/programowanie/laby/lab6/zad7.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <iostream>
|
||||
|
||||
class Punkt {
|
||||
public:
|
||||
int x, y;
|
||||
Punkt(int x, int y) : x(x), y(y) {}
|
||||
|
||||
void wyswietl() { std::cout << '(' << x << ',' << y << ')' << std::endl; }
|
||||
};
|
||||
|
||||
void zamienRef(Punkt &a, Punkt &b) {
|
||||
int x = a.x;
|
||||
int y = a.y;
|
||||
int i = b.x;
|
||||
int j = b.y;
|
||||
a.x = i;
|
||||
a.y = j;
|
||||
b.x = x;
|
||||
b.y = y;
|
||||
}
|
||||
|
||||
void zamienWsk(Punkt *a, Punkt *b) {
|
||||
int x = a->x;
|
||||
int y = a->y;
|
||||
int i = b->x;
|
||||
int j = b->y;
|
||||
a->x = i;
|
||||
a->y = j;
|
||||
b->x = x;
|
||||
b->y = y;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::cout << "Punkty: " << std::endl;
|
||||
Punkt p1(1, 2), p2(3, 4);
|
||||
p1.wyswietl();
|
||||
p2.wyswietl();
|
||||
std::cout << "Zamiana referencją: " << std::endl;
|
||||
zamienRef(p1, p2); // wywołanie przez referencję
|
||||
//
|
||||
p1.wyswietl();
|
||||
p2.wyswietl();
|
||||
|
||||
std::cout << "Zamiana wskaźnikiem: " << std::endl;
|
||||
zamienWsk(&p1, &p2); // wywołanie przez wskaźnik
|
||||
p1.wyswietl();
|
||||
p2.wyswietl();
|
||||
}
|
||||
11
uczelnia/2_semestr/programowanie/laby/lab6/zad7_2.cpp
Normal file
11
uczelnia/2_semestr/programowanie/laby/lab6/zad7_2.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <string>
|
||||
|
||||
class Samochod {
|
||||
std::string marka;
|
||||
int predkosc;
|
||||
|
||||
Samochod(std::string marka, int predkosc) {
|
||||
this->marka = marka;
|
||||
this->predkosc = predkosc;
|
||||
}
|
||||
};
|
||||
19
uczelnia/2_semestr/programowanie/laby/lab6/zad8.cpp
Normal file
19
uczelnia/2_semestr/programowanie/laby/lab6/zad8.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
|
||||
class Pies {
|
||||
public:
|
||||
static int liczba;
|
||||
Pies() { Pies::liczba++; }
|
||||
};
|
||||
|
||||
int Pies::liczba = 0;
|
||||
|
||||
int main() {
|
||||
printf("Aktualnie jest %d psów\n", Pies::liczba);
|
||||
Pies p1 = Pies();
|
||||
printf("Aktualnie jest %d psów\n", Pies::liczba);
|
||||
Pies p2 = Pies();
|
||||
printf("Aktualnie jest %d psów\n", Pies::liczba);
|
||||
Pies p3 = Pies();
|
||||
printf("Aktualnie jest %d psów\n", Pies::liczba);
|
||||
}
|
||||
40
uczelnia/2_semestr/programowanie/laby/lab6/zad9.cpp
Normal file
40
uczelnia/2_semestr/programowanie/laby/lab6/zad9.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
|
||||
class Konto {
|
||||
float saldo;
|
||||
|
||||
public:
|
||||
Konto(int saldoPoczatkowe) : saldo(saldoPoczatkowe) {}
|
||||
void wplac(float pieniadze) { saldo += pieniadze; }
|
||||
void wyplac(float pieniadze) {
|
||||
if (saldo - pieniadze <= 0) {
|
||||
throw std::invalid_argument(
|
||||
"Saldo po wypłacie nie może być mniejsze niż 0!!!\n");
|
||||
}
|
||||
saldo -= pieniadze;
|
||||
}
|
||||
void pokazSaldo() { printf("Aktualne saldo to: %0.2f\n", saldo); }
|
||||
};
|
||||
|
||||
int main() {
|
||||
float n = 200;
|
||||
printf("Tworzymy konto z saldem początkowym %0.2f\n", n);
|
||||
Konto k = Konto(n);
|
||||
k.pokazSaldo();
|
||||
|
||||
printf("Wypłacamy 100 zł\n");
|
||||
k.wyplac(100);
|
||||
k.pokazSaldo();
|
||||
|
||||
printf("Wpłacamy 50 zł\n");
|
||||
k.pokazSaldo();
|
||||
|
||||
printf("Próbujemy wypłacić 6769 złoty\n");
|
||||
|
||||
try {
|
||||
k.wyplac(6769);
|
||||
} catch (std::invalid_argument &ex) {
|
||||
printf("Nie wolno wypłacić aż tyle pieniędzy! %s", ex.what());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user