Website Summary Files Commits Branches @commit @diff @stats
path: root / Sem. 08
diff options
context:
space:
mode:
diff --git a/Sem. 08/Complex/Complex.cpp b/Sem. 08/Complex/Complex.cpp
deleted file mode 100644
index c604d0a..0000000
--- a/Sem. 08/Complex/Complex.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-#include "Complex.h"
-
-Complex::Complex()
-{
- real = 0;
- im = 0;
-}
-Complex::Complex(double real, double im)
-{
- this->real = real;
- this->im = im;
-}
-Complex& Complex::operator+=(const Complex& other)
-{
- real += other.real;
- im += other.im;
- return *this;
-}
-Complex& Complex::operator-=(const Complex& other)
-{
- real -= other.real;
- im -= other.im;
- return *this;
-}
-Complex& Complex::operator*=(const Complex& other)
-{
- int oldReal = real;
- real = real*other.real - im*other.im;
- im = oldReal*other.im + im * other.real;
- return *this;
-}
-Complex& Complex::operator/=(const Complex& other) // a/=b
-{
- Complex Conjugated = other.getConjugated(); //взимаме комплексно спрегнатата на другата дроб (b)
-
- Complex otherCopy(other);// копираме другата (b), за да не я промяняме.
-
- //Умножаваме двете по комплексно спрегнатата.
- *this *= Conjugated;
- otherCopy *= Conjugated; //Тук трябва да остане само реална част.
-
- if (otherCopy.real != 0)
- {
- real /= otherCopy.real;
- im /= otherCopy.real;
- }
-
- return *this;
-}
-
-
-//След дефинирането на +=, -=, *= и /=, можем лесно да дефинираме +, -, * и /, преизползвайки вече написаните опратори.
-Complex operator+(const Complex& lhs, const Complex& rhs) { //a+b
-
- Complex result(lhs); // Създаваме нов обект, който е копие на a (използваме копи-конструктора)
- result += rhs; //към копието на a, добавяме b (Използваме вече дефинирания оператор +=)
-
- return result;
-}
-//Операторите -, *, / са аналогични с +.
-Complex operator-(const Complex& lhs, const Complex& rhs) {
- Complex result(lhs);
- result -= rhs;
-
- return result;
-}
-
-Complex operator*(const Complex& lhs, const Complex& rhs) {
-
- Complex result(lhs);
- result *= rhs;
-
- return result;
-}
-
-Complex operator/(const Complex& lhs, const Complex& rhs) {
-
- Complex result(lhs);
- result /= rhs;
-
- return result;
-}
-
-Complex Complex::getConjugated() const
-{
- Complex result(*this);
- result.im *= -1;
-
- return result;
-}
-
-// за да можем да правим cout<<c1 или да запазваме във файл и др.
-std::ostream& operator<<(std::ostream& ofs, const Complex& r) {
-
- return ofs << r.real << ' ' << r.im << 'i';
-}
-
-// за да можем да правим cin>>c1 или да четем от файл и др.
-std::istream& operator>>(std::istream& ifs, Complex& r) {
-
- return ifs >> r.real >> r.im;
-}
diff --git a/Sem. 08/Complex/Complex.h b/Sem. 08/Complex/Complex.h
deleted file mode 100644
index d76a2f3..0000000
--- a/Sem. 08/Complex/Complex.h
+++ /dev/null
@@ -1,34 +0,0 @@
-#include <iostream>
-class Complex
-{
-private:
- double real;
- double im;
-
-public:
- Complex();
- Complex(double real, double im);
-
- Complex getConjugated() const; //връща комплексно спрегнатото число на текущия обект.
-
- //assignment operators
- // a+=b Към а се добавя стойността на b. а се променя , b не се. Операцията ще върне a за да може да се правят верижни изрази (a+=b+=c)
- Complex& operator+=(const Complex&);
- Complex& operator-=(const Complex&);
- Complex& operator*=(const Complex&);
- Complex& operator/=(const Complex&);
-
-
-
- //stream opeartors ( std::cout>> c1) (std::cin<<c1 )
- friend std::ostream& operator<<(std::ostream&, const Complex&);
- friend std::istream& operator>>(std::istream&, Complex&);
-
-};
-// a+b. Операторът връща НОВА променлива(Complex), която е резултатът от операцията.
-Complex operator+(const Complex&, const Complex&);
-Complex operator-(const Complex&, const Complex&);
-Complex operator*(const Complex&, const Complex&);
-Complex operator/(const Complex&, const Complex&);
-
-
diff --git a/Sem. 08/Complex/Source.cpp b/Sem. 08/Complex/Source.cpp
deleted file mode 100644
index 32f9e17..0000000
--- a/Sem. 08/Complex/Source.cpp
+++ /dev/null
@@ -1,9 +0,0 @@
-#include "Complex.h"
-
-int main()
-{
- Complex c(3, 4);
- Complex c2(3, 4);
-
- std::cout << c* c2;
-}
diff --git a/Sem. 08/Nvector/Nvector.cpp b/Sem. 08/Nvector/Nvector.cpp
deleted file mode 100644
index b4f983d..0000000
--- a/Sem. 08/Nvector/Nvector.cpp
+++ /dev/null
@@ -1,176 +0,0 @@
-#include "Nvector.h"
-
-Nvector::Nvector(size_t n) : size(n)
-{
- data = new int[n];
-
- for (int i = 0; i < n; i++)
- data[i] = 0;
-}
-
-Nvector::Nvector(const Nvector& other)
-{
- copyFrom(other);
-}
-
-Nvector& Nvector::operator=(const Nvector& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
-}
-Nvector::~Nvector()
-{
- free();
-}
-
-void Nvector::copyFrom(const Nvector& other)
-{
- size = other.size;
- data = new int[size];
-
- for (int i = 0; i < size; i++)
- data[i] = other.data[i];
-}
-void Nvector::free()
-{
- delete[] data;
- size = 0;
-}
-
-
-
-//v += v1;
-Nvector& Nvector::operator+=(const Nvector& other)
-{
- if (size != other.size)
- throw "The vectors should have the same size!";
-
- for (int i = 0; i < size; i++)
- data[i] += other.data[i];
-
- return *this;
-}
-
-Nvector& Nvector::operator-=(const Nvector& other)
-{
- if (size != other.size)
- throw "The vectors should have the same size!";
-
- for (int i = 0; i < size; i++)
- data[i] -= other.data[i];
-
- return *this;
-}
-
-const Nvector operator+(const Nvector& lhs, const Nvector& rhs)
-{
- Nvector lhsCopy(lhs);
- lhsCopy += rhs;
-
- return lhsCopy;
-}
-
-const Nvector operator-(const Nvector& lhs, const Nvector& rhs)
-{
- Nvector lhsCopy(lhs);
- lhsCopy -= rhs;
-
- return lhsCopy;
-}
-
-int& Nvector::operator[](size_t index)
-{
- if (index >= size)
- throw "Invalid index";
-
- return data[index];
-}
-
-int Nvector::operator[](size_t index) const
-{
- if (index >= size)
- throw "Invalid index";
-
- return data[index];
-}
-
-size_t Nvector::operator~() const
-{
- return size;
-}
-
-std::ostream& operator<<(std::ostream& os, const Nvector& v)
-{
- os << "[ ";
- for (int i = 0; i < v.size; i++)
- os << v[i] << " ";
- os << " ]";
-
- return os;
-}
-
-std::istream& operator>>(std::istream& is, Nvector& v)
-{
- for (int i = 0; i < v.size; i++)
- is >> v[i];
-
- return is;
-}
-
-bool operator||(const Nvector& lhs, const Nvector& rhs)
-{
- if (~lhs != ~rhs)
- return false;
-
- double coef = (double)lhs[0] / rhs[0];
-
- double eps = 0.01;
-
- for (int i = 1; i < ~lhs; i++)
- {
- double currCoef = (double)lhs[i] / rhs[i];
-
- if (abs(currCoef - coef) > eps)
- return false;
- }
- return true;
-}
-
-Nvector& Nvector::operator*=(size_t scalar)
-{
- for (int i = 0; i < size; i++)
- data[i] *= scalar;
-
- return *this;
-}
-
-const Nvector operator*(const Nvector& lhs, size_t scalar)
-{
- Nvector copy(lhs);
- copy *= scalar;
- return copy;
-}
-const Nvector operator*(size_t scalar, const Nvector& lhs)
-{
- return lhs * scalar;
-}
-size_t operator%(const Nvector& lhs, const Nvector& rhs)
-{
- if (~lhs != ~rhs)
- throw "The vectors should have the same size!";
-
- size_t res = 0;
- for (int i = 0; ~lhs; i++)
- res += lhs[i] * rhs[i];
-
- return res;
-}
-
-size_t operator|=(const Nvector& lhs, const Nvector& rhs)
-{
- return lhs % rhs == 0; //the size check is done by %
-} \ No newline at end of file
diff --git a/Sem. 08/Nvector/Nvector.h b/Sem. 08/Nvector/Nvector.h
deleted file mode 100644
index 745a844..0000000
--- a/Sem. 08/Nvector/Nvector.h
+++ /dev/null
@@ -1,52 +0,0 @@
-#pragma once
-#include <iostream>
-
-class Nvector
-{
-private:
- int* data;
- size_t size;
-
- void copyFrom(const Nvector& other);
- void free();
-
-public:
- Nvector(size_t size);
-
- Nvector(const Nvector& other);
- Nvector& operator=(const Nvector& other);
- ~Nvector();
-
- Nvector& operator+=(const Nvector& other);
- Nvector& operator-=(const Nvector& other);
-
- Nvector& operator*=(size_t scalar);
-
- int& operator[](size_t); //get set
-
- int operator[](size_t) const; // get
-
- void print();
-
- size_t operator~() const;//ize;
-
- friend std::ostream& operator<<(std::ostream& os, const Nvector& v);
- friend std::istream& operator>>(std::istream&, Nvector& v);
-};
-
-const Nvector operator+(const Nvector& lhs, const Nvector& rhs);
-const Nvector operator-(const Nvector& lhs, const Nvector& rhs);
-
-const Nvector operator*(const Nvector& lhs, size_t scalar);
-//So it could be commutative. Is there a better way?
-const Nvector operator*(size_t scalar, const Nvector& lhs);
-
-//are parallel
-bool operator||(const Nvector& lhs, const Nvector& rhs);
-
-
-//scalar product
-size_t operator%(const Nvector& lhs, const Nvector& rhs);
-
-//are perpendicular
-bool operator||(const Nvector& lhs, const Nvector& rhs); \ No newline at end of file
diff --git a/Sem. 08/Nvector/Source.cpp b/Sem. 08/Nvector/Source.cpp
deleted file mode 100644
index 291b683..0000000
--- a/Sem. 08/Nvector/Source.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#include <iostream>
-#include <fstream>
-#include "Nvector.h"
-
-using namespace std;
-
-
-
-int main()
-{
- Nvector v(3);
- v[2] = 10;
- Nvector v2 = 3 * v;
- cout << v2;
-
-}
-
diff --git a/Sem. 08/Nvector/TwoDimCoordSystem.cpp b/Sem. 08/Nvector/TwoDimCoordSystem.cpp
deleted file mode 100644
index e7a7072..0000000
--- a/Sem. 08/Nvector/TwoDimCoordSystem.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "TwoDimCoordSystem.h"
-
-TwoDimCoordSystem::TwoDimCoordSystem(const Nvector& v1, const Nvector& v2) : v1(v1), v2(v2)
-{
- if (~v1 != 2 || ~v2 != 2)
- throw "Size of vectors should be 2!";
- if (v1 || v2)
- throw "Vectors should not be parallel!";
-}
-
-Nvector TwoDimCoordSystem::getVectorByCoordinates(size_t coordX, size_t coordY) const
-{
- //todo
-}
-Nvector TwoDimCoordSystem::getCoordinatesByVector(const Nvector& other) const
-{
- //todo
-} \ No newline at end of file
diff --git a/Sem. 08/Nvector/TwoDimCoordSystem.h b/Sem. 08/Nvector/TwoDimCoordSystem.h
deleted file mode 100644
index a2fdbfe..0000000
--- a/Sem. 08/Nvector/TwoDimCoordSystem.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "Nvector.h"
-class TwoDimCoordSystem
-{
- Nvector v1;
- Nvector v2;
-
- TwoDimCoordSystem(const Nvector& v1, const Nvector& rhs);
-
- Nvector getVectorByCoordinates(size_t coordX, size_t coordY) const;
- Nvector getCoordinatesByVector(const Nvector& other) const;
-}; \ No newline at end of file
diff --git a/Sem. 08/README.md b/Sem. 08/README.md
deleted file mode 100644
index 41e40f4..0000000
--- a/Sem. 08/README.md
+++ /dev/null
@@ -1,161 +0,0 @@
-# Предефиниране на оператори. Приятелски класове и функции.
-## Oператори
-### Видове оператори.
-в C++ има два вида оператори:
-
- - Унарни (на един аргумент)
- - Бинарни (на два аргумента)
-
-
-### Операторите се характеризират с:
- - Приоритет
- - Асоциативност
- - Позиция на оператора спярмо аргумента - *префиксен*, *инфиксен* и *суфиксен*
-
-### Списъка на операторите в C++:
-| Оператор | Асоциативност |
-|------------------------------------------------|---------------------------------|
-| () [] -> . ++ - - | лявоасоциативен |
-| + - ! ~ ++ - - (type)* & sizeof | дясноасоциативен |
-| * / % | лявоасоциативен |
-| + - | лявоасоциативен|
-| << >> | лявоасоциативен|
-| < <= > >= | лявоасоциативен|
-| == != | лявоасоциативен|
-| & | лявоасоциативен |
-| ^ | лявоасоциативен |
-| \| | лявоасоциативен|
-| && | лявоасоциативен|
-| \|\| | лявоасоциативен|
-| ?: | дясноасоциативен |
-| = += -= *= /= %= >>= <<= &= ^= | дясноасоциативен |
-
-### Предефиниране на оператор (пример)
-```c++
-Complex& Complex::operator+=(const Complex& other)
-{
- real += other.real;
- im += other.im;
- return *this;
-}
- ```
-Вече може да правим следното:
-```c++
-ina main()
-{
- Complex c(1,3); //1 + 3i;
- Complex c2(10,20) // 10 + 2i;
- c += c2 // now c is 11 + 5i
-}
- ```
-При предефинирането на оператор **не могат** да се променят *приоритетът*, *асоциативността*, броят и позицията на *аргументите* му.
-
-## Приятелски класове и приятелски функции
-Декларират се с на запазената дума **friend** пред прототипа на функцията.
-Даденият friend-клас/фунцкия има достъп до всички компоненти на класа.
-Т.е. всички членове на класа са public за friend-класовете/функциите приятели.
-### Приятелски функции (пример)
-
- ```c++
-class Complex
-{
-
-private:
- double real;
- double im;
-public:
- friend double getModulos(const Complex& other);
- .
- .
- .
-}
- ```
- ```c++
-
-double getModulos(const Complex& other)
-{
- return sqrt((other.real – other.real) * (other.real – other.real) + (other.im – other.im ) * (other.im – other.im));
-}
-
-```
-## Задачи
-
-**Задача 1:**
-Реализирайте клас **Nvector**, който ще се използва за работа с математически вектор.
-Предефинирайте оператори със следната функционалност:
- - Събиране на вектори.
- - Изваждане на вектори.
- - Умножение на вектор със скалар.
- - Проверка дали два вектора са успоредни.
- - Проверка дали два вектора са перпендикулярни.
- - Взимане на дължина на вектор.
- - Достъп до произволен елемент на вектор.
- - Вход и изход от потоци.
-
- ```c++
-int main()
-{
- Nvector v(4);
- cin >> v;
-
- Nvector v2(4);
- cin >> v;
-
- Nvector result = v + v2;
-
- cout << result << endl;
-
-}
- ```
- Релизирайте клас двумерната декартова координатна система, която приема 2 вектора, които са нейният базис.
- Реализрайте следните функции:
- - Връща вектор в базиса по подадени 2 координата.
- - По подаден вектор връща координатите му в базиса.
-
- ```c++
-int main()
-{
- Nvector v(4);
- v[0] = 2;
- v[1] = 1;
-
- Nvector v2(4);
- v2[0] = 3;
- v2[1] = 1;
-
- twoDimCoordSystem s(v1, v2);
-
- cout << s1.getVectorByCoordinates(7, 4); // [26, 11]
-
- cout << s1.getCoordinatesByVector(7, 4); // [5, -1]
-
- cout << result << endl;
-
-}
- ```
-
- **Задача 2:**
-Реализирайте клас **Complex**, който ще се използва за работа с комплексни числа.
-Предефинирайте оператори със следната функционалност:
- - Събиране на комплексни числа.
- - Изваждане на комплексни числа.
- - Умножение на комплексни числа.
- - Деление на комплексни числа
- - Вход и изход от потоци.
-
-```c++
-
-
-int main()
-{
- Complex c;
- cin >> c;
-
- Complex c2;
- cin >> c2;
-
- Complex result = c2 / c;
-
- cout << result << endl;
-}
- ```