mirror of
https://github.com/szymon-jozef/ZUT-notatki.git
synced 2026-09-07 12:10:40 +02:00
kod
This commit is contained in:
17
uczelnia/2_semestr/programowanie/laby/lab3/zad10.cpp
Normal file
17
uczelnia/2_semestr/programowanie/laby/lab3/zad10.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include <iostream>
|
||||
|
||||
class Punkt {
|
||||
int x, y;
|
||||
|
||||
public:
|
||||
Punkt(int x, int y) : x(x), y(y) {}
|
||||
Punkt() : Punkt(0, 0) {}
|
||||
void pokaz() { std::cout << '(' << x << ',' << y << ')' << std::endl; }
|
||||
};
|
||||
|
||||
int main() {
|
||||
Punkt p;
|
||||
p.pokaz();
|
||||
Punkt p2(2, 2);
|
||||
p2.pokaz();
|
||||
}
|
||||
@@ -1,3 +1,32 @@
|
||||
#include <iostream>
|
||||
|
||||
int main() {}
|
||||
class Punkt {
|
||||
int x, y;
|
||||
|
||||
public:
|
||||
Punkt() {
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
|
||||
Punkt(int x, int y) {
|
||||
this->x = x;
|
||||
this->y = y;
|
||||
}
|
||||
|
||||
void pokaz() { std::cout << '(' << x << ',' << y << ')' << std::endl; }
|
||||
};
|
||||
|
||||
int main() {
|
||||
int x, y;
|
||||
std::cout << "Podaj x i y: ";
|
||||
std::cin >> x;
|
||||
std::cin >> y;
|
||||
Punkt p;
|
||||
std::cout << "Domyślny punkt: ";
|
||||
p.pokaz();
|
||||
std::cout << std::endl;
|
||||
std::cout << "Punkt z twoimi danymi: ";
|
||||
Punkt p2(x, y);
|
||||
p2.pokaz();
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
#include <iostream>
|
||||
|
||||
class Prostokat {
|
||||
private:
|
||||
int a;
|
||||
int b;
|
||||
|
||||
public:
|
||||
Prostokat() {} // dodany pusty konstruktor, by kod się skompilował
|
||||
Prostokat(int x, int y) : a(x), b(y) {}
|
||||
};
|
||||
Prostokat p1;
|
||||
|
||||
Prostokat p1; // w aktualnej formie się nie skompiluje, ponieważ nie istnieje
|
||||
// konstruktor bezargumentowy
|
||||
Prostokat p2(2, 3);
|
||||
Prostokat p3{4, 5};
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
class Samochod {
|
||||
private:
|
||||
@@ -6,10 +6,7 @@ private:
|
||||
int rok;
|
||||
|
||||
public:
|
||||
Samochod(std::string m, int r) {
|
||||
marka = m;
|
||||
rok = r;
|
||||
}
|
||||
Samochod(std::string m, int r) : marka(m), rok(r) {}
|
||||
};
|
||||
|
||||
int main() {}
|
||||
|
||||
@@ -1,3 +1,21 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
int main() {}
|
||||
class Produkt {
|
||||
std::string nazwa;
|
||||
float cena;
|
||||
|
||||
public:
|
||||
void ustawNazwe(std::string nazwa) { this->nazwa = nazwa; }
|
||||
void ustawCene(float cena) { this->cena = cena; }
|
||||
void pokaz() {
|
||||
std::cout << "Produkt " << nazwa << " kosztuje " << cena << " zł.";
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
Produkt p;
|
||||
p.ustawNazwe("Marchewka");
|
||||
p.ustawCene(234.342);
|
||||
p.pokaz();
|
||||
}
|
||||
|
||||
@@ -8,10 +8,11 @@ public:
|
||||
|
||||
int main() {
|
||||
std::cout << "Start" << std::endl;
|
||||
Test a;
|
||||
Test a; // konstruktor 1
|
||||
{
|
||||
Test b;
|
||||
Test b; // konstruktor 2
|
||||
std::cout << "Wewnatrz bloku" << std::endl;
|
||||
}
|
||||
} // destruktor 2
|
||||
std::cout << "Koniec" << std::endl;
|
||||
// destruktor 1
|
||||
}
|
||||
|
||||
@@ -1,3 +1,29 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
class Ksiazka {
|
||||
std::string tytul, autor;
|
||||
int rokWydania;
|
||||
|
||||
public:
|
||||
Ksiazka() {}
|
||||
|
||||
Ksiazka(std::string tytul, std::string autor, int rokWydania)
|
||||
: tytul(tytul), autor(autor), rokWydania(rokWydania) {}
|
||||
~Ksiazka() {
|
||||
std::cout << "Likwiduję książkę..." << std::endl;
|
||||
}
|
||||
|
||||
void pokaz() {
|
||||
std::cout << "Ksiażka " << tytul << " została napisana przez " << autor << " w " << rokWydania << " roku." << std::endl;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
Ksiazka pusta_ksiazka;
|
||||
pusta_ksiazka.pokaz();
|
||||
Ksiazka niepusta_ksiazka("Ksiazka", "Stefan", 2026);
|
||||
niepusta_ksiazka.pokaz();
|
||||
}
|
||||
|
||||
|
||||
int main() {}
|
||||
|
||||
@@ -1,3 +1,25 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
int main() {}
|
||||
class KontoBankowe {
|
||||
std::string wlasciciel;
|
||||
float saldo;
|
||||
|
||||
public:
|
||||
KontoBankowe(std::string wlasciciel, float saldo = 0.0)
|
||||
: wlasciciel(wlasciciel), saldo(saldo) {}
|
||||
~KontoBankowe() { std::cout << "Zamykam konto bankowe" << std::endl; }
|
||||
|
||||
void wplata(float pieniadze) { saldo += pieniadze; }
|
||||
void wyplata(float pieniadze) { saldo -= pieniadze; }
|
||||
void pokaz() { std::cout << wlasciciel << " ma " << saldo << " zł."; }
|
||||
};
|
||||
|
||||
int main() {
|
||||
KontoBankowe konto("bogdan");
|
||||
konto.pokaz();
|
||||
konto.wplata(23.3);
|
||||
konto.pokaz();
|
||||
konto.wyplata(2);
|
||||
konto.pokaz();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user