mirror of
https://github.com/szymon-jozef/ZUT-notatki.git
synced 2026-09-07 12:10:40 +02:00
blabla
This commit is contained in:
24
uczelnia/2_semestr/programowanie/laby/lab7/liczba.cpp
Normal file
24
uczelnia/2_semestr/programowanie/laby/lab7/liczba.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
class Liczba {
|
||||||
|
int wartosc;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Liczba(int w) : wartosc(w) {}
|
||||||
|
Liczba operator+(Liczba &inny) {
|
||||||
|
wartosc += inny.wartosc;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
friend std::ostream &operator<<(std::ostream &os, const Liczba &liczba) {
|
||||||
|
return os << liczba.wartosc;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Liczba l1 = Liczba(5);
|
||||||
|
Liczba l2 = Liczba(10);
|
||||||
|
Liczba l3 = l1 + l2;
|
||||||
|
std::cout << l3;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
BIN
uczelnia/2_semestr/programowanie/laby/lab7/out/1
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab7/out/1
Executable file
Binary file not shown.
BIN
uczelnia/2_semestr/programowanie/laby/lab7/out/liczba
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab7/out/liczba
Executable file
Binary file not shown.
BIN
uczelnia/2_semestr/programowanie/laby/lab7/out/ulamki
Executable file
BIN
uczelnia/2_semestr/programowanie/laby/lab7/out/ulamki
Executable file
Binary file not shown.
45
uczelnia/2_semestr/programowanie/laby/lab7/punkt.cpp
Normal file
45
uczelnia/2_semestr/programowanie/laby/lab7/punkt.cpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class Punkt2d {
|
||||||
|
|
||||||
|
public:
|
||||||
|
double x, y;
|
||||||
|
Punkt2d(double x, double y) : x(x), y(y) {}
|
||||||
|
Punkt2d() : x(0), y(0) {}
|
||||||
|
|
||||||
|
Punkt2d operator+(const Punkt2d &inny_pkt) const {
|
||||||
|
Punkt2d pkt;
|
||||||
|
pkt.x = x + inny_pkt.x;
|
||||||
|
pkt.y = y + inny_pkt.y;
|
||||||
|
return pkt;
|
||||||
|
}
|
||||||
|
|
||||||
|
Punkt2d operator-(const Punkt2d &inny_pkt) const {
|
||||||
|
Punkt2d pkt;
|
||||||
|
pkt.x = x - inny_pkt.x;
|
||||||
|
pkt.y = y - inny_pkt.y;
|
||||||
|
return pkt;
|
||||||
|
}
|
||||||
|
bool operator==(const Punkt2d &inny_pkt) const {
|
||||||
|
if (x != inny_pkt.x || y != inny_pkt.y) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool operator!=(const Punkt2d &inny_pkt) const {
|
||||||
|
return !(*this == inny_pkt);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend std::ostream &operator<<(std::ostream &os, const Punkt2d &inny_pkt) {
|
||||||
|
os << '(' << inny_pkt.x << ',' << inny_pkt.y << ')';
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Punkt2d a(6, 7), b(3, 4);
|
||||||
|
Punkt2d c = a + b;
|
||||||
|
std::cout << c << std::endl; // (9, 11)
|
||||||
|
std::cout << (a == b) << std::endl; // false
|
||||||
|
std::cout << (a != a) << std::endl; // false
|
||||||
|
}
|
||||||
115
uczelnia/2_semestr/programowanie/laby/lab7/ulamki.cpp
Normal file
115
uczelnia/2_semestr/programowanie/laby/lab7/ulamki.cpp
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
#include <ios>
|
||||||
|
#include <iostream>
|
||||||
|
#include <numeric>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
class Ulamek {
|
||||||
|
void skroc() {
|
||||||
|
int skracacz = std::gcd(licznik, mianownik);
|
||||||
|
if (mianownik < 0) {
|
||||||
|
licznik = -licznik;
|
||||||
|
mianownik = -mianownik;
|
||||||
|
}
|
||||||
|
licznik /= skracacz;
|
||||||
|
mianownik /= skracacz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
int licznik, mianownik;
|
||||||
|
|
||||||
|
Ulamek(int licznik, int mianownik) : licznik(licznik), mianownik(mianownik) {
|
||||||
|
if (mianownik == 0) {
|
||||||
|
throw std::invalid_argument("Mianownik nie moze byc zerem");
|
||||||
|
}
|
||||||
|
skroc();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ulamek() : licznik(0), mianownik(1) {}
|
||||||
|
|
||||||
|
Ulamek operator+(const Ulamek &inny_ulamek) const {
|
||||||
|
return Ulamek(licznik * inny_ulamek.mianownik +
|
||||||
|
inny_ulamek.licznik * mianownik,
|
||||||
|
mianownik * inny_ulamek.mianownik);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ulamek operator-(const Ulamek &inny_ulamek) const {
|
||||||
|
return Ulamek(licznik * inny_ulamek.mianownik -
|
||||||
|
inny_ulamek.licznik * mianownik,
|
||||||
|
mianownik * inny_ulamek.mianownik);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ulamek operator*(const Ulamek &inny_ulamek) const {
|
||||||
|
return Ulamek(licznik * inny_ulamek.licznik,
|
||||||
|
mianownik * inny_ulamek.mianownik);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ulamek operator/(const Ulamek &inny_ulamek) const {
|
||||||
|
if (inny_ulamek.licznik == 0) {
|
||||||
|
throw std::invalid_argument("Dzielenie przez zero");
|
||||||
|
}
|
||||||
|
return Ulamek(licznik * inny_ulamek.mianownik,
|
||||||
|
mianownik * inny_ulamek.licznik);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Ulamek &inny_ulamek) const {
|
||||||
|
return licznik == inny_ulamek.licznik && mianownik == inny_ulamek.mianownik;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const Ulamek &inny_ulamek) const {
|
||||||
|
return !(*this == inny_ulamek);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<(const Ulamek &inny_ulamek) const {
|
||||||
|
return licznik * inny_ulamek.mianownik < inny_ulamek.licznik * mianownik;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator>=(const Ulamek &inny_ulamek) const {
|
||||||
|
return !(*this < inny_ulamek);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<=(const Ulamek &inny_ulamek) const {
|
||||||
|
return *this == inny_ulamek || *this < inny_ulamek;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator>(const Ulamek &inny_ulamek) const {
|
||||||
|
return !(*this <= inny_ulamek);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend std::ostream &operator<<(std::ostream &os, const Ulamek &u) {
|
||||||
|
os << u.licznik << '/' << u.mianownik;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ulamek stworz_ulamek() {
|
||||||
|
int licznik, mianownik;
|
||||||
|
std::cout << "Podaj licznik: ";
|
||||||
|
std::cin >> licznik;
|
||||||
|
std::cout << "Podaj mianownik: ";
|
||||||
|
std::cin >> mianownik;
|
||||||
|
return Ulamek(licznik, mianownik);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Ulamek u1 = stworz_ulamek();
|
||||||
|
std::cout << "Ulamek 1: " << u1 << std::endl;
|
||||||
|
Ulamek u2 = stworz_ulamek();
|
||||||
|
std::cout << "Ulamek 2: " << u2 << std::endl;
|
||||||
|
std::cout << "=== OPERACJE ===" << std::endl;
|
||||||
|
std::cout << "Dodawanie: " << u1 + u2 << std::endl;
|
||||||
|
std::cout << "Odejmowanie: " << u1 - u2 << std::endl;
|
||||||
|
std::cout << "Mnożenie: " << u1 * u2 << std::endl;
|
||||||
|
try {
|
||||||
|
std::cout << "Dzielenie: " << u1 / u2 << std::endl;
|
||||||
|
} catch (const std::invalid_argument &e) {
|
||||||
|
std::cout << "Błąd: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << "=== PORÓWNYWANIE ===" << std::endl;
|
||||||
|
std::cout << std::boolalpha;
|
||||||
|
std::cout << u1 << " == " << u2 << ": " << (u1 == u2) << std::endl;
|
||||||
|
std::cout << u1 << " != " << u2 << ": " << (u1 != u2) << std::endl;
|
||||||
|
std::cout << u1 << " <= " << u2 << ": " << (u1 <= u2) << std::endl;
|
||||||
|
std::cout << u1 << " >= " << u2 << ": " << (u1 >= u2) << std::endl;
|
||||||
|
std::cout << u1 << " < " << u2 << ": " << (u1 < u2) << std::endl;
|
||||||
|
std::cout << u1 << " > " << u2 << ": " << (u1 > u2) << std::endl;
|
||||||
|
}
|
||||||
24
uczelnia/2_semestr/programowanie/laby/lab8/liczba.cpp
Normal file
24
uczelnia/2_semestr/programowanie/laby/lab8/liczba.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
class Liczba {
|
||||||
|
int wartosc;
|
||||||
|
|
||||||
|
public:
|
||||||
|
Liczba(int w) : wartosc(w) {}
|
||||||
|
Liczba operator+(Liczba &inny) {
|
||||||
|
wartosc += inny.wartosc;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
friend std::ostream &operator<<(std::ostream &os, const Liczba &liczba) {
|
||||||
|
return os << liczba.wartosc;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Liczba l1 = Liczba(5);
|
||||||
|
Liczba l2 = Liczba(10);
|
||||||
|
Liczba l3 = l1 + l2;
|
||||||
|
std::cout << l3;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
62
uczelnia/2_semestr/programowanie/laby/lab8/punkt.cpp
Normal file
62
uczelnia/2_semestr/programowanie/laby/lab8/punkt.cpp
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class Punkt2d {
|
||||||
|
|
||||||
|
public:
|
||||||
|
double x, y;
|
||||||
|
Punkt2d(double x, double y) : x(x), y(y) {}
|
||||||
|
Punkt2d() : x(0), y(0) {}
|
||||||
|
|
||||||
|
Punkt2d operator+=(const Punkt2d &inny_pkt) {
|
||||||
|
this->x += inny_pkt.x;
|
||||||
|
this->y += inny_pkt.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Punkt2d operator-=(const Punkt2d &inny_pkt) {
|
||||||
|
this->x -= inny_pkt.x;
|
||||||
|
this->y -= inny_pkt.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Punkt2d operator*=(const Punkt2d &inny_pkt) {
|
||||||
|
this->x *= inny_pkt.x;
|
||||||
|
this->y *= inny_pkt.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
Punkt2d operator+(const Punkt2d &inny_pkt) const {
|
||||||
|
Punkt2d p = *this;
|
||||||
|
p += inny_pkt;
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
Punkt2d operator-(const Punkt2d &inny_pkt) const {
|
||||||
|
Punkt2d pkt;
|
||||||
|
pkt.x = x - inny_pkt.x;
|
||||||
|
pkt.y = y - inny_pkt.y;
|
||||||
|
return pkt;
|
||||||
|
}
|
||||||
|
bool operator==(const Punkt2d &inny_pkt) const {
|
||||||
|
if (x != inny_pkt.x || y != inny_pkt.y) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
bool operator!=(const Punkt2d &inny_pkt) const {
|
||||||
|
return !(*this == inny_pkt);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend std::ostream &operator<<(std::ostream &os, const Punkt2d &inny_pkt) {
|
||||||
|
os << '(' << inny_pkt.x << ',' << inny_pkt.y << ')';
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Punkt2d a(6, 7), b(3, 4);
|
||||||
|
Punkt2d c = a + b;
|
||||||
|
std::cout << c << std::endl; // (9, 11)
|
||||||
|
std::cout << (a == b) << std::endl; // false
|
||||||
|
std::cout << (a != a) << std::endl; // false
|
||||||
|
}
|
||||||
115
uczelnia/2_semestr/programowanie/laby/lab8/ulamki.cpp
Normal file
115
uczelnia/2_semestr/programowanie/laby/lab8/ulamki.cpp
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
#include <ios>
|
||||||
|
#include <iostream>
|
||||||
|
#include <numeric>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
class Ulamek {
|
||||||
|
void skroc() {
|
||||||
|
int skracacz = std::gcd(licznik, mianownik);
|
||||||
|
if (mianownik < 0) {
|
||||||
|
licznik = -licznik;
|
||||||
|
mianownik = -mianownik;
|
||||||
|
}
|
||||||
|
licznik /= skracacz;
|
||||||
|
mianownik /= skracacz;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
int licznik, mianownik;
|
||||||
|
|
||||||
|
Ulamek(int licznik, int mianownik) : licznik(licznik), mianownik(mianownik) {
|
||||||
|
if (mianownik == 0) {
|
||||||
|
throw std::invalid_argument("Mianownik nie moze byc zerem");
|
||||||
|
}
|
||||||
|
skroc();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ulamek() : licznik(0), mianownik(1) {}
|
||||||
|
|
||||||
|
Ulamek operator+(const Ulamek &inny_ulamek) const {
|
||||||
|
return Ulamek(licznik * inny_ulamek.mianownik +
|
||||||
|
inny_ulamek.licznik * mianownik,
|
||||||
|
mianownik * inny_ulamek.mianownik);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ulamek operator-(const Ulamek &inny_ulamek) const {
|
||||||
|
return Ulamek(licznik * inny_ulamek.mianownik -
|
||||||
|
inny_ulamek.licznik * mianownik,
|
||||||
|
mianownik * inny_ulamek.mianownik);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ulamek operator*(const Ulamek &inny_ulamek) const {
|
||||||
|
return Ulamek(licznik * inny_ulamek.licznik,
|
||||||
|
mianownik * inny_ulamek.mianownik);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ulamek operator/(const Ulamek &inny_ulamek) const {
|
||||||
|
if (inny_ulamek.licznik == 0) {
|
||||||
|
throw std::invalid_argument("Dzielenie przez zero");
|
||||||
|
}
|
||||||
|
return Ulamek(licznik * inny_ulamek.mianownik,
|
||||||
|
mianownik * inny_ulamek.licznik);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const Ulamek &inny_ulamek) const {
|
||||||
|
return licznik == inny_ulamek.licznik && mianownik == inny_ulamek.mianownik;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator!=(const Ulamek &inny_ulamek) const {
|
||||||
|
return !(*this == inny_ulamek);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<(const Ulamek &inny_ulamek) const {
|
||||||
|
return licznik * inny_ulamek.mianownik < inny_ulamek.licznik * mianownik;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator>=(const Ulamek &inny_ulamek) const {
|
||||||
|
return !(*this < inny_ulamek);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator<=(const Ulamek &inny_ulamek) const {
|
||||||
|
return *this == inny_ulamek || *this < inny_ulamek;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator>(const Ulamek &inny_ulamek) const {
|
||||||
|
return !(*this <= inny_ulamek);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend std::ostream &operator<<(std::ostream &os, const Ulamek &u) {
|
||||||
|
os << u.licznik << '/' << u.mianownik;
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ulamek stworz_ulamek() {
|
||||||
|
int licznik, mianownik;
|
||||||
|
std::cout << "Podaj licznik: ";
|
||||||
|
std::cin >> licznik;
|
||||||
|
std::cout << "Podaj mianownik: ";
|
||||||
|
std::cin >> mianownik;
|
||||||
|
return Ulamek(licznik, mianownik);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
Ulamek u1 = stworz_ulamek();
|
||||||
|
std::cout << "Ulamek 1: " << u1 << std::endl;
|
||||||
|
Ulamek u2 = stworz_ulamek();
|
||||||
|
std::cout << "Ulamek 2: " << u2 << std::endl;
|
||||||
|
std::cout << "=== OPERACJE ===" << std::endl;
|
||||||
|
std::cout << "Dodawanie: " << u1 + u2 << std::endl;
|
||||||
|
std::cout << "Odejmowanie: " << u1 - u2 << std::endl;
|
||||||
|
std::cout << "Mnożenie: " << u1 * u2 << std::endl;
|
||||||
|
try {
|
||||||
|
std::cout << "Dzielenie: " << u1 / u2 << std::endl;
|
||||||
|
} catch (const std::invalid_argument &e) {
|
||||||
|
std::cout << "Błąd: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
std::cout << "=== PORÓWNYWANIE ===" << std::endl;
|
||||||
|
std::cout << std::boolalpha;
|
||||||
|
std::cout << u1 << " == " << u2 << ": " << (u1 == u2) << std::endl;
|
||||||
|
std::cout << u1 << " != " << u2 << ": " << (u1 != u2) << std::endl;
|
||||||
|
std::cout << u1 << " <= " << u2 << ": " << (u1 <= u2) << std::endl;
|
||||||
|
std::cout << u1 << " >= " << u2 << ": " << (u1 >= u2) << std::endl;
|
||||||
|
std::cout << u1 << " < " << u2 << ": " << (u1 < u2) << std::endl;
|
||||||
|
std::cout << u1 << " > " << u2 << ": " << (u1 > u2) << std::endl;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user