Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
134 files changed, 1 insertions, 6723 deletions
-rw-r--r--README.md20
-rw-r--r--Sem. 01/README.md55
-rw-r--r--Sem. 01/notes_1.pdfbin113291 -> 0 bytes
-rw-r--r--Sem. 01/task1.cpp37
-rw-r--r--Sem. 01/task1/task1.cpp126
-rw-r--r--Sem. 02/README.md137
-rw-r--r--Sem. 02/notes_02.pdfbin75732 -> 0 bytes
-rw-r--r--Sem. 02/task1/selfPrintingTask.cpp26
-rw-r--r--Sem. 02/task2/students.csv10
-rw-r--r--Sem. 02/task2/studentsDatabase.cpp253
-rw-r--r--Sem. 03/README.md129
-rw-r--r--Sem. 03/binaryFileExample.cpp0
-rw-r--r--Sem. 03/notes_03.pdfbin122659 -> 0 bytes
-rw-r--r--Sem. 03/sizeFile.cpp27
-rw-r--r--Sem. 04/README.md238
-rw-r--r--Sem. 04/task1/uni-task.cpp378
-rw-r--r--Sem. 05/Interval/Interval.cpp133
-rw-r--r--Sem. 05/Interval/Interval.h32
-rw-r--r--Sem. 05/Interval/Source.cpp15
-rw-r--r--Sem. 05/README.md218
-rw-r--r--Sem. 06/README.md166
-rw-r--r--Sem. 06/Time/Source.cpp14
-rw-r--r--Sem. 06/Time/Time.cpp78
-rw-r--r--Sem. 06/Time/Time.h27
-rw-r--r--Sem. 07/Person/Person.cpp40
-rw-r--r--Sem. 07/Person/Person.h19
-rw-r--r--Sem. 07/Person/Source.cpp16
-rw-r--r--Sem. 07/PersonAdvanced/PersonAdvanced.cpp69
-rw-r--r--Sem. 07/PersonAdvanced/PersonAdvanced.h28
-rw-r--r--Sem. 07/PersonAdvanced/Source.cpp16
-rw-r--r--Sem. 07/README.md121
-rw-r--r--Sem. 08/Complex/Complex.cpp102
-rw-r--r--Sem. 08/Complex/Complex.h34
-rw-r--r--Sem. 08/Complex/Source.cpp9
-rw-r--r--Sem. 08/Nvector/Nvector.cpp176
-rw-r--r--Sem. 08/Nvector/Nvector.h52
-rw-r--r--Sem. 08/Nvector/Source.cpp17
-rw-r--r--Sem. 08/Nvector/TwoDimCoordSystem.cpp18
-rw-r--r--Sem. 08/Nvector/TwoDimCoordSystem.h11
-rw-r--r--Sem. 08/README.md161
-rw-r--r--Sem. 09/README.md230
-rw-r--r--Sem. 09/task1 (not finished)/Grade.cpp69
-rw-r--r--Sem. 09/task1 (not finished)/Grade.h26
-rw-r--r--Sem. 09/task1 (not finished)/Student.cpp45
-rw-r--r--Sem. 09/task1 (not finished)/Student.h29
-rw-r--r--Sem. 09/task1 (not finished)/UniCourse.cpp135
-rw-r--r--Sem. 09/task1 (not finished)/UniCourse.h35
-rw-r--r--Sem. 09/task1 (not finished)/main.cpp15
-rw-r--r--Sem. 10/README.md70
-rw-r--r--Sem. 10/task1/Queue.hpp144
-rw-r--r--Sem. 10/task1/main.cpp23
-rw-r--r--Sem. 11/README.md129
-rw-r--r--Sem. 11/example/Person.cpp99
-rw-r--r--Sem. 11/example/Person.h35
-rw-r--r--Sem. 11/example/main.cpp17
-rw-r--r--Sem. 12/README.md190
-rw-r--r--Sem. 12/task1/Bar/Bar.cpp45
-rw-r--r--Sem. 12/task1/Bar/Bar.h36
-rw-r--r--Sem. 12/task1/Drinks/AlcoholDrink.cpp24
-rw-r--r--Sem. 12/task1/Drinks/AlcoholDrink.h15
-rw-r--r--Sem. 12/task1/Drinks/Drink.cpp69
-rw-r--r--Sem. 12/task1/Drinks/Drink.h27
-rw-r--r--Sem. 12/task1/Drinks/EnergyDrink.cpp49
-rw-r--r--Sem. 12/task1/Drinks/EnergyDrink.h22
-rw-r--r--Sem. 12/task1/Queue/Queue.hpp145
-rw-r--r--Sem. 12/task1/main.cpp30
-rw-r--r--Sem. 13/Figures/Circle.cpp16
-rw-r--r--Sem. 13/Figures/Circle.h14
-rw-r--r--Sem. 13/Figures/Rectangle.cpp26
-rw-r--r--Sem. 13/Figures/Rectangle.h10
-rw-r--r--Sem. 13/Figures/Shape.cpp52
-rw-r--r--Sem. 13/Figures/Shape.h41
-rw-r--r--Sem. 13/Figures/Triangle.cpp24
-rw-r--r--Sem. 13/Figures/Triangle.h12
-rw-r--r--Sem. 13/Figures/main.cpp36
-rw-r--r--Sem. 13/README.md198
-rw-r--r--Sem. 14/Collection/ShapesCollection.cpp67
-rw-r--r--Sem. 14/Collection/ShapesCollection.h35
-rw-r--r--Sem. 14/README.md157
-rw-r--r--Sem. 14/Shapes/Circle.cpp22
-rw-r--r--Sem. 14/Shapes/Circle.h15
-rw-r--r--Sem. 14/Shapes/Rectangle.cpp32
-rw-r--r--Sem. 14/Shapes/Rectangle.h13
-rw-r--r--Sem. 14/Shapes/Rhombus.cpp25
-rw-r--r--Sem. 14/Shapes/Rhombus.h12
-rw-r--r--Sem. 14/Shapes/Shape.cpp52
-rw-r--r--Sem. 14/Shapes/Shape.h43
-rw-r--r--Sem. 14/Shapes/Square.cpp19
-rw-r--r--Sem. 14/Shapes/Square.h13
-rw-r--r--Sem. 14/Shapes/Triangle.cpp30
-rw-r--r--Sem. 14/Shapes/Triangle.h14
-rw-r--r--Sem. 14/main.cpp16
-rw-r--r--Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.cpp69
-rw-r--r--Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.h43
-rw-r--r--Sem. 15/Chess_basic_prototype/ConfigEnums/ConfigEnums.h11
-rw-r--r--Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.cpp27
-rw-r--r--Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.h9
-rw-r--r--Sem. 15/Chess_basic_prototype/Figures/Bishop/Bishop.cpp16
-rw-r--r--Sem. 15/Chess_basic_prototype/Figures/Bishop/Bishop.h13
-rw-r--r--Sem. 15/Chess_basic_prototype/Figures/FigureBase/Figure.cpp0
-rw-r--r--Sem. 15/Chess_basic_prototype/Figures/FigureBase/Figure.h21
-rw-r--r--Sem. 15/Chess_basic_prototype/Figures/King/King.cpp16
-rw-r--r--Sem. 15/Chess_basic_prototype/Figures/King/King.h11
-rw-r--r--Sem. 15/Chess_basic_prototype/Figures/Knight/Knight.cpp26
-rw-r--r--Sem. 15/Chess_basic_prototype/Figures/Knight/Knight.h11
-rw-r--r--Sem. 15/Chess_basic_prototype/Figures/Pawn/Pawn.cpp20
-rw-r--r--Sem. 15/Chess_basic_prototype/Figures/Pawn/Pawn.h11
-rw-r--r--Sem. 15/Chess_basic_prototype/Figures/Queen/Queen.cpp18
-rw-r--r--Sem. 15/Chess_basic_prototype/Figures/Queen/Queen.h11
-rw-r--r--Sem. 15/Chess_basic_prototype/Figures/Rook/Rook.cpp15
-rw-r--r--Sem. 15/Chess_basic_prototype/Figures/Rook/Rook.h11
-rw-r--r--Sem. 15/Chess_basic_prototype/main.cpp16
-rw-r--r--Sem. 15/README.md1
-rw-r--r--Sem. 16/LogicExpressions/LogicExpressions/LogicExpr.h150
-rw-r--r--Sem. 16/LogicExpressions/Source.cpp15
-rw-r--r--Sem. 16/README.md1
-rw-r--r--Utills/KN_exams_poll/README.md15
-rw-r--r--Utills/KN_exams_poll/poll.txt1
-rw-r--r--Utills/KN_exams_poll/schedule.md8
-rw-r--r--Utills/si_14.06/task1/Optional/Optional.hpp109
-rw-r--r--Utills/si_14.06/task1/Source.cpp17
-rw-r--r--Utills/si_14.06/task2/Source.cpp14
-rw-r--r--Utills/si_14.06/task2/ValueArray/ValueArray.cpp72
-rw-r--r--Utills/si_14.06/task2/ValueArray/ValueArray.h26
-rw-r--r--Utills/si_14.06/task2/Values/Date/Date.cpp19
-rw-r--r--Utills/si_14.06/task2/Values/Date/Date.h22
-rw-r--r--Utills/si_14.06/task2/Values/DateTime/DateTime.cpp14
-rw-r--r--Utills/si_14.06/task2/Values/DateTime/DateTime.h14
-rw-r--r--Utills/si_14.06/task2/Values/String/StringValue.cpp14
-rw-r--r--Utills/si_14.06/task2/Values/String/StringValue.h15
-rw-r--r--Utills/si_14.06/task2/Values/Time/Time.cpp19
-rw-r--r--Utills/si_14.06/task2/Values/Time/Time.h19
-rw-r--r--Utills/si_14.06/task2/Values/ValueBase/Value.cpp11
-rw-r--r--Utills/si_14.06/task2/Values/ValueBase/Value.h18
diff --git a/README.md b/README.md
index be7ccf1..990383e 100644
--- a/README.md
+++ b/README.md
@@ -1,20 +1,2 @@
-### Код от семинарите по ООП - спец. Компютърни науки - летен семестър 2020/2021
+### Код от семинарите по ООП - спец. Компютърни науки и спец. Софтуерно инженерството
-
-
- - **Тема 1:** Структури. Декалрация и използване на структури. Предговор на някои теми от УП (динамична памет, сортировки).
- - **Тема 2:** Потоци и текстови файлове. Писане и четене в **текстов файл**.
- - **Тема 3:** Потоци и двоични файлове. Състояние на поток. Писане и четене в **двоични файлове**.
- - **Тема 4:** Структури. Размер на обекти. **Подравняване**. Работа с **обекти, динамична памет и двоични файлове**.
- - **Тема 5:** Член-функции. Жизнен цикъл на обект. Конструктори и деструктор. **Капсулация**. Модификатори за достъп. Член-функции **get** и **set**.
- - **Тема 6:** Разделна компилация. **Абстракция**. Копиращ конструктор и оператор=
- - **Тема 7:** Динамична памет в класовете. Голямата четворка (**Rule of four**).
- - **Тема 8:** Предефиниране на оператори. Приятелски класове и функции.
- - **Тема 9:** **Композиция** на обекти. Масиви от обекти. **has-a** взаимотношения.
- - **Тема 10:** Шаблони. Реализация на шаблонен клас.
- - **Тема 11:** Move семантики.
- - **Тема 12:** Наследяване. **is-a** взаимотношения.
- - **Тема 13:** Статично и динамично свързване. Виртуални функции. **Полиморфизъм**. Абстрактни класове.
- - **Тема 14:** Колекции от обекти в **полиморфна йерархия**. Копиране и триене.
- - **Тема 15:** Factory pattern. Полиморифизъм. Преобразуване на указател от базов клас до указател от клас-наследник.
- - **Тема 16:** Дървовидна структура от обекти от полиморфна йерархия.
diff --git a/Sem. 01/README.md b/Sem. 01/README.md
deleted file mode 100644
index e61f925..0000000
--- a/Sem. 01/README.md
+++ /dev/null
@@ -1,55 +0,0 @@
-
-
-## Структури
-
-Структурите в C++ се използват за групиране на елементи. Елементите, наричани още членове, могат да бъдат от различен тип и с различна дължина.
- ```c++
-struct Box
-{
- int height;
- int weight;
-}
- ```
-
-### Деклариране на обекти от новия тип
- ```c++
-Box b; //default values to height and weight
-
-Box b2 = {3, 4} // height = 3, weight = 3;
-
-Box b3;
-b3.height = 13;
-b3.weight = 14;
- ```
-
-### Подаване във функции
-Ако няма да променяме обекта го подаваме по **константна референция.**
- ```c++
-int calculcateArea(const Box& b)
-{
- return b.height * b.weight;
-}
-```
- Може и само по **референция**, но тогава промените ще се отразят върху подадения аргумент.
-
- ```c++
-void readBox(Box& b)
-{
- cin >> b.height >> b.weight;
-}
- ```
-Може и да го подаваме по **копие**.
- ```c++
-Box revertBox(Box b)
-{
- int temp = b.height;
- b.height = b.weight;
- b.weight = temp;
-
- return b;
-}
-```
-### Задачи
-
-**Задача 1:** Въвежда се цяло число **N** и после **N** тригъгълника в равнината, определени от 3 точки ( 6 координати).
-Отпечатайте тригълниците **сортирани по лицата им.**
diff --git a/Sem. 01/notes_1.pdf b/Sem. 01/notes_1.pdf
deleted file mode 100644
index 6110f89..0000000
--- a/Sem. 01/notes_1.pdf
+++ /dev/null
Binary files differ
diff --git a/Sem. 01/task1.cpp b/Sem. 01/task1.cpp
deleted file mode 100644
index e6f4661..0000000
--- a/Sem. 01/task1.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <iostream>
-#include <chrono>
-
-using namespace std;
-
-bool checkIfObratim(size_t element, size_t Z)
-{
- for (int i = 1; i < Z; i++)
- {
- if ((i * element) % Z == 0)
- {
- std::cout << "Obratniq element na " << element << " e " << i << std::endl;
- return true;
- }
- }
- return false;
-}
-size_t countDivisers(size_t Z)
-{
- size_t count = 0;
- for (int i = 1; i < Z; i++)
- {
- if (checkIfObratim(i,Z))
- count++;
- else
- {
- std::cout << "Neobratim " << i << std::endl;
- }
- }
- return count;
-}
-int main()
-{
-
- cout << countDivisers(4096) << endl;
-
-}
diff --git a/Sem. 01/task1/task1.cpp b/Sem. 01/task1/task1.cpp
deleted file mode 100644
index 67ad5b1..0000000
--- a/Sem. 01/task1/task1.cpp
+++ /dev/null
@@ -1,126 +0,0 @@
-#include <iostream>
-#include <chrono>
-
-using namespace std;
-
-
-struct point
-{
- int x;
- int y;
-};
-void print(const point& ptr)
-{
- cout << ptr.x << " " << ptr.y << endl;
-}
-point readPoint()
-{
- int x, y;
- cin >> x >> y;
- return{ x, y };
-}
-double getDist(const point& origin, const point& dest)
-{
- double dx = origin.x - dest.x;
- double dy = origin.y - dest.y;
-
- return sqrt(dx*dx + dy*dy);
-}
-
-
-struct triangle
-{
- point p1;
- point p2;
- point p3;
-};
-
-double getArea(const triangle& tr)
-{
- double sideA = getDist(tr.p1, tr.p2);
- double sideB = getDist(tr.p2, tr.p3);
- double sideC = getDist(tr.p3, tr.p1);
-
- double halfP = (sideA + sideB + sideC) / 2;
- return sqrt(halfP * (halfP - sideA) * (halfP - sideB) * (halfP - sideC));
-
-}
-
-void print(const triangle& tr)
-{
- cout << "Point1: ";
- print(tr.p1);
- cout << "Point2: ";
- print(tr.p2);
- cout << "Point3: ";
- print(tr.p3);
- cout << getArea(tr) << endl << endl;
-}
-
-void swap(int * arr, int i, int j)
-{
- int temp = arr[i];
- arr[i] = arr[j];
- arr[j] = temp;
-}
-void swap(triangle* arr, int i, int j)
-{
- triangle temp = arr[i];
- arr[i] = arr[j];
- arr[j] = temp;
-}
-void selectionSort(int* areas, triangle* triangles, int len)
-{
- for (int i = 0; i < len-1; i++)
- {
- int currPos = i;
- int min = i;
-
- for (int j = i; j < len; j++)
- {
- if (areas[j] < areas[min])
- min = j;
- }
-
- if (min != i)
- {
- swap(areas, i, min);
- swap(triangles, i, min);
- }
- }
-}
-int main()
-{
-
-
- int n;
- cin >> n;
-
- triangle* triangles = new triangle[n];
-
- for (int i = 0; i < n; i++)
- {
- point p1 = readPoint();
- point p2 = readPoint();
- point p3 = readPoint();
-
- triangles[i].p1 = p1;
- triangles[i].p2 = p2;
- triangles[i].p3 = p3;
- }
-
- int* areas = new int[n];
-
-
- for (int i = 0; i < n; i++)
- areas[i] = getArea(triangles[i]);
-
- selectionSort(areas, triangles, n);
-
- for (int i = 0; i < n; i++)
- print(triangles[i]);
-
- delete[] triangles;
- delete[] areas;
-
-}
diff --git a/Sem. 02/README.md b/Sem. 02/README.md
deleted file mode 100644
index 1a4c845..0000000
--- a/Sem. 02/README.md
+++ /dev/null
@@ -1,137 +0,0 @@
-## Файлове (част 1). Текстови файлове.
-Видове потоци:
- - Потоци за вход (istream).
- - Потоци за изход (ostream).
-
-##### Пример за работа с поток за вход (cin)
- ```c++
-#include <iostream>
-using namespace std;
-
-int main()
-{
- int a, b;
- cin >> a >> b;
-}
- ```
- Четем от стандартния вход.
-
-##### Пример за работа с поток за изход (cout)
- ```c++
-#include <iostream>
-using namespace std;
-
-int main()
-{
- int a = 10;
- int b = 12;
- int c = a + b;
-
- cout << a << " + " << b << " = " << c << endl;
-}
- ```
-
-### Работа с поток за вход от файл (ifstream)
-Пример за четене от файл!
- ```c++
-#include <iostream>
-#include <fstream>
-using namespace std;
-
-int main()
-{
- ifstream file("myFile.txt");
-
- if (!file.is_open())
- {
- cout << "Error!" << endl;
- return -1;
- }
- int a, b;
-
- file >> a >> b;
-
- file.close();
-}
-```
-Пример за прочитане на цялото съдържание файл:
- ```c++
-#include <iostream>
-#include <fstream>
-using namespace std;
-
-const int BUFF_SIZE = 1024;
-int main()
-{
- ifstream file("myFile.txt");
-
- if (!file.is_open())
- {
- cout << "Error!" << endl;
- return -1;
- }
- while (!file.eof())
- {
- char buff[BUFF_SIZE];
- file.getline(buff, BUFF_SIZE);
-
- //do something with the line
- cout << line << endl;
- }
- file.close();
-}
-```
-### Работа с поток за изход към файл (ofstream)
-
- ```c++
-#include <iostream>
-#include <fstream>
-
-using namespace std;
-
-int main()
-{
- ofstream file("myFile.txt");
-
- if (!file.is_open())
- {
- cout << "Error!" << endl;
- return -1;
- }
- int a = 3;
- int b = 10;
-
- file << a << " " << b << " " << a + b << endl;
-
- if(!file.eof()) //check if the file has ended
- cout << "The file contains more data after the two integers!" << endl;
-
- file.close();
-}
- ```
- ## Задачи
-
-**Задача 1**: Напишете програма, която отпечатва собствения си код.
-
-**Задача 2**: Напишете програма, която чете comma-separated values (**CSV**) файл със студенти **със следните 4 полета**: Първо име, Фамилно име, Имейл, Факултетен номер.
-1. Със стартирането на програмата потребителят да въвежда име на файл, който да бъде зареден в паметта.
-2. Напишете функция, която след зареждане на файла да отпечатва на **стандартния изход** информация за студента при подаден **факултетен номер**.
-3. Напишете функция, която **по подаден факултетен номер и низ**, променя първото име на студента, който има дадения факултетен номер, с подадения низ.
-4. Напишете функцията , която приема низ (име на файл) и запазва студентите в същия формат (**CSV**). Т.е. при повторно пускане на програмата да може да прочете новия генериран файл.
-
-Да се реализира прост интерфейс, с който да се извикват написаните фунцкии през конзолата:
-
-**Пример** (входът от потребителя започва с '>'):
-
- ```
-Open file:
->students.csv
-File successfully opened!
->print 80000
-Name = Stefan Velkov, Email: stefan@yahoo.com, FN: 80000
->edit 80000 Krum
->print 80000
-Name = Krum Velkov, Email: stefan@yahoo.com, FN: 80000
->save students2.csv
-file students2.csv successfully saved!
-```
diff --git a/Sem. 02/notes_02.pdf b/Sem. 02/notes_02.pdf
deleted file mode 100644
index a7372af..0000000
--- a/Sem. 02/notes_02.pdf
+++ /dev/null
Binary files differ
diff --git a/Sem. 02/task1/selfPrintingTask.cpp b/Sem. 02/task1/selfPrintingTask.cpp
deleted file mode 100644
index 862cf07..0000000
--- a/Sem. 02/task1/selfPrintingTask.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include <iostream>
-#include <fstream>
-
-using namespace std;
-
-const int MAX_SIZE = 1024;
-int main()
-{
- ifstream inputFile("selfPrintingTask.cpp");
-
- if (inputFile.fail())
- {
- cout << "Error!" << endl;
- return -1;
- }
-
- while (!inputFile.eof())
- {
- char buff[MAX_SIZE];
- inputFile.getline(buff, MAX_SIZE);
- cout << buff << endl;
- }
- inputFile.close()
-
- return 0;
-}
diff --git a/Sem. 02/task2/students.csv b/Sem. 02/task2/students.csv
deleted file mode 100644
index 1d7debc..0000000
--- a/Sem. 02/task2/students.csv
+++ /dev/null
@@ -1,10 +0,0 @@
-Име,Фамилия,"Имейл адрес","Факултетен номер"
-Peter,Ivanov,peter@mail.bg,81235
-Alexander,Popov,popov@abv.bg,81234
-Stefan,Velikov,velikov@mail.bg,81876
-Krasimir,Petkov,krasi@abv.bg,81234
-Stefani,Angelova,stef@gmail.com,81876
-Ivana,Marinova,ivana@abv.bg,81321
-Stefan,Velkov,stefan@yahoo.com,80000
-Krasimira,Markova,krasi@mail.bg,81234
-Wladimir,Klitschko,wlad@kiev.com,89999 \ No newline at end of file
diff --git a/Sem. 02/task2/studentsDatabase.cpp b/Sem. 02/task2/studentsDatabase.cpp
deleted file mode 100644
index 7f9a5f5..0000000
--- a/Sem. 02/task2/studentsDatabase.cpp
+++ /dev/null
@@ -1,253 +0,0 @@
-#include <iostream>
-#include <fstream>
-
-using namespace std;
-
-const int FIELD_MAX_SIZE = 50;
-const int BUFFER_LINE_SIZE = 1024;
-
-struct OOPstudent
-{
- char firstName[FIELD_MAX_SIZE];
- char lastName[FIELD_MAX_SIZE];
- char email[FIELD_MAX_SIZE];
- int fn = 0;
-
-};
-
-int countLines(const char* fileName)
-{
- ifstream f(fileName);
- if (!f.is_open())
- return -1;
- int linesCount = 0;
-
- while (!f.eof())
- {
- char buff[1024];
- f.getline(buff, 1024);
- linesCount++;
- }
- f.close();
-
- return linesCount;
-
-}
-// abc,bcd,ab@Abv.bg,fn
-void readStudent(const char* input, OOPstudent& student)
-{
- int ind = 0;
-
- // first name
- while (input[ind] != ',')
- {
- student.firstName[ind] = input[ind];
- ind++;
- }
- student.firstName[ind] = '\0';
- ind++;
-
- //last name
- int lastNameInd = 0;
- while (input[ind] != ',')
- student.lastName[lastNameInd++] = input[ind++];
- student.lastName[lastNameInd] = '\0';
- ind++;
-
- //email
- int emailInd = 0;
-
- while (input[ind] != ',')
- student.email[emailInd++] = input[ind++];
- student.email[emailInd] = '\0';
- ind++;
-
- //fn
- while (input[ind] != '\0')
- (student.fn *= 10) += (input[ind++] - '0');
-
-}
-
-bool saveStudentsToFile(const OOPstudent* studentsCollection, int len, const char* fileName)
-{
- ofstream outFile(fileName);
-
- if (!outFile.is_open())
- return false;
-
- outFile << "First name, Last name, email, fn" << endl;
-
- for (int i = 0; i < len; i++)
- outFile << studentsCollection[i].firstName << "," << studentsCollection[i].lastName << "," << studentsCollection[i].email << "," << studentsCollection[i].fn << endl;
-
- outFile.close();
-
- return true;
-}
-
-int indexOfFirstSpaceOrTerminatingZero(const char* command)
-{
- int ind = 0;
- while (*command != ' ' && *command != '\t' && *command != '\0')
- {
- command++;
- ind++;
- }
- return ind;
-
-}
-
-bool printStudent(const OOPstudent* arrayOfStudents, int len, int fn)
-{
- for (int i = 0; i < len; i++)
- {
- if (arrayOfStudents[i].fn == fn)
- {
- cout << arrayOfStudents[i].firstName << "," << arrayOfStudents[i].lastName << "," << arrayOfStudents[i].email << "," << arrayOfStudents[i].fn << endl;
- return true;
- }
- }
- return false;
-}
-bool editFirstName(OOPstudent* arrayOfStudents, int len, int fn, const char* newFirstName)
-{
- for (int i = 0; i < len; i++)
- {
- if (arrayOfStudents[i].fn == fn)
- {
- strcpy(arrayOfStudents[i].firstName, newFirstName);
- return true; //success!
- }
- }
- return false; //no such student
-}
-int main()
-{
-
- cout << "Open file:" << endl << ">";
-
- char fileName[BUFFER_LINE_SIZE];
- cin.getline(fileName, BUFFER_LINE_SIZE);
-
- int studentsCount = countLines(fileName) - 1; // We ignore the first line
-
-
- if (studentsCount <= 0)
- {
- cout << "Error while reading data from the file " << endl;
- return -1;
- }
-
- OOPstudent* studentsCollection = new OOPstudent[studentsCount];
-
-
- ifstream f(fileName, ios::_Nocreate);
-
- if (!f.is_open())
- {
- cout << "Error!" << endl;
- delete[] studentsCollection;
- return -1;
- }
-
- int line = 1;
- while (!f.eof())
- {
- char buff[BUFFER_LINE_SIZE];
- f.getline(buff, BUFFER_LINE_SIZE);
-
- if (line == 1)
- {
- line++;
- continue;
- }
-
- readStudent(buff, studentsCollection[line - 2]);
- line++;
- }
- f.close();
-
- cout << "File successfully opened!" << endl;
-
- char commandLine[BUFFER_LINE_SIZE];
- do
- {
- cout << ">";
- cin.getline(commandLine, 1024);
- size_t len = strlen(commandLine);
-
-
-
- //first argument (edit, save ...)
- size_t firstArgSize = indexOfFirstSpaceOrTerminatingZero(commandLine);
- char* commandFirstArg = new char[firstArgSize + 1];
-
- for (int i = 0; i < firstArgSize; i++)
- commandFirstArg[i] = commandLine[i];
- commandFirstArg[firstArgSize] = '\0';
-
-
-
-
- if (len == firstArgSize) //no more arguments - quit? Check is bellow
- continue;
-
- //second argument (students.csv, 45543 ...)
- size_t secondArgSize = len - firstArgSize - 1;
- char* commandSecondArg = new char[secondArgSize + 1];
-
- for (int i = 0; i < secondArgSize; i++)
- commandSecondArg[i] = commandLine[firstArgSize + 1 + i];
- commandSecondArg[secondArgSize] = '\0';
- if (strcmp(commandFirstArg, "print") == 0)
- {
- int fn = atoi(commandSecondArg);
-
- bool res = printStudent(studentsCollection, studentsCount, fn);
-
- if (!res)
- cout << "Student with fn: " << fn << " doesn't exist!" << endl;;
- }
- else if (strcmp(commandFirstArg, "edit") == 0)
- {
- int fn = atoi(commandSecondArg);
-
- //we have a third argument here. It's in the second arguments string
-
- size_t seprator = indexOfFirstSpaceOrTerminatingZero(commandSecondArg);
-
- size_t thirdArgumentSize = secondArgSize - seprator;
- char* commandThirdArg = new char[thirdArgumentSize + 1];
-
- for (int i = 0; i < thirdArgumentSize; i++)
- commandThirdArg[i] = commandSecondArg[seprator + 1 + i];
- commandThirdArg[thirdArgumentSize] = '\0';
-
- bool result = editFirstName(studentsCollection, studentsCount, fn, commandThirdArg);
-
- if (result)
- cout << "Succesfully changed name!" << endl;
- else
- cout << "Student with fn: " << fn << "doesn't exist!" << endl;
-
- delete[] commandThirdArg;
- }
- else if (strcmp(commandFirstArg, "save") == 0)
- {
-
- bool res = saveStudentsToFile(studentsCollection, studentsCount, commandSecondArg);
-
- if (res)
- cout << "Successfully saved to file: " << commandSecondArg << endl;
- else
- cout << "Error while saving in file: " << commandSecondArg << endl;
-
- }
- delete[] commandFirstArg;
- delete[] commandSecondArg;
-
- } while (strcmp(commandLine, "Quit"));
-
- delete[] studentsCollection;
- return 0;
-}
diff --git a/Sem. 03/README.md b/Sem. 03/README.md
deleted file mode 100644
index 6439ced..0000000
--- a/Sem. 03/README.md
+++ /dev/null
@@ -1,129 +0,0 @@
-# Файлове (част 2). Двоични файлове.
-
-## Режими за работа с файлове
-
-
-| Режим:| Ефект: |
-|--------|------------------------------------------------------------------------------|
-|ios::in |Отваря файл за четене (по подразбиране на ifstream) |
-|ios::out |Отваря файл за четене (по подразбиране на ofstream) |
-|ios::binary | Отваря файл в двоичен режим |
-|ios::trunc | Ако файлът съществува, съдържанието му се изтрива след отваряне на поток |
-|ios::app | Отваря файлът за вмъкване. Поставя put указателят в края. Не се допуска вмъкване преди края на потока |
-|ios::ate | Отваря файлът за вмъкване. Поставя put указателят в края. Допуска вмъкване на прозиволни места |
-|ios::nocreate | Отваря за вмъкване, само ако файлът с указаното име съществува.|
-ios::noreplace | Отваря за вмъкване само ако файлът с указаното име не съществува.|
-### Пример:
- ```c++
-#include <iostream>
-#include <fstream>
-using namespace std;
-int main()
-{
- fstream f("test.txt", ios::out | ios::app);
-
- if (!f.is_open())
- {
- cout << "Error while opening file!" << endl;
- return -1;
- }
- f << 33; //appends at the end of the file
-
- f.close();
- return 0;
-}
- ```
-## Флагове на състоянията на потока
-| Флаг:| Значение: |
-|--------|------------------------------------------------------------------------------|
-|bad() | Има загуба на информация. Някоя операция за четене и писане не е изпълнена. |
-|fail() |Последната входно/изходна операция е невалидна.|
-| eof() | Достигнат е края на файла. |
-|good() | Всички операции са изпълнени успешно.|
-|clear()| Изчиства състоянието на потока (Вече good() ще върне истина).|
-
-## Позициониране във файл
-
- - tellg() - Връща позцития на текущия символ в **потока за четене**
- - tellp() - Връща позцития на текущия символ в **потока за писане**
- - seekg(offset, direction) - Премества get-указателят на позцития на **потока за четене**.
- - seekp(offset, direction) - Премества put-указателят на позцития на **потока за писане**.
-
-
- -**offset** : целочислена стойност. Отместването от direction.
-
- -**direction** : Може да заема следите стойностти:
-
-1. ios::beg - началото на файла.
-2. ios::cur - текущата позиция във файла.
-3. ios::end - края на файла.
-
-### Пример:
- ```c++
-#include <iostream>
-#include <fstream>
-using namespace std;
-size_t getFileLen(std::ifstream& ifs) //we can pass stream to functions.
-{
-
- ifs.seekg(0, std::ios::end); //set the position at the end of the file
- size_t size = ifs.tellg(); //get the curren position
- ifs.seekg(0, std::ios::beg); //set the position at the beginning
-
- return size;
-}
- ```
-## Двоични файлове.
-
-Изпоилзваме функциите:
-
-1. .read(char* memoryBlock, size_t size);
-2. .write(const char* memoryBlock, size_t size);
-
-Обърнете внимание, че функцията приема **char***. Ако искаме да запазим променлива от друг вид, ще трябва експлицитно да преобразуваме указателя към тип char* (без значение, че указателят не сочи към елементи от тип char)
-
-### Пример за писане в двоичен файл:
- ```c++
-#include <iostream>
-#include <fstream>
-
-using namespace std;
-
-int main()
-{
- ofstream f("file.dat");
-
- int a = 155555;
-
- f.write((const char*)&a, sizeof(int));
-
- return 0;
-}
- ```
- ### Пример за четене от двоичен файл:
-
- ```c++
-#include <iostream>
-#include <fstream>
-
-using namespace std;
-
-int main()
-{
- ifstream f("file.dat");
-
- int a;
-
- f.read((char*)&a, sizeof(int));
-
- cout << a << endl;
-
- return 0;
-}
- ```
-
- ### Съдържанието на двоичния файл:
- ![enter image description here](https://i.ibb.co/G3R72qG/sudurjanie.png "Binary file example")
-
-Байтовете се записват в **обратна посока**. Най-старшият байт е последен. Следователно запаментеното число е **00025fa3**, което е точно шестанйсетичния запис на числото **155555**.
-
diff --git a/Sem. 03/binaryFileExample.cpp b/Sem. 03/binaryFileExample.cpp
deleted file mode 100644
index e69de29..0000000
--- a/Sem. 03/binaryFileExample.cpp
+++ /dev/null
diff --git a/Sem. 03/notes_03.pdf b/Sem. 03/notes_03.pdf
deleted file mode 100644
index 0200d97..0000000
--- a/Sem. 03/notes_03.pdf
+++ /dev/null
Binary files differ
diff --git a/Sem. 03/sizeFile.cpp b/Sem. 03/sizeFile.cpp
deleted file mode 100644
index 862d565..0000000
--- a/Sem. 03/sizeFile.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#include <iostream>
-#include <fstream>
-
-using namespace std;
-
-size_t getFileSize(const char* fileName)
-{
- ifstream f(fileName);
-
- if (!f.is_open())
- return 0;
-
- f.seekg(0, ios::end);
- size_t pos = f.tellg();
-
- f.close();
-
- return pos;
-}
-int main()
-{
-
-
- cout << getFileSize("sizeFile.cpp") << endl;
-
- return 0;
-} \ No newline at end of file
diff --git a/Sem. 04/README.md b/Sem. 04/README.md
deleted file mode 100644
index 8974ae7..0000000
--- a/Sem. 04/README.md
+++ /dev/null
@@ -1,238 +0,0 @@
-
-
-
-# Структури и двоични файлове.
-### Размер на структура:
- ```c++
-#include <iostream>
-using namespace std;
-
-struct A
-{
- int a;
- int b;
-};
-
-int main()
-{
- cout << sizeof(A) << endl; // 8 bytes (4 bytes for each int)
-
- return 0;
-}
- ```
-
- Ето как изглежда структурата в паметта:
-
-
- ![enter image description here](https://i.ibb.co/9yWmQjP/2.png)
-
-Пример за **естествено подравняване**:
-
- ```c++
-#include <iostream>
-
-using namespace std;
-
-struct B
-{
- char ch;
- int a;
-};
-
-int main()
-{
- cout << sizeof(B); // 8 byte-s
-
- return 0;
-}
-
- ```
- В паметта нещата изглеждат така:
-
-![enter image description here](https://i.ibb.co/zJ5bLCw/pic1.png)
-
-### Подравняване
-При представянето на обект (от някакъв тип) в паметта:
-
-- В паметта променливите са разположени **в същия ред**, в който са декларирани в структурата.
- - Подравняването става по **големината на най-голямата примитивна член-променлива** на структурата - размерът на структурата трябва да се дели на размерът на най-голямата променлива.
- - *Неформално*: Всяка променлива трябва да е на байт (ако приемем, че байтовете имат индекс, започвайки от 0), който е **кратен на големината на променливата**.
-
- За постигане на най-компактно представяне полетата на структурата да се сортират по тяхната големина в низходящ ред
-
-### Пример за записване на обекти във файл.
- ```c++
-#include <iostream>
-#include <fstream>
-using namespace std;
-
-struct Test
-{
- char ch;
- int a;
-};
-int main()
-{
- ofstream f("output.dat", ios::binary);
-
- if(!f.is_open())
- {
- cout << "Error!" << endl;
- return -1;
- }
-
- Test arr[3] = {{'a', 400},{'b', 500},{'c', 600}};
-
- f.write((const char*)&arr, sizeof(arr));
-
- f.close();
-
- return 0;
-}
-
- ```
-
-След изпълнението на програмата, файлът (**output.dat**) изглежда така:
-
-![Image of the binary file after running the code](https://i.ibb.co/0JthLd6/3-A978-D14-7-C7-A-4-ABD-8-B0-C-DA27-F6-E9-CD0-A.png "Binary file")
-
-
-
-
-
-### Пример за записване на обекти, които съдържат динамично заделени данни, във файл.
- ```c++
-#include <iostream>
-#include <fstream>
-
-using namespace std;
-
-
-struct Student
-{
- char* name;
- int fn;
- int gradesCount;
- double averageGrade;
-};
-void print(const Student& st)
-{
- cout << st.name << " " << st.fn << " " << st.gradesCount << " " << st.averageGrade << endl;
-}
-Student createStudent(const char* name, int fn, int gradesCount, double avGrade)
-{
- Student obj;
-
- size_t nameLen = strlen(name);
-
- obj.name = new char[nameLen + 1];
- strcpy(obj.name, name);
-
- obj.fn = fn;
- obj.gradesCount = gradesCount;
- obj.averageGrade = avGrade;
-
- return obj;
-}
-void saveStudentToFile(ofstream& f, const Student& st)
-{
- size_t nameLen = strlen(st.name);
-
- f.write((const char*)&nameLen, sizeof(nameLen)); //first we write the size of the name!
- f.write(st.name, nameLen);
-
- f.write((const char*)&st.fn, sizeof(st.fn));
- f.write((const char*)&st.gradesCount, sizeof(st.gradesCount));
- f.write((const char*)&st.averageGrade, sizeof(st.averageGrade));
-
-}
-Student readStudentFromFile(ifstream& f)
-{
- Student res;
-
- size_t nameLen;
-
- f.read((char *)&nameLen, sizeof(nameLen)); //first we read the size of the name!
-
- res.name = new char[nameLen + 1];
- f.read(res.name, nameLen);
- res.name[nameLen] = '\0';
-
- f.read((char *)&res.fn, sizeof(res.fn));
- f.read((char*)&res.gradesCount, sizeof(res.gradesCount));
- f.read((char*)&res.averageGrade, sizeof(res.averageGrade));
-
- return res;
-}
-void freeStudent(Student& s)
-{
- delete[] s.name;
-
- s.averageGrade = s.fn = s.gradesCount = 0;
-
-}
-
-
-int main()
-{
- { //save students to file
- Student s1 = createStudent("Ivan", 1234, 2, 4);
- Student s2 = createStudent("Petur", 5555, 5, 5.5);
-
- ofstream f1("uni.dat", ios::binary);
-
- if (!f1.is_open())
- {
- cout << "Error" << endl;
- return -1;
- }
-
- saveStudentToFile(f1, s1);
- saveStudentToFile(f1, s2);
-
- freeStudent(s1);
- freeStudent(s2);
-
- f1.close();
- }
-
- { //read students from file
- ifstream f2("uni.dat", ios::binary);
-
- if (!f2.is_open())
- {
- cout << "Error" << endl;
- return -1;
- }
- Student s1 = readStudentFromFile(f2);
- Student s2 = readStudentFromFile(f2);
-
- print(s1);
- print(s2);
-
- freeStudent(s1);
- freeStudent(s2);
-
- f2.close();
- }
-}
-
-
- ```
-
-### Задачи
-
-**Задача 1:** Да се реализира система за база данни **произволен брой унивеситети**. Всеки университет има име (**низ до 32 символа**) и колекция от студенти (**произволен брой**). Всеки студент има - име (**низ с произволна дължина**), факултетен номер, брой получени оценки и средна оценка. Релизирайте **записване във файл и четене от файл** за базата данни. Релизирайте и следнита функции:
-
-- По подадено име на университет и факултетен номер на студент променя името на студента.
-
-*changeName(const char &ast; uni, int fn, const char &ast; newName)*
-
-- Добавяне на оценка на даден студент. След добавянето на оценката, трябва да се обнови броят получени оценки и средната оценка.
-
- *addGrade(const char &ast; uni, int fn, int grade)*
-
-- Функция, която сортира университите по среден успех на студентите.
-
-*sort(uni &ast;, size_t unisCount)*
-
diff --git a/Sem. 04/task1/uni-task.cpp b/Sem. 04/task1/uni-task.cpp
deleted file mode 100644
index 0b534c0..0000000
--- a/Sem. 04/task1/uni-task.cpp
+++ /dev/null
@@ -1,378 +0,0 @@
-#include <iostream>
-#include<cstring>
-#include<fstream>
-#pragma warning(disable : 4996)
-
-struct Student
-{
- char* name;
- int fn;
- int gradesCount;
- double averageGrade;
-};
-
-struct University
-{
- char name[32];
- Student* collection;
- size_t studentsCount;
-};
-
-void print(const Student& st)
-{
- std::cout << std::endl << "======STUDENT======" << std::endl;
- std::cout << "Name: " << st.name << std::endl << "Faculcy number:" << st.fn <<
- std::endl << "Grades: " << st.gradesCount << std::endl << "Avarage: " << st.averageGrade << std::endl;
-}
-
-Student createStudent(const char* name, int fn, int gradesCount, double avGrade)
-{
- Student obj;
-
- size_t nameLen = strlen(name);
-
- obj.name = new char[nameLen + 1];
- strcpy(obj.name, name);
-
- obj.fn = fn;
- obj.gradesCount = gradesCount;
- obj.averageGrade = avGrade;
-
- return obj;
-}
-
-void freeStudent(Student& s)
-{
- delete[] s.name;
-
- s.averageGrade = s.fn = s.gradesCount = 0;
-
-}
-
-void saveStudentToFile(std::ofstream& f, const Student& st)
-{
- size_t nameLen = strlen(st.name);
-
- f.write((const char*)&nameLen, sizeof(nameLen)); //first we write the size of the name!
- f.write(st.name, nameLen);
-
- f.write((const char*)&st.fn, sizeof(st.fn));
- f.write((const char*)&st.gradesCount, sizeof(st.gradesCount));
- f.write((const char*)&st.averageGrade, sizeof(st.averageGrade));
-}
-
-Student readStudentFromFile(std::ifstream& f)
-{
- Student res;
-
- size_t nameLen;
-
- f.read((char*)&nameLen, sizeof(nameLen)); //first we read the size of the name!
-
- res.name = new char[nameLen + 1];
- f.read(res.name, nameLen);
- res.name[nameLen] = '\0';
-
- f.read((char*)&res.fn, sizeof(res.fn));
- f.read((char*)&res.gradesCount, sizeof(res.gradesCount));
- f.read((char*)&res.averageGrade, sizeof(res.averageGrade));
-
- return res;
-}
-
-University createUniversity(const char* _name, const Student* collection, const size_t& studentCount)
-{
- University uni;
-
- strcpy(uni.name, _name);
- uni.collection = new Student[studentCount];
- uni.studentsCount = studentCount;
-
- for (size_t i = 0; i < studentCount; i++)
- {
- uni.collection[i] = collection[i];
- }
-
- return uni;
-}
-
-void saveUniversityToFile(std::ofstream& outStream, const University& Uni)
-{
- //Writing the name of the university first:
- outStream.write(Uni.name, 32);
-
- //Then we write the students count:
- outStream.write((const char*)(&Uni.studentsCount), sizeof(Uni.studentsCount));
-
- //Writing every single student:
- size_t count = Uni.studentsCount;
- for (size_t i = 0; i < count; i++)
- {
- saveStudentToFile(outStream, Uni.collection[i]);
- }
-}
-
-University readUniFromFile(std::ifstream& inFile)
-{
- //to return:
- University uni;
-
- //We follow the same read order as we wrote them:
-
- //name:
- inFile.read((char*)(&uni.name), 32);
-
- //count:
- inFile.read((char*)(&uni.studentsCount), sizeof(uni.studentsCount));
-
- //students:
- size_t studentsCount = uni.studentsCount;
- uni.collection = new Student[studentsCount];
-
- for (size_t i = 0; i < studentsCount; i++)
- {
- uni.collection[i] = readStudentFromFile(inFile);
- }
-
- return uni;
-}
-
-void printUni(const University& uni)
-{
- size_t studentsCount = uni.studentsCount;
-
- std::cout << std::endl << "----------" << uni.name << "----------";
-
- for (size_t i = 0; i < studentsCount; i++)
- {
- print(uni.collection[i]);
- std::cout << std::endl;
- }
- std::cout << "-------------------------";
-}
-
-void freeUni(University& uni)
-{
- for (int i = 0; i < uni.studentsCount; i++)
- freeStudent(uni.collection[i]);
-
- strcpy(uni.name, "");
- uni.studentsCount = 0;
-}
-
-void changeStudentName(Student& st, const char* newName)
-{
- delete[] st.name;
- st.name = new char[strlen(newName) + 1];
- strcpy(st.name, newName);
-}
-
-void changeName(University* uniCollection, const int& uniCount, const char* uni, const int& fn, const char* newName)
-{
- int uniFound = -1;
- int studentFound = -1;
-
- for (int i = 0; i < uniCount; i++)
- {
- if (strcmp(uniCollection[i].name, uni) != 0)
- {
- continue;
- }
-
-
- uniFound = i;
- size_t studentsCount = uniCollection[i].studentsCount;
-
- for (size_t j = 0; j < studentsCount; j++)
- {
- if (uniCollection[i].collection[j].fn != fn)
- {
- continue;
- }
-
- studentFound = j;
- changeStudentName(uniCollection[i].collection[j], newName);
- break;
- }
- break;
- }
-
- if (uniFound != -1 && studentFound != -1)
- {
- std::cout << std::endl << "Changed: " << std::endl;
- print(uniCollection[uniFound].collection[studentFound]);
- }
- else
- {
- std::cout << std::endl << "No such student in this university" << std::endl;
- }
-}
-
-void addStudentGrade(Student& st, const int& grade)
-{
- double newAvarageGrade = (double)((st.averageGrade * st.gradesCount) + grade) / (double)(st.gradesCount + 1);
- st.averageGrade = newAvarageGrade;
- st.gradesCount++;
-}
-
-void addGrade(University* uniCollection, const int& uniCount, const char* uni, const int& fn, const int& grade)
-{
- int uniFound = -1;
- int studentFound = -1;
-
- for (int i = 0; i < uniCount; i++)
- {
- if (strcmp(uniCollection[i].name, uni) != 0)
- {
- continue;
- }
-
- uniFound = i;
- size_t studentsCount = uniCollection[i].studentsCount;
-
- for (size_t j = 0; j < studentsCount; j++)
- {
- if (uniCollection[i].collection[j].fn != fn)
- {
- continue;
- }
-
- studentFound = j;
- addStudentGrade(uniCollection[i].collection[j], grade);
- break;
- }
- break;
- }
-
- if (uniFound != -1 && studentFound != -1)
- {
- std::cout << std::endl << "Added: " << std::endl;
- print(uniCollection[uniFound].collection[studentFound]);
- }
- else
- {
- std::cout << std::endl << "No such student in this university" << std::endl;
- }
-}
-
-double getSuccess(const University uni)
-{
- double avarageGrade = 0;
- size_t studentsCount = uni.studentsCount;
-
- for (size_t i = 0; i < studentsCount; i++)
- {
- avarageGrade += uni.collection[i].averageGrade;
- }
-
- avarageGrade = avarageGrade / (double)(studentsCount);
-
- return avarageGrade;
-}
-
-void swapUniversities(University* uniCollection, const int& first, const int& second)
-{
- University temp = uniCollection[first];
- uniCollection[first] = uniCollection[second];
- uniCollection[second] = temp;
-}
-
-void sort(University* uniCollection, size_t unisCount)
-{
- //selection sort
- for (int pos = 0; pos < unisCount - 1; pos++)
- {
- int minimalIndex = pos;
-
- for (int i = pos; i < unisCount; i++)
- {
- int currSuccess = getSuccess(uniCollection[minimalIndex]);
- if (getSuccess(uniCollection[i]) > currSuccess)
- {
- minimalIndex = i;
- }
- }
-
- if (minimalIndex != pos)
- swapUniversities(uniCollection, pos, minimalIndex);
- }
-}
-
-int main()
-{
- //simple example:
-
- //creating university database:---------------
- University* uniCollection = new University[3];
-
- //FMI
- Student collection[3];
- collection[0] = createStudent("Angel", 81111, 6, 3);
- collection[1] = createStudent("Dimitar", 82222, 6, 2);
- collection[2] = createStudent("Anton", 83333, 6, 2);
-
- University FMI = createUniversity("FMI", collection, 3);
-
- //TU
- Student collectionTwo[4];
- collectionTwo[0] = createStudent("Vesko", 31244, 6, 6);
- collectionTwo[1] = createStudent("Ivan", 42342, 6, 6);
- collectionTwo[2] = createStudent("Mariano", 13433, 6, 6);
- collectionTwo[3] = createStudent("Gabriela", 43234, 6, 6);
-
- University TU = createUniversity("TU", collectionTwo, 4);
-
- //UNWE
- Student collectionThree[5];
- collectionThree[0] = createStudent("Chavdar", 13579, 6, 4);
- collectionThree[1] = createStudent("Stoino", 24680, 6, 4);
- collectionThree[2] = createStudent("Miss Playmate", 24567, 6, 4);
- collectionThree[3] = createStudent("ex fmi student", 12343, 6, 4);
- collectionThree[4] = createStudent("bukvalno vseki", 13333, 6, 5);
-
- University UNWE = createUniversity("UNWE", collectionThree, 5);
-
- uniCollection[0] = FMI;
- uniCollection[1] = TU;
- uniCollection[2] = UNWE;
- //-------------------------------------------------------------
-
- //functions:
- std::ofstream outFile("path.txt", std::ios::binary);
- saveUniversityToFile(outFile, uniCollection[1]);
- if (outFile.good() == 0)
- {
- std::cout << "Error saving the file";
- }
-
- outFile.close();
-
- std::ifstream inFile("path.txt", std::ios::binary);
- University example = readUniFromFile(inFile);
-
- if (inFile.good() == 0)
- {
- std::cout << "Error reading the file";
- }
-
- inFile.close();
-
- printUni(example);
-
- changeName(uniCollection, 3, "FMI", 83333, "Antoan");
- addGrade(uniCollection, 3, "FMI", 81111, 6);
-
- sort(uniCollection, 3);
-
- std::cout << "\nSorted:\n";
-
- for (int i = 0; i < 3; i++)
- {
- std::cout << i + 1 << ". " << uniCollection[i].name << std::endl;
- }
-
- for (int i = 0; i < 3; i++)
- {
- freeUni(uniCollection[i]);
- }
-}
diff --git a/Sem. 05/Interval/Interval.cpp b/Sem. 05/Interval/Interval.cpp
deleted file mode 100644
index c3f11cf..0000000
--- a/Sem. 05/Interval/Interval.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-#include <iostream>
-#include <algorithm>
-#include "Interval.h"
-
-bool isPrime(int n)
-{
- double temp = sqrt(n);
- for (int i = 2; i <= temp; i++)
- {
- if (n % i == 0)
- return false;
- }
- return true;
-}
-
-bool isPalindorme(int n)
-{
- int reversed = 0;
-
- while (n != 0)
- {
- int lastDigit = n % 10;
- (reversed *= 10) += lastDigit;
- n /= 10;
- }
- return n == reversed;
-}
-bool containsOnlyDistinctNumbers(int n)
-{
- bool digits[10];
- for (int i = 0; i < 10; i++)
- digits[i] = false;
-
- while (n != 0)
- {
- int lastDigit = n % 10;
- if (digits[lastDigit])
- return false;
- digits[n % 10] = true;
- n /= 10;
- }
- return true;
-}
-
-size_t Interval::countNumbersInIntervalCondition(bool(*pred)(int)) const
-{
- size_t count = 0;
- for (int i = a; i <= b; i++)
- {
- if (pred(i))
- count++;
- }
- return count;
-}
-
-Interval::Interval() : Interval(0, 0) {}
-
-Interval::Interval(int a, int b)
-{
- if (a > b)
- a = b = 0;
-
- this->a = a;
- this->b = b;
-}
-
-int Interval::getA() const
-{
- return a;
-}
-
-int Interval::getB() const
-{
- return b;
-}
-void Interval::setA(int a)
-{
- if (a > b)
- return;
- this->a = a;
-}
-
-void Interval::setB(int b)
-{
- if (b < a)
- return;
- this->b = b;
-}
-
-size_t Interval::getLength() const
-{
- return b - a + 1;
-}
-
-bool Interval::isMemberOfInterval(int x) const
-{
- return (a <= x && x <= b);
-}
-
-size_t Interval::calcPrimeNumbersInTheInterval() const
-{
- return countNumbersInIntervalCondition(isPrime);
-}
-
-size_t Interval::calcPalindromicNumbersInTheInterval() const
-{
- return countNumbersInIntervalCondition(isPalindorme);
-}
-
-size_t Interval::calcDiffrentDigitNumbersInTheInverval() const
-{
- return countNumbersInIntervalCondition(containsOnlyDistinctNumbers);
-}
-
-bool Interval::areStartAndEndPowersOfTwo() const
-{
- return (a == 0 || (a & a - 1) == 0) && (b == 0 || (b & b - 1) == 0);
-}
-
-Interval Interval::intersect(const Interval& other) const
-{
- if (b < other.getA() || a > other.getB())
- return Interval(0, 0);
-
- int newA = std::max(a, other.getA());
- int newB = std::min(b, other.getB());
-
- return Interval(newA, newB);
-}
-bool Interval::isSuperInterval(const Interval& other) const
-{
- return a <= other.getA() && b >= other.getB();
-} \ No newline at end of file
diff --git a/Sem. 05/Interval/Interval.h b/Sem. 05/Interval/Interval.h
deleted file mode 100644
index c8fcbc7..0000000
--- a/Sem. 05/Interval/Interval.h
+++ /dev/null
@@ -1,32 +0,0 @@
-
-class Interval
-{
- int a;
- int b;
-
- size_t countNumbersInIntervalCondition(bool(*pred)(int)) const;
-
-public:
-
- Interval();
- Interval(int a, int b);
-
- int getA() const;
- int getB() const;
-
- void setA(int a);
- void setB(int b);
-
- size_t getLength() const;
- bool isMemberOfInterval(int x) const;
-
- size_t calcPrimeNumbersInTheInterval() const;
- size_t calcPalindromicNumbersInTheInterval() const;
- size_t calcDiffrentDigitNumbersInTheInverval() const;
-
- bool areStartAndEndPowersOfTwo() const;
-
- Interval intersect(const Interval& other) const;
-
- bool isSuperInterval(const Interval& other) const;
-};
diff --git a/Sem. 05/Interval/Source.cpp b/Sem. 05/Interval/Source.cpp
deleted file mode 100644
index 7e6b3e1..0000000
--- a/Sem. 05/Interval/Source.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <iostream>
-#include "Interval.h"
-
-using namespace std;
-
-
-int main()
-{
- Interval i(1, 11);
-
- cout << i.calcDiffrentDigitNumbersInTheInverval() << endl;
-
- cout << i.getLength() << endl;
-
-} \ No newline at end of file
diff --git a/Sem. 05/README.md b/Sem. 05/README.md
deleted file mode 100644
index d9bd067..0000000
--- a/Sem. 05/README.md
+++ /dev/null
@@ -1,218 +0,0 @@
-# Член-функции. Конструктори и деструктор. Модификатори за достъп. Капсулация.
-
-## Член-функции.
-Член-функциите са функции, които работят с член-данните на обекта от дадена структура.
- ```c++
-struct Point
-{
- int x;
- int y;
-};
-bool isInFirstQuadrant(const Point& p)
-{
- return p.x >= 0 && p.y >= 0;
-}
-int main()
-{
- Point p1 = {3, 4};
- Point p2 = {-9, 8};
- cout << isInFirstQuadrant(p1) << endl;
- cout << isInFirstQuadrant(p2) << endl;
-}
- ```
-
- Може функцията да бъде член-функция:
- ```c++
-struct Point
-{
-
- int x;
- int y
-
- bool isInFirstQuadrant()
- {
- return x >= 0 && y >= 0;
- }
-
-};
-
-int main()
-{
- Point p1 = {3, 4};
- Point p2 = {-9, 8};
- cout << p1.isInFirstQuadrant() << endl;
- cout << p2.isInFirstQuadrant() << endl;
-}
- ```
-#
-**Член-функциите**:
-
- - Работят с член-данните на класа.
- - Извикват се с обект на класа
-
- - Компилаторът преобразува всяка **член-функция** на дадена структура в
- обикновена функция с уникално име и един допълнителен параметър
- –**указател към обекта**.
-
-**Константни член-функции**:
-
- - Не променят член-данните на структурата.
- - Оказва се чрез записването на ключовата дума **const** в декларацията и в края на заглавието в дефиницията им
- - Могат да се извикват от константни обекти.
-## Конструктори и деструктор.
-
-**Жизнен цикъл на обект**:
- - Създаване на обект в даден scope – заделя се памет и член-данните се инициализират.
- - Достига се до края на скоупа(област).
- - Обектът и паметта, която е асоциирана с него се разрушава.
-
-**Конструктор**:
- - Извиква се веднъж - при създаването на обекта.
- - Не се оказва експлицитно тип на връщане (връща констатна референция).
- - Има същото име като класа.
-
- **Деструктор**:
- - Извиква се веднъж - при изтриването на обекта.
- - Не се оказва експлицитно тип на връщане.
- - Има същото име като класа със симовла '~' в началото.
-
- ```c++
-
-#include <iostream>
-
-using namespace std;
-
-
-struct Test
-{
- Test()
- {
- cout << "Object is created" <<endl;
- }
-
- ~Test()
- {
- cout << "Object is destroyed" <<endl;
- }
- int a;
- int b;
-};
-
-int main()
-{
- while ()
- {
- Test t;// Object is created
- if ()
- {
- Test t2; // Object is created
-
- }// Object is destroyed (t2)
-
- }//Object is destroyed (t)
-}
-
- ```
- ## Капсулация (encapsulation).
-Понякога искаме потребителите да **нямат достъп до всички член-данни и методи на даден клас**.
-Това е така, защото тяхната промяна може да доведе до **неочаквано поведение** на нашата програма. Принципът за **капсулация** ни помага като позволява да определим кои методи и атрибути може да използват потребителите на нашия клас.
-
- **Модификатор за достъп**:
-
-| Модификатор за достъп: | Достъп: |
-|------------------------|---------------------------------|
-| private | В текущия клас. |
-| protected | В текущия клас и *наследниците. |
-| public | За всеки |
-
-**Пример за get-ъри и set-ъри**
-
- ```c++
-
-#include <iostream>
-
-using namespace std;
-
-
-struct Student
-{
-private:
- int grade;
- int age;
-public:
- Student(int grade, int age)
- {
- setGrade(grade);
- setAge(age);
- }
- int getGrade()
- {
- return grade;
- }
- int getAge()
- {
- return age;
- }
- void setGrade(int grade)
- {
- if(grade >= 2 && grade <= 6)
- this->grade = grade;
- }
- int setAge(int age)
- {
- if(age >= 0)
- this->age = age;
- }
-};
-
-int main()
-{
- while ()
- {
- Test t;// Object is created
- if ()
- {
- Test t2; // Object is created
-
- }// Object is destroyed (t2)
-
- }//Object is destroyed (t)
-}
-
- ```
-
-
-## Задачи
-
-**Задача 1:**
-Реализирайте клас/структура интервал, който представлява интервал [a,b] (задължително а <= b) от реалната права. Нашият интервал ще бъде дискретен - началото и краят му ще бъдат цели числа и ще разглеждаме само точки, които са цели числа. Релизирайте следният интерфейс:
-
- - Подразбиращ се контруктор, който създава интервала **[0,0]**.
- - Конструктор, който приема двата параметъра. Ако a<=b, то създава интервала **[a,b]**. В противен случай, създава **[0,0]**.
- - Член-функция, която връща **дължината на интервала**.
- - Член-функция, която приема число и проверява **дали е част от интервала**.
- - Член-функция, която връща **броя на простите числа** в интервала.
- - Член-функция, която връща **броя на числата в интервала**, които са палиндорми.
- - Член-функция, която връща **броя на числата, които нямат повтарящи цифри**.
- - Член-функция, която връща дали началото и края на интервала са **степени на 2-ката**. ([2,16] - истина)
- - Член-функция, която приема интервал и връща **сечението на текущия интервал с подадения**. (Сечението на [1, 5] [3, 7] e [3, 5]).
- - Член-функция, която приема интервал и връща дали подадения (като параметър) интервал е **подинтервал на текущия**(обектът, от който се извиква функцията).
-
- **Пример за работа с класа:**
- ```c++
-
-int main()
-{
- Interval t1(3,10); // [3, 10]
- Interval t2(4,14); // [4, 14]
- Interval t3; // [0, 0]
-
- Interval result = t1.intersect(t2); // [4, 10]
-
- t2.isSuperInterval(result); //true
-
- result.calcPrimeNumbersInTheInterval() // 2 (only 5 and 7)
-}
- ```
-
-
diff --git a/Sem. 06/README.md b/Sem. 06/README.md
deleted file mode 100644
index 70f3ba3..0000000
--- a/Sem. 06/README.md
+++ /dev/null
@@ -1,166 +0,0 @@
-
-# Разделна компилация. Абстракция. Копиращ конструктор и оператор=
-
-## Разделна компилация.
-
-![enter image description here](https://gamedevunboxed.com/wp-content/uploads/2019/08/image.png)
-
-Една програма на С++ може да бъде разбита в множество файлове, които се **компилират независимо един от друг**, т.е. осъществява се **разделна компилация**. В резултат на компилацията се получават няколко **обектни файла** (файлове с разширение **.obj**). Изпълнимият код напрограмата (файл с разширение .ехе) се получава след свързване на обектните файлове (**Linking**).
-
-За да се възполваме максимално от разделната компилация, разделяме класовете на **.h** и **.cpp** файлове. Навсякъде където ще работим с класа, ще включваме **само .h файла.** По този начин, ако променим реализацията на някоя от функциите на класа, ще се **прекомпилира само този файл**.
-
-![enter image description here](https://i.ibb.co/N9RnMHv/sss.png)
-## Абстракция
-Пример за **лоша абстракция**:
-
-```c++
-struct Triangle
-{
- int x1;
- int y1;
-
- int x2;
- int y2;
-
- int x3;
- int y3;
-};
-int getPer(const Triangle& t)
-{
- return
- sqrt( (t.x1-t.x2)*(t.x1-t.x2) + (t.y1-t.y2)*(t.y1-t.y2) +
- sqrt( (t.x2-t.x3)*(t.x2-t.x3) + (t.y2-t.y3)*(t.y2-t.y3) +
- sqrt( (t.x3-t.x1)*(t.x3-t.x1) + (t.y3-t.y1)*(t.y3-t.y1);
-}
- ```
- Пример за **по-добра абстракция**:
- ```c++
-struct Point
-{
- int x;
- int y
- double getDistTo(const Point& other)
- {
- return sqrt((x-other.x)*(x-other.x)+(y-other.y)*(y-other.y));
- }
-};
-struct Triangle
-{
- Point p1;
- Point p2;
- Point p3;
-};
-
-int getPer(const Triangle& t)
-{
- return t.p1.getDistTo(t.p2) + t.p2.getDistTo(t.p3) + t.p3.getDistTo(t.p1);
-}
- ```
-
-## Копиращ конструктор и оператор =
-Заедно с конструктора по подразбиране и деструктора във всеки клас се дефинират и следните член-функции:
- - Копиращ конструктор - конструктор, който приема обект от същия клас и създава новият обект като негово копие.
- - Оператор= - функция/оператор, който приема обект от същия клас и променя данните на съществуващ обект от същия клас (обектът от който извикваме функцията.
-
-**Забележка:** Копиращият конструктор създава нов обект, а оператор= модифицира вече съществуващ такъв!
-
- ```c++
-
-#include <iostream>
-
-using namespace std;
-
-struct Test
-{
-
- Test()
- {
- cout << "Default constructor" <<endl;
- }
-
- Test(const Test& other)
- {
- cout << "Copy constructor" <<endl;
- }
-
- Test& operator=(const Test& other)
- {
- cout << "operator=" <<endl;
- }
-
- ~Test()
- {
- cout << "Destructor" <<endl;
- }
-};
-
-void f(Test object)
-{
- //do Stuff
-}
-
-
-void g(Test& object)
-{
- //do Stuff
-}
-int main()
-{
- Test t; //Default constructor;
-
- Test t2(t) // Copy constructor
- Test t3(t2) // Copy constructor
- Test t2 = t3 // operator=
- Test t3 = t // operator=
-
- Test newTest = t; //Copy constructor !!!!!!!
-
- f(t); // Copy constructor
- g(t); // nothing. We are passing it as a reference. We are not copying it!
-
- Test* ptr = new Test(); // Default constructor // we create a new object in the dynamic memory. The destructor must be invoked explicitly (with delete)
-
- delete ptr; // Destructor
-
-} //Destructor Destructor Destructor Destructor
-
- ```
-
-## Задачи
-
-**Задача 1:**
-Реализирайте клас **Time**, който ще се използва за работа с часове (13:05:45).
-Вашият клас трябва да има следния интерфейс:
-
- - Подразбиращ се контруктор, който създава часа на **00:00:00**.
- - Конструктор, който приема три параметъра - **час, минути и секунди**.
- - Член-функция, която **добавя/изважда** часове.
- - Член-функция, която **добавя/изважда** минути.
- - Член-функция, която **добавя/изважда** секунди.
- - Член-функция, която връща оставащото време до **полунощ**.
- - Член-функция, която връща дали е **време за вечеря**. В рамките на задачата време за вечеря е между **20:30** и **22:00**.
- - Член-функция, която връща дали е **време за парти**. В рамките на задачата време за парти е между **23:00** и **06:00**.
- - Член-функция, която приема друг обект от тип **Time** и връща обект от тип **Time**, което е разликата между двете времена.
- - Член-функция, която която приема друг обект от тип **Time** и сравнява двата обекта (по-къснен/по-ранен)
-
-
-
- ```c++
-
-int main()
-{
- Time t(12,30,45); //12:30:45
- Time t2; //00:00:00
-
- t.addSeconds(15); //12:31:00
- t.addMinutes(29); // 13:00:00;
-
- t.isPartyTime(); // false
-
- Time result = t.timeToMidnight(); // 11:00:00
-
- t2.compareTo(t); //some value that indicates that t2 < t
-}
- ```
-
-
diff --git a/Sem. 06/Time/Source.cpp b/Sem. 06/Time/Source.cpp
deleted file mode 100644
index e4dd497..0000000
--- a/Sem. 06/Time/Source.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <iostream>
-#include "Time.h"
-
-using namespace std;
-
-
-int main()
-{
- Time t(12, 30, 30);
-
- t.print();
- t.addMinutes(45);
- t.print();
-} \ No newline at end of file
diff --git a/Sem. 06/Time/Time.cpp b/Sem. 06/Time/Time.cpp
deleted file mode 100644
index 9cd8620..0000000
--- a/Sem. 06/Time/Time.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-#include "Time.h"
-#include <iostream>
-
-Time::Time() : Time(0, 0, 0){}
-
-Time::Time(size_t hours, size_t mins, size_t seconds)
-{
- setHours(hours);
- setMins(mins);
- setSeconds(seconds);
-}
-
-size_t Time::getHours() const
-{
- return hours;
-}
-size_t Time::getMins() const
-{
- return mins;
-}
-size_t Time::getSeconds() const
-{
- return seconds;
-}
-void Time::setHours(size_t hours)
-{
- if (hours >= 24)
- hours = 0;
- this->hours = hours;
-}
-void Time::setMins(size_t mins)
-{
- if (mins > 59)
- mins = 0;
- this->mins = mins;
-}
-void Time::setSeconds(size_t seconds)
-{
- if (seconds > 59)
- seconds = 0;
- this->seconds = seconds;
-}
-void Time::print()
-{
- std::cout << hours << ":" << mins << ":" << seconds << std::endl;
-}
-
-void Time::addSeconds(size_t seconds)
-{
- size_t currentTimeSeconds = convertTimeToSeconds();
-
- currentTimeSeconds += seconds;
-
- setTimeBySeconds(currentTimeSeconds);
-
-}
-void Time::addMinutes(size_t minutes)
-{
- addSeconds(60 * minutes);
-}
-void Time::addHours(size_t hours)
-{
- addMinutes(60 * hours);
-}
-size_t Time::convertTimeToSeconds()
-{
- return hours * 3600 + mins * 60 + seconds;
-}
-void Time::setTimeBySeconds(size_t seconds) //12000
-{
- hours = seconds / 3600;
- seconds %= 3600;
-
- mins = seconds / 60;
- seconds %= 60;
-
- this->seconds = seconds;
-} \ No newline at end of file
diff --git a/Sem. 06/Time/Time.h b/Sem. 06/Time/Time.h
deleted file mode 100644
index 3789910..0000000
--- a/Sem. 06/Time/Time.h
+++ /dev/null
@@ -1,27 +0,0 @@
-class Time
-{
- size_t hours;
- size_t mins;
- size_t seconds;
-
- size_t convertTimeToSeconds();
- void setTimeBySeconds(size_t);
-
-public:
- Time();
- Time(size_t hours, size_t mins, size_t seconds);
-
-
- size_t getHours() const;
- size_t getMins() const;
- size_t getSeconds() const;
- void setHours(size_t hours);
- void setMins(size_t mins);
- void setSeconds(size_t seconds);
-
- void addSeconds(size_t seconds);
- void addMinutes(size_t seconds);
- void addHours(size_t seconds);
-
- void print();
-};
diff --git a/Sem. 07/Person/Person.cpp b/Sem. 07/Person/Person.cpp
deleted file mode 100644
index 2786671..0000000
--- a/Sem. 07/Person/Person.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-#include <iostream>
-#include "Person.h"
-
-Person::Person(const char* name, int age)
-{
- setName(name);
- setAge(age);
-}
-
-
-void Person::setName(const char* name)
-{
- if (strlen(name) >= 20)
- {
- strcpy(this->name, "Unknown");
- }
- else
- {
- strcpy(this->name, name);
- }
-}
-
-void Person::setAge(int age)
-{
- if (age<0 || age > 120)
- age = 40;
- this->age = age;
-}
-const char* Person::getName() const
-{
- return name;
-}
-int Person::getAge() const
-{
- return age;
-}
-void Person::print()
-{
- std::cout << name << " " << age << std::endl;
-} \ No newline at end of file
diff --git a/Sem. 07/Person/Person.h b/Sem. 07/Person/Person.h
deleted file mode 100644
index 499c744..0000000
--- a/Sem. 07/Person/Person.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#pragma once
-
-class Person
-{
-public:
- Person(const char* name, int age);
-
- void setName(const char* name);
- void setAge(int age);
-
- const char* getName() const;
- int getAge() const;
-
- void print();
-
-private:
- char name[20];
- int age;
-};
diff --git a/Sem. 07/Person/Source.cpp b/Sem. 07/Person/Source.cpp
deleted file mode 100644
index 478d07a..0000000
--- a/Sem. 07/Person/Source.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <iostream>
-#include "Person.h"
-using namespace std;
-
-int main()
-{
- Person p("Ivan", 13);
- Person p2("Petur", 12);
-
- p = p2;
-
- p2.setName("Aleks");
- p.print();
- p2.print();
-
-}
diff --git a/Sem. 07/PersonAdvanced/PersonAdvanced.cpp b/Sem. 07/PersonAdvanced/PersonAdvanced.cpp
deleted file mode 100644
index e4e062f..0000000
--- a/Sem. 07/PersonAdvanced/PersonAdvanced.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-#include "PersonAdvanced.h"
-#include <iostream>
-
-PersonAdvanced::PersonAdvanced(const char* name, int age) : name(nullptr), age(age)
-{
- setName(name);
- setAge(age);
-}
-
-PersonAdvanced::PersonAdvanced(const PersonAdvanced& other)
-{
- copyFrom(other);
-}
-
-PersonAdvanced& PersonAdvanced::operator = (const PersonAdvanced& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
-}
-PersonAdvanced::~PersonAdvanced()
-{
- free();
-}
-
-const char* PersonAdvanced::getName() const
-{
- return name;
-}
-
-int PersonAdvanced::getAge() const
-{
- return age;
-}
-
-void PersonAdvanced::setName(const char* name)
-{
- delete[] this->name;
- this->name = new char[strlen(name) + 1];
- strcpy(this->name, name);
-}
-void PersonAdvanced::setAge(int age)
-{
- if (age < 0 || age > 120)
- age = 40;
- this->age = age;
-}
-
-
-void PersonAdvanced::copyFrom(const PersonAdvanced& other)
-{
- name = new char[strlen(other.name) + 1];
- strcpy(name, other.name);
-
- age = other.age;
-}
-void PersonAdvanced::free()
-{
- delete[] name;
- age = 0;
-}
-
-void PersonAdvanced::print()
-{
- std::cout <<"Name: "<< name << ", age: " << age << std::endl;
-} \ No newline at end of file
diff --git a/Sem. 07/PersonAdvanced/PersonAdvanced.h b/Sem. 07/PersonAdvanced/PersonAdvanced.h
deleted file mode 100644
index 92e000e..0000000
--- a/Sem. 07/PersonAdvanced/PersonAdvanced.h
+++ /dev/null
@@ -1,28 +0,0 @@
-#pragma once
-
-class PersonAdvanced
-{
-public:
- PersonAdvanced(const char* name, int age);
-
- PersonAdvanced(const PersonAdvanced& other);
- PersonAdvanced& operator=(const PersonAdvanced& other);
- ~PersonAdvanced();
-
- void setName(const char* name);
- void setAge(int age);
-
- const char* getName() const;
- int getAge() const;
-
- void print();
-
-private:
-
- void copyFrom(const PersonAdvanced& other);
- void free();
-
-
- char* name;
- int age;
-};
diff --git a/Sem. 07/PersonAdvanced/Source.cpp b/Sem. 07/PersonAdvanced/Source.cpp
deleted file mode 100644
index 8c92e6c..0000000
--- a/Sem. 07/PersonAdvanced/Source.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <iostream>
-#include "PersonAdvanced.h"
-using namespace std;
-
-int main()
-{
- PersonAdvanced p("Ivan", 13);
- PersonAdvanced p2("Petur", 12);
-
- p = p2;
-
- p2.setName("Aleks");
- p.print();
- p2.print();
-
-}
diff --git a/Sem. 07/README.md b/Sem. 07/README.md
deleted file mode 100644
index 1d3b9a6..0000000
--- a/Sem. 07/README.md
+++ /dev/null
@@ -1,121 +0,0 @@
-# Голямата четворка (Rule of four)
-
- - Конструктор по подразбиране (конструктор без параметри)
- - Конструктор за копиране
- - Оператор =
- - Деструктор
-
-Да разгледаме следната структура:
-```c++
-struct Test
-{
- char str[20];
- A obj2;
- B obj3;
-};
- ```
- Понеже функциите (от голямата четворка) не са дефинирани в структурата, то компилаторът ще създаде такива:
- ```c++
-int main()
-{
- Test currentObject; //default constructor
-
- Test object2(currentObject); //copy constructor
-
- currentObject = object2; //operator =
-
-} //destructor (x2)
- ```
- Кодът се компилира успешно и функциите имат правилно поведение.
-### Как работят дефинираните от компилатора функции?
- Всяка една от тезу функции **извиква рекурсивно същите функции връху член-данните.**
- #### Пример за конструктора по подразбиране:
-
-![enter image description here](https://i.ibb.co/s2m8XtC/1.png)
-
- #### Пример за деструктора:
-![enter image description here](https://i.ibb.co/kmYSzP7/2.png)
-
- #### Пример за копиращия конструктор:
-![enter image description here](https://i.ibb.co/9Vqk7Mn/3.png)
-### Проблем при функциите, генерирани от компилатора:
-
-Да разгледаме следния код:
-
- ```c++
-struct Person
-{
- PersonA(const char* name, int age)
- {
- this->name = new char[strlen(name) + 1];
- strcpy(this->name, name);
- this->age = age;
- }
-private:
-
- char* name;
- int age;
-};
-
-int main()
-{
- Person p1;
- Person p2(p1);
-}
-
- ```
- Горното извикване на копиращия конструктор има **грешено поведение**:
-
-![enter image description here](https://i.ibb.co/q5rfGBf/Capture.png)
-
-
-Това е **shallow copy**. В p2 са се копирали стойностите на p1, което довежда до споделяне на една и съща динамична памет.
-В тази ситуация ще трябва да се имплементират експлицитно **копиращия конструктор, оператора за присвояване и деструктора**, защото генерираните от компилатора не биха работили правилно.
-
-**Правилното поведение** на копиращия конструктор е следното:
-
-![enter image description here](https://i.ibb.co/XZq5rGT/33.png)
-
-### Собствена имплементация на функциите за копиране и деструктора
-
- ```c++
-struct Person
-{
- Person(const char* name, int age) : name(nullptr), age(age)
- {
- setName(name);
- setAge(age);
- }
-
- Person(const Person& other)
- {
- copyFrom(other); // копираме
- }
-
- Person& operator=(const Person& other)
- {
- if (this != &other)
- {
- free(); //трием
- copyFrom(other); //копираме
- }
- return *this;
- }
- ~Person()
- {
- free(); //трием
- }
-
- .
- .
- .
-
-
-
-};
-
- ```
-
-При всички класове, които използват динамична памет, тези функции изглеждат по този начин. Разликите са в имплементациите на функциите **free** и **copyFrom**.
-
-
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;
-}
- ```
diff --git a/Sem. 09/README.md b/Sem. 09/README.md
deleted file mode 100644
index 3ec48cc..0000000
--- a/Sem. 09/README.md
+++ /dev/null
@@ -1,230 +0,0 @@
-# Композиция на обекти. Масиви от обекти. Шаблони.
-## Композиция
-Композиция – класове като елементи на други класове (влагане на класове) Един клас може да включва в себе си обекти от други класове като член-данни. Когато обект от даден клас се дефинира, автоматично се извиква неговият конструктор. Ако класът съдържа член-данни, в неговия конструктор трябва да се укаже кои конструктори на член-данните да се извикват.
-#### Пример 1
-```c++
-class A
-{
- .
- .
- .
-}
-class B
-{
- int n;
- A obj;
-}
- ```
-В тази ситуация се извикват **default-ните те конструктори на n и obj**.
-#### Пример 2
-```c++
-class A
-{
- A(int a, int b)
- .
- .
- .
-}
-class B
-{
- B() : A(1, 2)
- {}
-
- int n;
- A obj;
-}
- ```
-Тук A няма default-ен конструктор. Това означава, че в конструктора на B трябва да се извика **експлицитно** някой от неговите конструктори
-### Композиция на обекти с динамична памет
-Когато имаме композиция и в главния клас има динамично заделяне на памет, то трябва в реализацията на копи-конструктора и оператор= **експлицитно** да се извикват копи-конструкторите и оператора = за всички член-данни (композирани обекти).
-```c++
-class B;
-
-class A
-{
- void copyFrom(const A& other)
- {
- arr = new int[other.size];
- for (int i = 0; i < other.size; i++)
- arr[i] = other.arr[i];
- size = other.size;
- }
- void free()
- {
- delete[] arr;
- }
-
-public:
- B nestedObject;
- int* arr; //dynamic array
- size_t size;
-
- A(int n) : size(n)
- {
- arr = new int[n];
- }
- A(const A& other) : nestedObject(other.objTest), size(other.size)
- {
- copyFrom(other);
- }
- A& operator=(const A& other)
- {
- nestedObject= other.nestedObject;
- size = other.size;
-
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
- }
-
- ~A()
- {
- free();
- }
-};
- ```
- **ВАЖНО**: Деструкторите на член-данните **НЕ** трябва да се извикват експлицитно в деструктора на класа.
-
-## Масиви от обекти
-#### Статичен масив от обекти
-
-```c++
-class A;
-int main()
-{
- A arr[5]; //5 def. constr.
-} //5 destr
- ```
-Създава **статичен** масив с 5 обекта от тип A. На всеки от тях се е извикал конструктора по подразбиране.
-Масивът ще се изтрие, когато приключи функцията.
-#### Статичен масив от указатели към обекти
-```c++
-class A;
-int main()
-{
- A* arr[10]; //5 empty pointers.
-
- arr[0] = new A();
- arr[2] = new A();
-
- delete arr[0];
- delete arr[2];
-}
- ```
-Създава **статичен** масив с 5 указателя . Само на 2 от тези указатели присвояваме обекти, които са заделени в динамичната памет.
-Масивът ще се изтрие, когато приключи функцията.
-#### Динамичен масив от обекти
-```c++
-class A;
-int main()
-{
- A* arr = new A[5]; //5 def constr.
- delete[] arr; //5 destr
-}
- ```
-Създава **динамичен** масив с 5 обекта от тип A. На всеки от тях се е извикал конструктора по подразбиране.
-Масивът ще се изтрие (и ще се изтрият обектите), когато се извика delete[] върху него.
-
-#### Динамичен масив от указатели към обекти
-```c++
-class A;
-int main()
-{
- A** arr = new A*[5]; //5 empty pointers.
-
- arr[0] = new A(); //def constr.
- arr[2] = new A(); //def constr.
-
- delete arr[0]; //destr.
- delete arr[2]; //destr.
-
- delete[] arr;
-}
- ```
- Създава **динамичен** масив с 5 указателя . Само на 2 от тези указатели присвояваме обекти, които са заделени в динамичната памет.
-Масивът ще се изтрие (и ще се изтрият обектите), когато се извика delete[] върху него.
-
-
-
-## Задачи
-
-**Задача 1:**
-Трябва да реализирате библиотека за работа с факултатитен курс.
-Курсът ще има преподаватели - лектор и асистенти - имената им се приемат като параметри.
-Асистентите могат да са най-много 3.
-
-**Пример**:
- ```c++
-int main()
-{
- OOPcourse p("Lecturer1", "Assistant1");
-
- p.addStudent("Ivan Petrov", 45123);
- p.addStudent("Aleksandur Mironov", 45123);
- p.addStudent("Stefan Popov", 45123);
-
- p.addGrade(45123, "HW1", 4, "Assistant1");
- p.addGrade(45222, "HW1", 6, "Lecturer1");
- p.addGrade(45222, "K1", 5, "Assistant1");
-
- p.getAverage("HW1"); // 4.5;
-
- p.removeStudent(45123);
-
- p.getAverageGradePerTask("HW1"); // 5;
-
- p.getAverageFromTeacher("Lecturer1"); //6
-
-}
- ```
-Функционални изисквания:
- - Всеки студент трябва да има най-много една оценка за дадено задание.
- - Записана оценка за дадено задание може да се променя, но не може да се изтрива!
- - Във всеки момент трябва да може да се види каква е средната оценка, която е написал лекторът или асистентът.
- - Студент може да има най-много 20 оценки.
- - Студентите имат имена с макс дължина 30 символа.
-
-
- **Задача 2:**
- Релизирайте клас стринг, който ще се ползва за работа със символни низове. Стрингът трябва да има като минимум следния интерфейс:
-
-
- - Конструктор по подразбиране (по поразбиране ще е празният низ)
- - Конструктор, който приема константен указател към масив от символи.
- - Член-функция, която приема друг стринг и връща дали е подстринг на текущия.
- - Член-функция, която приема цяло число k и връща подстринг на текущия, но започващ от k-ти символ
- - Член-функция, която приема две цели числа k и t и връща подстринг на текущия, но започващ от k-ти символ и завършващ на t-ти символ.
- - Предефиниран оператор [] за достъп до произвол символ.
-- Предефиниран оператори + и += за конкатенация на стрингове.
-- Предефиниран оператор *, който приема стринг и цяло число k и мултиплицира съдържаниято на стринга k пъти.
-- Предефинирани оператори << и >>.
-- Предефинирани опратори за сравнение (<, >, <=, >=, ==, !=). Стринговете да се сравняват лексикографско!
-
-**Пример**:
- ```c++
-int main()
-{
- myString s1; // ""
- myString s2("Test");
-
- s2.substr(2); // st
-
- s2.substr(1,2); // es
-
- s1 = "pronto";
-
- s2.contains(s1); //false
-
- myString s3 = s1 + s2; // prontoTest
-
- s3 *= 3; //prontoTestprontoTestprontoTest
-
- cin >> s3;
- cout << s3 << endl;
-
- s3 == s1; //false;
-}
- ```
diff --git a/Sem. 09/task1 (not finished)/Grade.cpp b/Sem. 09/task1 (not finished)/Grade.cpp
deleted file mode 100644
index 4302166..0000000
--- a/Sem. 09/task1 (not finished)/Grade.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-#include "Grade.h"
-
-
-Grade::Grade() : taskName(nullptr)
-{
- setTaskName("Unknown");
- setGrade(2);
-}
-
-Grade::Grade(const char* taskName, size_t gradeValue) : taskName(nullptr)
-{
- setTaskName(taskName);
- setGrade(gradeValue);
-}
-
-void Grade::free()
-{
- delete[] taskName;
-}
-void Grade::copyFrom(const Grade& other)
-{
- gradeValue = other.gradeValue;
-
- taskName = new char[strlen(other.taskName) + 1];
- strcpy(taskName, other.taskName);
-}
-
-Grade::Grade(const Grade& other)
-{
- copyFrom(other);
-}
-
-Grade& Grade::operator=(const Grade& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
-}
-Grade::~Grade()
-{
- free();
-}
-
-const char* Grade::getTaskName() const
-{
- return taskName;
-}
-size_t Grade::getGrade() const
-{
- return gradeValue;
-}
-
-void Grade::setGrade(size_t grade)
-{
- if (grade < 2 || grade > 6)
- throw std::exception("error!");
-
- gradeValue = grade;
-}
-
-void Grade::setTaskName(const char* name)
-{
- delete[] taskName;
- taskName = new char[strlen(name) + 1];
- strcpy(taskName, name);
-} \ No newline at end of file
diff --git a/Sem. 09/task1 (not finished)/Grade.h b/Sem. 09/task1 (not finished)/Grade.h
deleted file mode 100644
index d0cb2e7..0000000
--- a/Sem. 09/task1 (not finished)/Grade.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#pragma once
-
-#include <iostream>
-
-class Grade
-{
- size_t gradeValue;
- char* taskName;
-
- void free();
- void copyFrom(const Grade& other);
-public:
- Grade();
-
- Grade(const char* taskName, size_t gradeValue);
-
- Grade(const Grade& other);
- Grade& operator=(const Grade& other);
- ~Grade();
-
- const char* getTaskName() const;
- size_t getGrade() const;
-
- void setTaskName(const char* name);
- void setGrade(size_t grade);
-}; \ No newline at end of file
diff --git a/Sem. 09/task1 (not finished)/Student.cpp b/Sem. 09/task1 (not finished)/Student.cpp
deleted file mode 100644
index 99d26dc..0000000
--- a/Sem. 09/task1 (not finished)/Student.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-#include "Student.h"
-
-Student::Student(const char* name, size_t fn)
-{
- setName(name);
- setFn(fn);
-}
-
-void Student::setFn(size_t fn)
-{
- if (fn < 80000 || fn > 83000)
- throw std::exception("Invalid fn");
-
- this->fn = fn;
-}
-void Student::setName(const char* name)
-{
- if (strlen(name) > MAX_NAME_LENGTH)
- throw std::exception("Name is too long!");
-
- strcpy(this->name, name);
-}
-
-size_t Student::getFN() const
-{
- return fn;
-}
-const char* Student::getName() const
-{
- return name;
-}
-
-void Student::addGrade(const char* taskName, size_t grade)
-{
- if (gradesCount == MAX_GRADES_COUNT)
- throw std::exception("Error! Too many grades!");
-
- Grade currentGrade(taskName, grade);
- grades[gradesCount++] = currentGrade;
-}
-
-void Student::print() const
-{
- std::cout << name << " " << fn << std::endl;
-} \ No newline at end of file
diff --git a/Sem. 09/task1 (not finished)/Student.h b/Sem. 09/task1 (not finished)/Student.h
deleted file mode 100644
index 5c09792..0000000
--- a/Sem. 09/task1 (not finished)/Student.h
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "Grade.h"
-
-const size_t MAX_NAME_LENGTH = 30;
-const size_t MAX_GRADES_COUNT = 20;
-class Student
-{
-public:
-
- Student(const char* name, size_t fn);
-
- void setFn(size_t fn);
- void setName(const char* name);
-
- size_t getFN() const;
- const char* getName() const;
-
- void addGrade(const char* taskName, size_t grade);
-
-
- void print() const;
-private:
- char name[MAX_NAME_LENGTH + 1];
- size_t fn;
-
- Grade grades[MAX_GRADES_COUNT];
- size_t gradesCount;
-
-
-}; \ No newline at end of file
diff --git a/Sem. 09/task1 (not finished)/UniCourse.cpp b/Sem. 09/task1 (not finished)/UniCourse.cpp
deleted file mode 100644
index c854b82..0000000
--- a/Sem. 09/task1 (not finished)/UniCourse.cpp
+++ /dev/null
@@ -1,135 +0,0 @@
-#include "UniCourse.h"
-
-UniCourse::UniCourse(const char* lecturerName) : UniCourse(lecturerName, "", "", "")
-{}
-UniCourse::UniCourse(const char* lecturerName, const char* assistant1Name) : UniCourse(lecturerName, assistant1Name, "", "")
-{}
-UniCourse::UniCourse(const char* lecturerName, const char* assistant1Name, const char* assistant2Name) : UniCourse(lecturerName, assistant1Name, assistant2Name, "")
-{}
-
-UniCourse::UniCourse(const char* lecturerName, const char* assistant1Name, const char* assistant2Name, const char* assistant3Name)
-{
- this->lecturerName = new char[strlen(lecturerName) + 1];
- strcpy(this->lecturerName, lecturerName);
-
- assistantsNames[0] = new char[strlen(assistant1Name) + 1];
- strcpy(assistantsNames[0], assistant1Name);
-
- assistantsNames[1] = new char[strlen(assistant2Name) + 1];
- strcpy(assistantsNames[1], assistant2Name);
-
- assistantsNames[2] = new char[strlen(assistant3Name) + 1];
- strcpy(assistantsNames[2], assistant3Name);
-
- capacity = 8;
- size = 0;
-
- students = new Student*[capacity];
-}
-
-
-void UniCourse::copyFrom(const UniCourse& other)
-{
- lecturerName = new char[strlen(other.lecturerName) + 1];
- strcpy(lecturerName, other.lecturerName);
-
- for (int i = 0; i < 3; i++)
- {
- if (other.assistantsNames[i] != nullptr)
- {
- assistantsNames[i] = new char[strlen(other.assistantsNames[i]) + 1];
- strcpy(assistantsNames[i], other.assistantsNames[i]);
- }
- }
-
-
- students = new Student*[other.capacity];
-
- for (int i = 0; i < other.size; i++)
- students[i] = new Student(*other.students[i]);
-
- capacity = other.capacity;
- size = other.size;
-
-}
-void UniCourse::free()
-{
- delete[] lecturerName;
-
- for (int i = 0; i < 3; i++)
- delete[] assistantsNames[i];
-
- for (int i = 0; i < size; i++)
- delete students[i];
-
- delete[] students;
-}
-
-UniCourse::UniCourse(const UniCourse& other)
-{
- copyFrom(other);
-}
-
-UniCourse& UniCourse::operator=(const UniCourse& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
-}
-UniCourse::~UniCourse()
-{
- free();
-}
-void UniCourse::addStudent(const char* name, size_t fn)
-{
- if (size == capacity)
- resize();
-
- Student* current = new Student(name, fn);
- students[size++] = current;
-}
-
-void UniCourse::resize()
-{
- Student** temp = new Student*[capacity *= 2];
-
- for (int i = 0; i < size; i++)
- temp[i] = students[i];
-
- delete[] students;
-
- students = temp;
-}
-
-size_t UniCourse::findStudentByFn(size_t fn)
-{
- for (int i = 0; i < size; i++)
- {
- if (students[i]->getFN() == fn)
- return i;
- }
- return -1;
-}
-void UniCourse::removeStudent(size_t fn)
-{
- size_t indexOfStudent = findStudentByFn(fn);
- if (fn == -1)
- return;
-
- delete students[indexOfStudent];
-
- for (int i = indexOfStudent; i < size - 1; i++)
- students[i] = students[i + 1];
-
- size--;
-
-}
-
-void UniCourse::print()
-{
- for (int i = 0; i < size; i++)
- students[i]->print();
-} \ No newline at end of file
diff --git a/Sem. 09/task1 (not finished)/UniCourse.h b/Sem. 09/task1 (not finished)/UniCourse.h
deleted file mode 100644
index fde1518..0000000
--- a/Sem. 09/task1 (not finished)/UniCourse.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "Student.h"
-
-class UniCourse
-{
- char* lecturerName;
- char* assistantsNames[3];
-
- Student** students;
- size_t capacity;
- size_t size;
-
- void copyFrom(const UniCourse& other);
- void free();
-
- size_t findStudentByFn(size_t fn);
-
- void resize();
-
-public:
- UniCourse(const char* lecturerName);
- UniCourse(const char* lecturerName, const char* assistant1Name);
- UniCourse(const char* lecturerName, const char* assistant1Name, const char* assistant2Name);
- UniCourse(const char* lecturerName, const char* assistant1Name, const char* assistant2Name, const char* assistant3Name);
-
-
- UniCourse(const UniCourse& other);
- UniCourse& operator=(const UniCourse& other);
- ~UniCourse();
-
- void addStudent(const char* name, size_t fn);
- void removeStudent(size_t fn);
-
- void print();
-
-}; \ No newline at end of file
diff --git a/Sem. 09/task1 (not finished)/main.cpp b/Sem. 09/task1 (not finished)/main.cpp
deleted file mode 100644
index 6b727fa..0000000
--- a/Sem. 09/task1 (not finished)/main.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "UniCourse.h"
-
-int main()
-{
- UniCourse u("ddz");
-
- u.addStudent("ivan", 80123);
- u.addStudent("angel", 80125);
- u.addStudent("petur", 80126);
- u.addStudent("ivan2", 81000);
- //u.print();
-
- u.removeStudent(80125);
- u.print();
-} \ No newline at end of file
diff --git a/Sem. 10/README.md b/Sem. 10/README.md
deleted file mode 100644
index 40d6502..0000000
--- a/Sem. 10/README.md
+++ /dev/null
@@ -1,70 +0,0 @@
-## Шаблони
-Функция/клас, която работи не с променливи от някакъв дефиниран тип, а с абстрактни променливи, се нарича шаблонна функция/клас
-```c++
-#include <iostream>
-using namespace std;
-
-template <class T>
-T sum(T a, T b)
-{
- return a + b;
-}
-
-int main()
-{
- int a = 4;
- int b = 9;
- cout << sum<int>(a, b) << endl;
-
- double c = 3.14;
- double d = 4.5;
- cout << sum<double>(c,d) << endl;
-
- return 0;
-}
-```
-Компилаторът генерира т. нар. шаблонна функция, като замества параметрите на шаблона с типовете на съответните фактически параметри.
-
-**Задача 1:**
-Релизирайте структурата от данни опашка. Опашката трябва да работи с **произволни типове**. След като е добавен един елемент в края на опашката, той ще може да бъде извлечен (премахнат) единствено след като бъдат премахнати всички елементи преди него в реда, в който са добавени.
-
-**Пример**:
- ```c++
-int main()
-{
- quene<int> q;
- q.enqueue(3);
- q.enqueue(5);
- q.enqueue(10);
-
- cout << q.dequeue() << endl; //3
- cout << q.dequeue() << endl; //5
- cout << q.dequeue() << endl; //10
-
- cout << q.isEmpty() << endl; //1
-}
- ```
- **Задача 2:**
- Създайте **шаблонна** опашка с k приоритета. При взимане на елемент от опашката трябва да се връща най-отдавна добавения елемент от тези с най-висок приоритет.
-
- ```c++
-int main()
-{
- kPriorityQueue<char> q(4); // 4 priorities - 0, 1, 2 и 3.
-
- q.enqueue('A',0): //adds A with lowest priority: 0
- q.enqueue('B',3);
- q.enqueue('C',2);
- q.enqueue('D',2);
- q.enqueue('E',1);
-
- //q.enqueue('F', 5); //error! No such priority!
-
- q.dequeue(); // B
- q.dequeue(); // C
- q.dequeue(); // D
- q.dequeue(); // E
- q.dequeue(); // A
-}
- ```
-
diff --git a/Sem. 10/task1/Queue.hpp b/Sem. 10/task1/Queue.hpp
deleted file mode 100644
index 1f7f854..0000000
--- a/Sem. 10/task1/Queue.hpp
+++ /dev/null
@@ -1,144 +0,0 @@
-#include <iostream>
-
-template <typename T>
-class Queue
-{
- T* data;
- size_t capacity;
- size_t count;
-
- size_t head; //where to get
- size_t tail; //last added element;
-
- void resize(size_t newCapacity);
-
- void copyFrom(const Queue<T>& other);
- void free();
-public:
- Queue();
-
- Queue(const Queue<T>& other);
- Queue<T>& operator=(const Queue<T>& other);
-
- void enqueue(const T& obj);
- T dequeue();
-
- size_t getCount();
- size_t isEmpty();
-
- ~Queue();
-};
-
-template <typename T>
-Queue<T>::Queue()
-{
- capacity = 4;
- data = new T[capacity];
-
- count = 0;
- head = tail = 0;
-}
-
-
-
-template <typename T>
-void Queue<T>::enqueue(const T& obj)
-{
- if (count == capacity)
- resize(capacity * 2);
- if (count != 0)
- tail++;
-
- tail %= capacity; //so we don't get an out of range exception
-
- data[tail] = obj;
-
- count++;
-}
-
-template <typename T>
-T Queue<T>::dequeue()
-{
- if (count == 0)
- throw std::exception("The collection is empty!");
-
- T toReturn = data[head];
- (++head) %= capacity;
-
- count--;
-
- return toReturn;
-}
-
-template <typename T>
-size_t Queue<T>::getCount()
-{
- return count;
-}
-
-template <typename T>
-size_t Queue<T>::isEmpty()
-{
- return getCount() == 0;
-}
-
-template <typename T>
-void Queue<T>::resize(size_t newCapacity)
-{
- T* newData = new T[newCapacity];
-
- for (int i = 0, ind = head; i < count; i++, (++ind) %= capacity)
- newData[i] = data[ind];
-
- delete[] data;
- capacity = newCapacity;
- data = newData;
-
- head = 0;
- tail = count - 1;
-}
-
-template <typename T>
-void Queue<T>::copyFrom(const Queue<T>& other)
-{
- data = new T[other.capacity];
- for (int i = 0; i < other.capacity; i++)
- data[i] = other.data[i];
-
- head = other.head;
- tail = other.tail;
-
- count = other.count;
- capacity = other.capacity;
-
-}
-
-template <typename T>
-void Queue<T>::free()
-{
- delete[] data;
-}
-
-template <typename T>
-Queue<T>::Queue(const Queue<T>& other)
-{
- copyFrom(other);
-
-}
-
-template <typename T>
-Queue<T>& Queue<T>::operator=(const Queue<T>& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
-}
-
-template <typename T>
-Queue<T>::~Queue()
-{
- free();
-}
diff --git a/Sem. 10/task1/main.cpp b/Sem. 10/task1/main.cpp
deleted file mode 100644
index e52579a..0000000
--- a/Sem. 10/task1/main.cpp
+++ /dev/null
@@ -1,23 +0,0 @@
-#include <iostream>
-#include "Queue.hpp"
-using namespace std;
-
-
-
-int main()
-{
- Queue<char> q;
-
- q.enqueue('A');
- q.enqueue('B');
- q.enqueue('C');
- q.enqueue('D');
- cout << q.dequeue() << endl;
- q.enqueue('E');
- q.enqueue('F');
- cout << q.dequeue() << endl;
- cout << q.dequeue() << endl;
- cout << q.dequeue() << endl;
- cout << q.dequeue() << endl;
- cout << q.dequeue() << endl;
-} \ No newline at end of file
diff --git a/Sem. 11/README.md b/Sem. 11/README.md
deleted file mode 100644
index 485b956..0000000
--- a/Sem. 11/README.md
+++ /dev/null
@@ -1,129 +0,0 @@
-# Move семантики
-#### Подаване на стойност по референция
-```c++
-#include <iostream>
-using namespace std;
-
-void f(int& n)
-{
- cout << n << endl;
-}
-int main()
-{
- int number = 10;
- f(number); // OK!
- f(3); // Error!
-}
- ```
-"Висящата" константа 3 **няма адрес в паметта**. За това подаването и като параметър на функцията f ще доведе до компилационна грешка.
-
-**&&** - за стойности без адрес в паметта
-```c++
-#include<iostream>
-using namespace std;
-
-void f(int& n)
-{
- cout << n << endl;
-}
-int main()
-{
- int number = 10;
- f(number); // OK!
- f(3); // Error!
-}
- ```
-
-#### Пример за използването на &&
-```c++
-#include<iostream>
-using namespace std;
-
-void f(int&& n)
-{
- cout << n << endl;
-}
-int main()
-{
- int number = 10;
- f(number); // Error!
- f(3); // OK!
-}
- ```
-Тук грешката възниква при подаването на променлива, която **има адрес в паметта.**
-#### lvalue и rvalue
-
- - **lvalue** - обект, който заема някакво конкретно място в паметта. (стойността в паметта може да се модифицира)
- - **rvalue** - обект, който не е *lvalue* .
-
-
-#### Излишни копия?
-Да разгледаме следният програмен фрагмент:
-
-```c++
-#include<iostream>
-#include<iostream>
-#include "Person.h"
-using namespace std;
-
-Person createPerson(const char* name, int age)
-{
- Person p(name, age);
-
- return p;
-}
-
-int main()
-{
- Person p2("Petur",18);
- p2 = createPerson("Ivan", 23);
-}
- ```
-Тук се изпълняват следните функции на Person:
-
- 1. Конструктор на Person (за p2)
- 2. Конструктор за Person (на p).
- 3. Копиращ конструктор (за *return p*)
- 4. Деструктор (в края на функцията *createPerson*)
- 5. Оператор = (за *p2 = create...* )
- 6. Деструктор (в края на функцията *main*)
-
-Проблемът тук е, че правим излишни копия. Обектът създаден в *createPerson* **се копира два пъти докато се присвои** на p2.
-#### Move конструктор и move оператор =.
-За да избегнем излишните копия, може да "преместим" данните на обектът, който се създава във функцията, в данните на p2.
-```c++
-
-//Move constructor
-Person::Person(Person&& rhs)
-{
- name = rhs.name;
- age = rhs.age;
-
- rhs.name = nullptr;
-}
-
-//Move operator=
-Person& Person::operator=(Person&& rhs)
-{
- if (this != &rhs)
- {
- free();
-
- name = rhs.name;
- rhs.name = nullptr;
- }
- return *this;
-}
- ```
-
- Важно е да се обърне внимание, че тук данните **не се копират**, а се **местят**. Т.е приемаме, че rhs **няма да се използва след изпълнението на функцията.**
- Сега при изпълнението на първоначално разгледания код:
- 1. Конструктор на Person (за p2)
- 2. Конструктор за Person (на p).
- 3. **Move конструктор** (за *return p*)
- 4. Деструктор (в края на функцията *createPerson*)
- 5. **Move oператор =** (за *p2 = create...* )
- 6. Деструктор (в края на функцията *main*)
-
-
-Т.е тук си спестихме 2 копия за динамичната памет в Person.
diff --git a/Sem. 11/example/Person.cpp b/Sem. 11/example/Person.cpp
deleted file mode 100644
index ae78280..0000000
--- a/Sem. 11/example/Person.cpp
+++ /dev/null
@@ -1,99 +0,0 @@
-#include "Person.h"
-#include <iostream>
-
-using namespace std;
-
-Person::Person() : Person("Unknown", 0)
-{
-
-}
-Person::Person(const char* name, int age) : name(nullptr), age(age)
-{
- cout << "Constr" << endl;
- setName(name);
- setAge(age);
-}
-
-Person::Person(const Person& other)
-{
- cout << "copy constr" << endl;
- copyFrom(other);
-}
-Person::Person(Person&& other)
-{
- cout << "Move constr" << endl;
-
- name = other.name;
- age = other.age;
-
- other.name = nullptr;
-}
-
-Person& Person::operator=(Person&& other)
-{
-
- std::cout << "Move op= " << endl;
- if (this != &other)
- {
- free();
-
- name = other.name;
- other.name = nullptr;
-
- age = other.age;
-
- }
- return *this;
-}
-
-Person& Person::operator = (const Person& other)
-{
- cout << "op =" << endl;
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
-}
-Person::~Person()
-{
- cout << "Destructor" << endl;
- free();
-}
-
-const char* Person::getName() const
-{
- return name;
-}
-
-int Person::getAge() const
-{
- return age;
-}
-
-void Person::setName(const char* name)
-{
- delete[] this->name;
- this->name = new char[strlen(name) + 1];
- strcpy(this->name, name);
-}
-void Person::setAge(int age)
-{
- if (age < 0 || age > 120)
- age = 40;
- this->age = age;
-}
-
-void Person::copyFrom(const Person& other)
-{
- name = new char[strlen(other.name) + 1];
- strcpy(name, other.name);
-
- age = other.age;
-}
-void Person::free()
-{
- delete[] name;
- age = 0;
-} \ No newline at end of file
diff --git a/Sem. 11/example/Person.h b/Sem. 11/example/Person.h
deleted file mode 100644
index 9a404c4..0000000
--- a/Sem. 11/example/Person.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#pragma once
-
-class Person
-{
-public:
- Person();
- Person(const char* name, int age);
-
- Person(const Person& other);
-
- Person(Person&& other); //move constr
-
- Person& operator=(Person&& other); // move op=
-
- Person& operator=(const Person& other);
- ~Person();
-
- void setName(const char* name);
- void setAge(int age);
-
- const char* getName() const;
- int getAge() const;
-
- void print();
-
-
-private:
-
- void copyFrom(const Person& other);
- void free();
-
-
- char* name;
- int age;
-}; \ No newline at end of file
diff --git a/Sem. 11/example/main.cpp b/Sem. 11/example/main.cpp
deleted file mode 100644
index 80fef69..0000000
--- a/Sem. 11/example/main.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#include<iostream>
-#include<iostream>
-#include "Person.h"
-using namespace std;
-
-Person createPerson(const char* name, int age)
-{
- Person p(name, age);
-
- return std::move(p);
-}
-
-int main()
-{
- Person p2("Petur",18);
- p2 = createPerson("Ivan", 23);
-}
diff --git a/Sem. 12/README.md b/Sem. 12/README.md
deleted file mode 100644
index 5c13eba..0000000
--- a/Sem. 12/README.md
+++ /dev/null
@@ -1,190 +0,0 @@
-
-# Наследяване
-## Пример за наследяване
-
-При създаване на нов клас, който има общи компоненти и поведение с вече дефиниран клас, вместо да дефинира повторно тези компоненти и поведение, можем да го обявим за наследник на вече дефинирания.
-
-```c++
-class A
-{
- .
- .
- .
-public:
- void f()
- {
- .
- .
- .
- }
- .
- .
- .
-};
-class B : public A
-{
- .
- .
- .
-}
-
-int main()
-{
- B obj;
- obj.f(); // OK!
-}
- ```
- При наследяването:
- - Наследяват се член-данните и методите на основните класове
- - Получава се достъп до **някои** от наследените компоненти на основните класове
-
-
-В нашия пример класът **В е наследник на класа А.** Обекти от класовете изглеждат така:
-
-![enter image description here](https://i.ibb.co/Fshm2LJ/Untitled-Diagram.png)
-
-
-След като В е наследник на класа А, то при създаване на обект от тип В се създава обект от тип А, **който е част от обекта** от тип В.
-
-
-## Видове наследяване
-Някои типове наследяване в c++:
-
- - private (по подразбиране)
- - protected
- - public
-
-Примери:
-```c++
-class A
-{
- public:
- int x;
- protected:
- int y;
- private:
- int z;
-};
-
-class B : public A
-{
- // x is public
- // y is protected
- // z is not accessible from B
-};
-
-class C : protected A
-{
- // x is protected
- // y is protected
- // z is not accessible from C
-};
-
-class D : private A // 'private' is default for classes
-{
- // x is private
- // y is private
- // z is not accessible from D
-};
- ```
-
-## Подаване като параметри на функции.
-Класове-наследници могат да бъдат подавани като параметри на функции, които приемат обекти от базовия клас. Може да се използва функционалността само от базовия клас.
-
-```c++
-class A
-{
- int a;
-}
-class B : public A
-{
-public:
- int b;
-}
-void f(A& obj)
-{
- obj.a++;
-}
-
-int main()
-{
- A obj1;
- B obj2;
-
- f(obj1); //OK!
- f(obj2); //OK!
-}
- ```
-
-## Конструктури и деструктори при наследяване.
-Във всеки контструктор на класът-наследник, трябва да се оказва кой конструктор да се извика за базовия клас. Ако не оказано, ще се извика конструктора по подразбиране.
-
-```c++
-class B : public A
-{
-.
-.
-.
-public:
- B(...) : A(...) //some constructor of A.
- {
- .
- .
- .
- }
-}
- ```
-Деструкторът на наследния клас извиква деструктора на базовия клас.
-
-
-## Копиране при наследяване
-При разписване на конструктора за копиране и оператора за присовяване на клас-наследник, трябва експлицитно да извикваме копиране и за базовия клас.
- ```c++
-B::B(const B& other) : A(other) // (copy constructor of A (base class)
-{
- copyFrom(other);
-}
-
-B& B::operator=(const B& other)
-{
-
- if (this != &other)
- {
- A::operator=(other); //operator= of A (base class)
- free();
- copyFrom(other);
- }
- return *this;
-}
- ```
-
-
-
-
-## Задачи
-
-**Задача 1:**
-Реализирайте класове бар, от който ще могат да се взимат напитки (нормални и алкохолни) в определен ред. Редът ще бъде по зареждането им в бара.
-**Напитката** има *име и количество (в мл)*, а **алкохолната напитка** има *име, количество и процент алкохол.*
-
-Примерен интерфейс:
- ```c++
-
-int main()
-{
- Bar b;
-
- b.addDrink("Coke", 330);
-
- b.addDrink("Fanta", 500);
-
- b.addAlocoholDrink("Zagorka", 500, 5);
-
- b.getAcloholDrink(); // Zagorka
-
- b.getDrink() // Coke
- b.getDrink() // Fanta
-}
- ```
-
-
diff --git a/Sem. 12/task1/Bar/Bar.cpp b/Sem. 12/task1/Bar/Bar.cpp
deleted file mode 100644
index 0235801..0000000
--- a/Sem. 12/task1/Bar/Bar.cpp
+++ /dev/null
@@ -1,45 +0,0 @@
-#include "Bar.h"
-
-void Bar::addDrink(const char* name, int ml)
-{
- drinks.enqueue(Drink(name, ml));
-}
-void Bar::addAlocoholDrink(const char* name, int ml, int alcohol)
-{
- alcoholDrinks.enqueue(AlcoholDrink(name, ml, alcohol));
-}
-
-Drink Bar::getDrink()
-{
- Drink d = drinks.dequeue();
- incrementStatistics(d);
- return d;
-}
-AlcoholDrink Bar::getAcloholDrink()
-{
- AlcoholDrink d = alcoholDrinks.dequeue();
- incrementStatistics(d, true);
- return d;
-}
-
-void Bar::incrementStatistics(const Drink& dr, bool isAlcoholDrink)
-{
- stats.mlSold += dr.getMl();
- stats.allDrinksSold++;
-
- if (isAlcoholDrink)
- stats.alcoholDrinksSold++;
-}
-
-size_t Bar::getMlSold() const
-{
- return stats.mlSold;
-}
-size_t Bar::getAllDrinksSold() const
-{
- return stats.allDrinksSold;
-}
-size_t Bar::getAlcoholDrinksSold() const
-{
- return stats.alcoholDrinksSold;
-}
diff --git a/Sem. 12/task1/Bar/Bar.h b/Sem. 12/task1/Bar/Bar.h
deleted file mode 100644
index 06e7d92..0000000
--- a/Sem. 12/task1/Bar/Bar.h
+++ /dev/null
@@ -1,36 +0,0 @@
-#pragma once
-#include <iostream>
-#include "../Drinks/AlcoholDrink.h"
-#include "../Queue/Queue.hpp"
-
-
-
-class Bar
-{
- struct Statistics
- {
- size_t mlSold = 0;
- size_t allDrinksSold = 0;
- size_t alcoholDrinksSold = 0;
- };
-
-private:
- Queue<Drink> drinks;
- Queue<AlcoholDrink> alcoholDrinks;
-
- Statistics stats;
-
- void incrementStatistics(const Drink& dr, bool isAlcoholDrink = false);
-
-public:
-
- void addDrink(const char* name, int ml);
- void addAlocoholDrink(const char* name, int ml, int alcohol);
-
- Drink getDrink();
- AlcoholDrink getAcloholDrink();
-
- size_t getMlSold() const;
- size_t getAllDrinksSold() const;
- size_t getAlcoholDrinksSold() const;
-};
diff --git a/Sem. 12/task1/Drinks/AlcoholDrink.cpp b/Sem. 12/task1/Drinks/AlcoholDrink.cpp
deleted file mode 100644
index 4171ff0..0000000
--- a/Sem. 12/task1/Drinks/AlcoholDrink.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#pragma warning(disable: 4996)
-#include "AlcoholDrink.h"
-
-AlcoholDrink::AlcoholDrink() : AlcoholDrink("Unknown", 0, 0){}
-
-AlcoholDrink::AlcoholDrink(const char* name, int ml, int alcoholPercentage) : Drink(name, ml)
-{
- setAlcoholPercentage(alcoholPercentage);
-}
-int AlcoholDrink::getAlcoholPercentage() const
-{
- return alcoholPercentage;
-}
-void AlcoholDrink::setAlcoholPercentage(int alcoholPercentage)
-{
- const int MINPERCENTAGE = 1;
- const int MAXPERCENTAGE = 97;
-
- this->alcoholPercentage = MINPERCENTAGE;
-
- if (MINPERCENTAGE <= alcoholPercentage && alcoholPercentage <= MAXPERCENTAGE)
- this->alcoholPercentage = alcoholPercentage;
-
-} \ No newline at end of file
diff --git a/Sem. 12/task1/Drinks/AlcoholDrink.h b/Sem. 12/task1/Drinks/AlcoholDrink.h
deleted file mode 100644
index 89b2da3..0000000
--- a/Sem. 12/task1/Drinks/AlcoholDrink.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-
-#include "Drink.h"
-
-class AlcoholDrink : public Drink
-{
- int alcoholPercentage;
-
-public:
- AlcoholDrink();
- AlcoholDrink(const char* name, int ml, int alcoholPercentage);
-
- int getAlcoholPercentage() const;
- void setAlcoholPercentage(int alcoholPercentage);
-}; \ No newline at end of file
diff --git a/Sem. 12/task1/Drinks/Drink.cpp b/Sem. 12/task1/Drinks/Drink.cpp
deleted file mode 100644
index 55b3e3a..0000000
--- a/Sem. 12/task1/Drinks/Drink.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-#pragma warning(disable: 4996)
-#include "Drink.h"
-#include <iostream>
-
-Drink::Drink() : Drink("Unknown", 0)
-{}
-const char* Drink::getName() const
-{
- return name;
-}
-int Drink::getMl() const
-{
- return ml;
-}
-
-void Drink::setName(const char* name)
-{
- delete[] this->name;
-
- this->name = new char[strlen(name) + 1];
- strcpy(this->name, name);
-
-}
-void Drink::setMl(int ml)
-{
- const int MAX_ML = 1000;
- const int MIN_ML = 100;
-
- ml = MIN_ML;
- if (MIN_ML <= ml && ml <= MAX_ML)
- this->ml = ml;
-
-}
-
-Drink::Drink(const char* name, int ml) : name(nullptr)
-{
- setName(name);
- setMl(ml);
-}
-
-Drink::Drink(const Drink& other)
-{
- copyFrom(other);
-}
-Drink& Drink::operator = (const Drink& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
-}
-Drink::~Drink()
-{
- free();
-}
-void Drink::copyFrom(const Drink& other)
-{
- name = new char[strlen(other.name) + 1];
- strcpy(name, other.name);
-
- ml = other.ml;
-}
-void Drink::free()
-{
- delete[] name;
- ml = 0;
-} \ No newline at end of file
diff --git a/Sem. 12/task1/Drinks/Drink.h b/Sem. 12/task1/Drinks/Drink.h
deleted file mode 100644
index d4d37ae..0000000
--- a/Sem. 12/task1/Drinks/Drink.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#pragma once
-
-class Drink
-{
-public:
- Drink();
-
- Drink(const char* name, int ml);
-
- Drink(const Drink& other);
- Drink& operator=(const Drink& other);
- ~Drink();
-
- const char* getName() const;
- int getMl() const;
-
- void setName(const char* name);
- void setMl(int ml);
-
-private:
- char* name;
- int ml;
-
- void copyFrom(const Drink& other);
- void free();
-
-}; \ No newline at end of file
diff --git a/Sem. 12/task1/Drinks/EnergyDrink.cpp b/Sem. 12/task1/Drinks/EnergyDrink.cpp
deleted file mode 100644
index ef61456..0000000
--- a/Sem. 12/task1/Drinks/EnergyDrink.cpp
+++ /dev/null
@@ -1,49 +0,0 @@
-#pragma warning(disable: 4996)
-#include "EnergyDrink.h"
-#include <iostream>
-
-EnergyDrink::EnergyDrink(const char* name, int ml, const char* sertificate) : Drink(name, ml), qualityCertificate(nullptr)
-{
- setCertificate(sertificate);
-}
-const char* EnergyDrink::getCertifiate() const
-{
- return qualityCertificate;
-}
-void EnergyDrink::setCertificate(const char* certficate)
-{
- delete[] qualityCertificate;
-
- qualityCertificate = new char[strlen(certficate) + 1];
- strcpy(qualityCertificate, certficate);
-
-}
-EnergyDrink::EnergyDrink(const EnergyDrink& other) : Drink(other)
-{
- copyFrom(other);
-}
-
-EnergyDrink& EnergyDrink::operator=(const EnergyDrink& other)
-{
- if (this != &other)
- {
- Drink::operator=(other);
- free();
- copyFrom(other);
- }
- return *this;
-}
-
-EnergyDrink::~EnergyDrink()
-{
- free();
-}
-void EnergyDrink::copyFrom(const EnergyDrink& other)
-{
- qualityCertificate = new char[strlen(other.qualityCertificate) + 1];
- strcpy(qualityCertificate, other.qualityCertificate);
-}
-void EnergyDrink::free()
-{
- delete[] qualityCertificate;
-} \ No newline at end of file
diff --git a/Sem. 12/task1/Drinks/EnergyDrink.h b/Sem. 12/task1/Drinks/EnergyDrink.h
deleted file mode 100644
index 99bbbdb..0000000
--- a/Sem. 12/task1/Drinks/EnergyDrink.h
+++ /dev/null
@@ -1,22 +0,0 @@
-// име, мл, сертификат за качество.
-#pragma once
-#include "Drink.h"
-
-class EnergyDrink : public Drink
-{
-private:
- char* qualityCertificate;
-
- void copyFrom(const EnergyDrink& other);
- void free();
-
-public:
- EnergyDrink(const char* name, int ml, const char* certificate);
-
- EnergyDrink(const EnergyDrink& other);
- EnergyDrink& operator=(const EnergyDrink& other);
- ~EnergyDrink();
-
- const char* getCertifiate() const;
- void setCertificate(const char* certificate);
-}; \ No newline at end of file
diff --git a/Sem. 12/task1/Queue/Queue.hpp b/Sem. 12/task1/Queue/Queue.hpp
deleted file mode 100644
index e47460a..0000000
--- a/Sem. 12/task1/Queue/Queue.hpp
+++ /dev/null
@@ -1,145 +0,0 @@
-#pragma once
-#include <iostream>
-
-template <typename T>
-class Queue
-{
- T* data;
- size_t capacity;
- size_t count;
-
- size_t head; //where to get
- size_t tail; //last added element;
-
- void resize(size_t newCapacity);
-
- void copyFrom(const Queue<T>& other);
- void free();
-public:
- Queue();
-
- Queue(const Queue<T>& other);
- Queue<T>& operator=(const Queue<T>& other);
-
- void enqueue(const T& obj);
- T dequeue();
-
- size_t getCount();
- size_t isEmpty();
-
- ~Queue();
-};
-
-template <typename T>
-Queue<T>::Queue()
-{
- capacity = 4;
- data = new T[capacity];
-
- count = 0;
- head = tail = 0;
-}
-
-
-
-template <typename T>
-void Queue<T>::enqueue(const T& obj)
-{
- if (count == capacity)
- resize(capacity * 2);
- if (count != 0)
- tail++;
-
- tail %= capacity; //so we don't get an out of range exception
-
- data[tail] = obj;
-
- count++;
-}
-
-template <typename T>
-T Queue<T>::dequeue()
-{
- if (count == 0)
- throw std::exception("The collection is empty!");
-
- T toReturn = data[head];
- (++head) %= capacity;
-
- count--;
-
- return toReturn;
-}
-
-template <typename T>
-size_t Queue<T>::getCount()
-{
- return count;
-}
-
-template <typename T>
-size_t Queue<T>::isEmpty()
-{
- return getCount() == 0;
-}
-
-template <typename T>
-void Queue<T>::resize(size_t newCapacity)
-{
- T* newData = new T[newCapacity];
-
- for (int i = 0, ind = head; i < count; i++, (++ind) %= capacity)
- newData[i] = data[ind];
-
- delete[] data;
- capacity = newCapacity;
- data = newData;
-
- head = 0;
- tail = count - 1;
-}
-
-template <typename T>
-void Queue<T>::copyFrom(const Queue<T>& other)
-{
- data = new T[other.capacity];
- for (int i = 0; i < other.capacity; i++)
- data[i] = other.data[i];
-
- head = other.head;
- tail = other.tail;
-
- count = other.count;
- capacity = other.capacity;
-
-}
-
-template <typename T>
-void Queue<T>::free()
-{
- delete[] data;
-}
-
-template <typename T>
-Queue<T>::Queue(const Queue<T>& other)
-{
- copyFrom(other);
-
-}
-
-template <typename T>
-Queue<T>& Queue<T>::operator=(const Queue<T>& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
-}
-
-template <typename T>
-Queue<T>::~Queue()
-{
- free();
-}
diff --git a/Sem. 12/task1/main.cpp b/Sem. 12/task1/main.cpp
deleted file mode 100644
index ba367d8..0000000
--- a/Sem. 12/task1/main.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#pragma warning(disable: 4996)
-
-
-#include <iostream>
-#include "Bar/Bar.h"
-#include "Drinks/EnergyDrink.h"
-
-using namespace std;
-
-int main()
-{
- Bar b;
-
- b.addDrink("Coke", 330);
-
- b.addDrink("Fanta", 500);
-
- b.addAlocoholDrink("Zagorka", 500, 5);
-
- cout << b.getDrink().getName()<<endl;
- cout << b.getDrink().getName() << endl;
-
- cout << b.getAcloholDrink().getName() << endl;
-
- cout << b.getAllDrinksSold() << endl;
-
- EnergyDrink energyDrink("Monster", 500, "ECAS");
-
- std::cout << energyDrink.getCertifiate();
-}
diff --git a/Sem. 13/Figures/Circle.cpp b/Sem. 13/Figures/Circle.cpp
deleted file mode 100644
index 8226582..0000000
--- a/Sem. 13/Figures/Circle.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "Circle.h"
-
-const double PI = 3.1415;
-Circle::Circle(int x, int y, double radius) : Shape(1), radius(radius)
-{
- setPoint(0, x, y);
-}
-
-double Circle::getArea() const
-{
- return PI * radius * radius;
-}
-double Circle::getPer() const
-{
- return 2 * PI * radius;
-} \ No newline at end of file
diff --git a/Sem. 13/Figures/Circle.h b/Sem. 13/Figures/Circle.h
deleted file mode 100644
index 6449fc1..0000000
--- a/Sem. 13/Figures/Circle.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#pragma once
-#include "Shape.h"
-
-class Circle : public Shape
-{
- double radius;
-
-public:
- Circle(int x, int y, double radius);
-
- double getArea() const override;
- double getPer() const override;
-
-}; \ No newline at end of file
diff --git a/Sem. 13/Figures/Rectangle.cpp b/Sem. 13/Figures/Rectangle.cpp
deleted file mode 100644
index 3fa1026..0000000
--- a/Sem. 13/Figures/Rectangle.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "Rectangle.h"
-
-Rectangle::Rectangle(int x1, int y1, int x3, int y3) : Shape(4)
-{
- setPoint(0, x1, y1);
- setPoint(1, x1, y3);
- setPoint(2, x3, y3);
- setPoint(3, x3, y1);
-}
-double Rectangle::getArea() const
-{
- Shape::point p0 = getPointAtIndex(0);
- Shape::point p1 = getPointAtIndex(1);
- Shape::point p3 = getPointAtIndex(3);
-
- return p0.getDist(p1) * p0.getDist(p3);
-
-}
-double Rectangle::getPer() const
-{
- Shape::point p0 = getPointAtIndex(0);
- Shape::point p1 = getPointAtIndex(1);
- Shape::point p3 = getPointAtIndex(3);
-
- return 2*(p0.getDist(p1) + p0.getDist(p3));
-} \ No newline at end of file
diff --git a/Sem. 13/Figures/Rectangle.h b/Sem. 13/Figures/Rectangle.h
deleted file mode 100644
index ccdad8e..0000000
--- a/Sem. 13/Figures/Rectangle.h
+++ /dev/null
@@ -1,10 +0,0 @@
-#pragma once
-#include "Shape.h"
-
-class Rectangle : public Shape
-{
-public:
- Rectangle(int x1, int y1, int x3, int y3);
- double getArea() const override;
- double getPer() const override;
-}; \ No newline at end of file
diff --git a/Sem. 13/Figures/Shape.cpp b/Sem. 13/Figures/Shape.cpp
deleted file mode 100644
index 27bb9e9..0000000
--- a/Sem. 13/Figures/Shape.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-#include "Shape.h"
-
-Shape::Shape(size_t pointsCount) : pointsCount(pointsCount)
-{
- points = new point[pointsCount]; // [0,0], [0,0]....
-}
-
-void Shape::copyFrom(const Shape& other)
-{
- points = new point[other.pointsCount];
-
- for (int i = 0; i < other.pointsCount; i++)
- points[i] = other.points[i];
-}
-void Shape::free()
-{
- delete[] points;
-}
-
-Shape::Shape(const Shape& other)
-{
- copyFrom(other);
-}
-Shape& Shape::operator= (const Shape& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
-}
-Shape::~Shape()
-{
- free();
-}
-
-const Shape::point& Shape::getPointAtIndex(size_t index) const
-{
- if (index >= pointsCount)
- throw std::exception("Invalid point index!");
-
- return points[index];
-}
-
-void Shape::setPoint(size_t pointIndex, int x, int y)
-{
- if (pointIndex >= pointsCount)
- throw std::exception("Invalid point index!");
-
- points[pointIndex] = point(x, y);
-}
diff --git a/Sem. 13/Figures/Shape.h b/Sem. 13/Figures/Shape.h
deleted file mode 100644
index 62f5c41..0000000
--- a/Sem. 13/Figures/Shape.h
+++ /dev/null
@@ -1,41 +0,0 @@
-#pragma once
-#include <iostream>
-
-class Shape // Abstract class - no instances of Shape are allowed!
-{
-protected:
- struct point
- {
- point() :x(0), y(0){}
- point(int x, int y) :x(x), y(y){}
- int x;
- int y;
- double getDist(const point& other) const
- {
- int dx = x - other.x;
- int dy = y - other.y;
-
- return sqrt(dx*dx + dy*dy);
- }
- };
- const point& getPointAtIndex(size_t index) const;
-private:
- point* points;
- size_t pointsCount;
-
- void copyFrom(const Shape& other);
- void free();
-
-
-public:
- Shape(size_t pointsCount);
-
- Shape(const Shape& other);
- Shape& operator=(const Shape& other);
- virtual ~Shape(); //!!!!!!
-
- void setPoint(size_t pointIndex, int x, int y);
-
- virtual double getArea() const = 0; //pure virtual
- virtual double getPer() const = 0; // pure virtual
-}; \ No newline at end of file
diff --git a/Sem. 13/Figures/Triangle.cpp b/Sem. 13/Figures/Triangle.cpp
deleted file mode 100644
index 7de831c..0000000
--- a/Sem. 13/Figures/Triangle.cpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "Triangle.h"
-
-Triangle::Triangle(int x1, int y1, int x2, int y2, int x3, int y3) : Shape(3)
-{
- setPoint(0, x1, y1);
- setPoint(1, x2, y2);
- setPoint(2, x3, y3);
-}
-double Triangle::getArea() const
-{
- Shape::point p1 = getPointAtIndex(0);
- Shape::point p2 = getPointAtIndex(1);
- Shape::point p3 = getPointAtIndex(2);
-
- return abs(p1.x*p2.y + p2.x*p3.y + p3.x*p1.y - p1.y * p2.x - p2.y*p3.x - p3.y*p1.x) / 2.00;
-}
-double Triangle::getPer() const
-{
- Shape::point p1 = getPointAtIndex(0);
- Shape::point p2 = getPointAtIndex(1);
- Shape::point p3 = getPointAtIndex(2);
-
- return p1.getDist(p2) + p2.getDist(p3) + p3.getDist(p1);
-} \ No newline at end of file
diff --git a/Sem. 13/Figures/Triangle.h b/Sem. 13/Figures/Triangle.h
deleted file mode 100644
index c157de8..0000000
--- a/Sem. 13/Figures/Triangle.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#pragma once
-
-#include "Shape.h"
-
-class Triangle : public Shape
-{
-
-public:
- Triangle(int x1, int y1, int x2, int y2, int x3, int y3);
- double getArea() const override;
- double getPer() const override;
-}; \ No newline at end of file
diff --git a/Sem. 13/Figures/main.cpp b/Sem. 13/Figures/main.cpp
deleted file mode 100644
index 7e9f9ff..0000000
--- a/Sem. 13/Figures/main.cpp
+++ /dev/null
@@ -1,36 +0,0 @@
-#include <iostream>
-using namespace std;
-
-#include "Rectangle.h"
-#include "Circle.h"
-#include "Triangle.h"
-
-
-void printAreas(const Shape* const * shapes, size_t shapesCount)
-{
- for (int i = 0; i < shapesCount; i++)
- cout << shapes[i]->getArea() <<endl;
-}
-void printPers(const Shape* const * shapes, size_t shapesCount)
-{
- for (int i = 0; i < shapesCount; i++)
- cout << shapes[i]->getPer() << endl;
-}
-int main()
-{
- Shape** arr = new Shape*[4];
-
- arr[0] = new Rectangle(3, 4, 6, 8);
- arr[1] = new Circle(3, 3, 4);
- arr[2] = new Circle(1, 4, 5);
- arr[3] = new Triangle(1, 1, 2, 2, 3, 3);
-
- printAreas(arr, 4);
- printPers(arr, 4);
-
- for (int i = 0; i < 4; i++)
- delete arr[i];
- delete[] arr;
-
-
-} \ No newline at end of file
diff --git a/Sem. 13/README.md b/Sem. 13/README.md
deleted file mode 100644
index 7835c36..0000000
--- a/Sem. 13/README.md
+++ /dev/null
@@ -1,198 +0,0 @@
-# Статично и динамично свързване. Виртуални функции. Полиморфизъм. Абстрактни класове.
-#### Статично и динамично свързване. Виртуални функции.
-Пример за **статично** свързване:
-```c++
-#include <iostream>
-using namespace std;
-
-struct A
-{
- void f() const
- {
- std::cout << "A::f()" << std::endl;
- }
-};
-
-struct B : public A
-{
- void f() const
- {
- std::cout << "B::f()" << std::endl;
- }
-};
-
-int main()
-{
- B* bPtr = new B();
-
- A* aPtr = bPtr;
-
- bPtr->f(); // B::f()
- aPtr->f(); // A::f()
-}
- ```
-
- - **Статично** свързване - изборът на функцията, която трябва да се изпълни става **по време на компилация**.
- - **Динамично** свързване – изборът на функцията, която трябва да се изпълни става **по време на изпълнение на програмата**.
-
-```c++
-#include <iostream>
-using namespace std;
-
-struct A
-{
- virtual void f() const
- {
- std::cout << "A::f()" << std::endl;
- }
-};
-
-struct B : public A
-{
- void f() const
- {
- std::cout << "B::f()" << std::endl;
- }
-};
-
-int main()
-{
- А* ptrs[2];
- ptrs[0] = new A();
- ptrs[1] = new B();
-
- ptrs[0]->f(); // B::f()
- ptrs[1]->f(); // B::f()
-}
- ```
-#### Полиморфизъм
-Едни и същи действия се реализират по различен начин в
-зависимост от обектите, върху които се прилагат.
-
- - Действията се наричат полиморфни.
- - Реализира се чрез виртуални функции.
- - Класовете, върху които ще се прилага, трябва да имат общ родител или прародител, т.е. да са наследници на един и същ клас.
- - В класа се дефинира виртуален метод, съответстващ на полиморфното действие.
- - Всеки клас предефинира или не виртуалния метод.
- - Активирането става чрез указател към базов клас, на който може да се присвоят адресите на обекти на който и да е от базовите класове от йерархията
-
-**Важно!** При полиморфна йерархия ще изтриваме обектите чрез указатели от базовия клас. За да се извикват правилните деструкори задължително **деструкторът на базовият клас** трябва е деклариран като виртуален!
-```c++
-#include<iostream>
-
-struct Animal
-{
- virtual void sayHello() const
- {
- std::cout << "Hello, I am a random animal" << std::endl;
- }
-
- virtual ~Animal(){} //!!!
-};
-struct Dog : public Animal
-{
- void sayHello() const override
- {
- std::cout << "Hello, I am a dog!" << std::endl;
- }
-};
-
-struct Cat : public Animal
-{
- void sayHello() const override
- {
- std::cout << "Hello, I am a cat!" << std::endl;
- }
-};
-
-struct Mouse : public Animal
-{
-};
-
-int main()
-{
- Animal** animals = new Animal*[3];
-
- animals[0] = new Dog();
- animals[1] = new Cat();
- animals[2] = new Mouse();
-
-
- //from base-class pointer
- animals[0]->sayHello(); // Hello, I am a dog!
- animals[1]->sayHello(); // Hello, I am a cat!
- animals[2]->sayHello(); // Hello, I am a random animal!
-
- delete animals[0], animals[1], animals[2];
- delete[] animals;
-}
-
- ```
- #### Абстрактен клас
-
-
- - Чисто виртуална функция (**pure virtual function**) - вруална функция без тяло.
- - Клас е **абстрактен**, ако в него има поне една **чисто виртуална функция**.
-
-Тогава класът е предназначен единствено за наследяване и няма да може да създаваме обекти от него.
-Така във всеки наследник ще трябва да се разпише имплементация на функцията. Ако някой наследник няма собствена имплементация, то и той става абстрактен клас.
-
-```c++
-#include<iostream>
-
-struct Animal
-{
- virtual void sayHello() const = 0;
-
-
- virtual ~Animal(){} //!!!
-};
-struct Dog : public Animal
-{
- void sayHello() const override
- {
- std::cout << "Hello, I am a dog!" << std::endl;
- }
-};
-
-struct Cat : public Animal
-{
- void sayHello() const override
- {
- std::cout << "Hello, I am a cat!" << std::endl;
- }
-};
-
-struct Mouse : public Animal
-{
- void sayHello() const override
- {
- std::cout << "Hello, I am a mouse!" << std::endl;
- }
-};
-
-struct PrehistoricAnimal : public Animal
-{};
-
-int main()
-{
- // Animal* pa1 = new Animal(); No! Animal is an abstract class!
- // Animal* pa2 = new PrehistoricAnimal(); No! PrehistoricAnimal is also an abstract class!
-
- Animal** animals = new Animal*[3];
-
- animals[0] = new Dog();
- animals[1] = new Cat();
- animals[2] = new Mouse();
-
-
- //from base-class pointer
- animals[0]->sayHello(); // Hello, I am a dog!
- animals[1]->sayHello(); // Hello, I am a cat!
- animals[2]->sayHello(); // Hello, I am a random animal!
-
- delete animals[0], animals[1], animals[2];
- delete[] animals;
-}
-
- ```
diff --git a/Sem. 14/Collection/ShapesCollection.cpp b/Sem. 14/Collection/ShapesCollection.cpp
deleted file mode 100644
index 5bd2711..0000000
--- a/Sem. 14/Collection/ShapesCollection.cpp
+++ /dev/null
@@ -1,67 +0,0 @@
-#include "ShapesCollection.h"
-
-void ShapesCollection::addCircle(double x, double y, double radius)
-{
- Circle* ptr = new Circle(x, y, radius);
- collection.push_back(ptr);
-}
-void ShapesCollection::addRectangle(double x1, double y1, double x3, double y3)
-{
- Rectangle* ptr = new Rectangle(x1, y1, x3, y3);
- collection.push_back(ptr);
-}
-void ShapesCollection::addTriangle(double x1, double y1, double x2, double y2, double x3, double y3)
-{
- Triangle* ptr = new Triangle(x1, y1, x2, y2, x3, y3);
- collection.push_back(ptr);
-}
-void ShapesCollection::addRhombus(double x1, double y1, double x2, double y2)
-{
- collection.push_back(new Rhombus(x1, y1, x2, y2));
-}
-
-void ShapesCollection::addSquare(double x1, double y1, double sideLength)
-{
- collection.push_back(new Square(x1, y1, sideLength));
-}
-
-void ShapesCollection::printAreas() const
-{
- for (int i = 0; i < collection.size(); i++)
- std::cout << collection[i]->getArea() << " " << std::endl;
-}
-void ShapesCollection::printPers() const
-{
- for (int i = 0; i < collection.size(); i++)
- std::cout << collection[i]->getPer() << " " << std::endl;
-}
-
-void ShapesCollection::copyFrom(const ShapesCollection& other)
-{
- for (int i = 0; i < other.collection.size(); i++)
- collection.push_back(other.collection[i]->clone());
-}
-void ShapesCollection::free()
-{
- for (int i = 0; i < collection.size(); i++)
- delete collection[i];
- collection.clear();
-}
-
-ShapesCollection::ShapesCollection(const ShapesCollection& other)
-{
- copyFrom(other);
-}
-ShapesCollection& ShapesCollection::operator= (const ShapesCollection& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
-}
-ShapesCollection::~ShapesCollection()
-{
- free();
-}
diff --git a/Sem. 14/Collection/ShapesCollection.h b/Sem. 14/Collection/ShapesCollection.h
deleted file mode 100644
index 92c7deb..0000000
--- a/Sem. 14/Collection/ShapesCollection.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#include "../Shapes/Circle.h"
-#include "../Shapes/Rectangle.h"
-#include "../Shapes/Triangle.h"
-#include "../Shapes/Rhombus.h"
-#include "../Shapes/Square.h"
-#include <vector>
-
-class ShapesCollection
-{
- std::vector<Shape*> collection;
-
- void free();
- void copyFrom(const ShapesCollection& other);
-
-public:
-
-
- //factory
- void addCircle(double x, double y, double radius);
- void addRectangle(double x1, double y1, double x3, double y3);
- void addTriangle(double x1, double y1, double x2, double y2, double x3, double y3);
- void addRhombus(double x1, double y1, double x2, double y2);
- void addSquare(double x1, double y2, double sideLength);
- //
-
-
- void printAreas() const;
- void printPers() const;
-
- ShapesCollection() = default;
- ShapesCollection(const ShapesCollection& other);
- ShapesCollection& operator=(const ShapesCollection& other);
-
- ~ShapesCollection();
-};
diff --git a/Sem. 14/README.md b/Sem. 14/README.md
deleted file mode 100644
index acf6382..0000000
--- a/Sem. 14/README.md
+++ /dev/null
@@ -1,157 +0,0 @@
-
-# Колекции от обекти в полиморфна йерархия. Копиране и триене.
-## Колекция.
-
-Можем да реализираме колекция от различни типове (но с общ базов клас), чрез масив от указатели. Указателите трябва да са от типа на базовия клас.
-
-```c++
-struct Fruit
-{
- virtual void printColor() const = 0;
-
- virtual ~Fruit(){}
-};
-
-struct Apple
-{
- void printColor() const override
- {
- std::cout << "Red or green! "<<std::endl;
- }
-};
-
-struct Orange
-{
- void printColor() const override
- {
- std::cout << "Orange! "<<std::endl;
- }
-
-};
-
-struct Lemon
-{
- Lemon(size_t sourness) : sourness(sourness){}
-
- size_t sourness;
- void printColor() const override
- {
- std::cout << "Yellow! "<<std::endl;
- }
-};
-
-class FruitStore
-{
-private:
- Fruit** fruits;
- size_t capacity;
- size_t count;
-
- void copyFrom(const FruitStore& other);
- void free();
-
-public:
- FruitStore();
- FruitStore(const FruitStore&);
- FruitStore& operator=(const FruitStore&);
- ~FruitStore();
-
- void addApple();
- void addOrange();
- void addLemon(size_t sourness);
-};
-
-void FruitStore::addApple()
-{
- fruits[count++] = new Apple();
-}
-
-void FruitStore::addOrange()
-{
- fruits[count++] = new Orange();
-}
-void FruitStore::addLemon(size_t sourness)
-{
- fruits[count++] = new Lemon(sourness);
-}
- ```
-
-## Триене
-Понеже имаме виртуален деструктор в базовия клас, не се интересуваме в колекцията какви са обектите, които трием.
-```c++
-void FruitStore::free()
-{
- for(int i = 0; i < count; i++)
- delete fruits[i];
- delete[] fruits;
-}
- ```
-
-## Копиране
-Искаме да реализираме копиране на колекцията.
-Това трябва да стане без да нарушаваме абстракцията - искаме обеките да се копират без да се налага да запитваме за техния тип.
-За това дефинираме виртуална функция clone, която ще връща копие на обекта. Тази функция я разписваме във всеки от наследниците.
-
-```c++
-
-struct Fruit
-{
- virtual void printColor() const = 0;
- virtual ~Fruit(){}
-
- virtual Fruit* clone() const = 0; //!
-};
-
-struct Apple
-{
- void printColor() const override
- {
- std::cout << "Red or green! "<<std::endl;
- }
- Fruit* clone() const override
- {
- return new Apple(*this);
- }
-
-};
-
-struct Orange
-{
- void printColor() const override
- {
- std::cout << "Orange! "<<std::endl;
- }
-
- Fruit* clone() const override
- {
- return new Apple(*this);
- }
-};
-
-struct Lemon
-{
- Lemon(size_t sourness) : sourness(sourness){}
-
- size_t sourness;
- void printColor() const override
- {
- std::cout << "Yellow! "<<std::endl;
- }
- Fruit* clone() const override
- {
- return new Lemon(*this);
- }
-};
- ```
-От тук копирането става тривиално:
-```c++
-void FruitStore::copyFrom(const FruitStore& other)
-{
- fruits = new Fruit*[other. capacity];
- for(int i = 0; i < other.count; i++)
- fruits[i] = other.fruits[u]->clone();
- count = other.count;
- capacity = other.capacity;
-}
- ```
-
diff --git a/Sem. 14/Shapes/Circle.cpp b/Sem. 14/Shapes/Circle.cpp
deleted file mode 100644
index 3f4ac98..0000000
--- a/Sem. 14/Shapes/Circle.cpp
+++ /dev/null
@@ -1,22 +0,0 @@
-#include "Circle.h"
-
-const double PI = 3.1415;
-Circle::Circle(double x, double y, double radius) : Shape(1), radius(radius)
-{
- setPoint(0, x, y);
-}
-
-double Circle::getArea() const
-{
- return PI * radius * radius;
-}
-double Circle::getPer() const
-{
- return 2 * PI * radius;
-}
-
-Shape* Circle::clone() const
-{
- Circle* copy = new Circle(*this);
- return copy;
-} \ No newline at end of file
diff --git a/Sem. 14/Shapes/Circle.h b/Sem. 14/Shapes/Circle.h
deleted file mode 100644
index 84380fa..0000000
--- a/Sem. 14/Shapes/Circle.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-#include "Shape.h"
-
-class Circle : public Shape
-{
- double radius;
-
-public:
- Circle(double x, double y, double radius);
-
- double getArea() const override;
- double getPer() const override;
-
- Shape* clone() const override;
-}; \ No newline at end of file
diff --git a/Sem. 14/Shapes/Rectangle.cpp b/Sem. 14/Shapes/Rectangle.cpp
deleted file mode 100644
index 9e16b01..0000000
--- a/Sem. 14/Shapes/Rectangle.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#include "Rectangle.h"
-
-Rectangle::Rectangle(double x1, double y1, double x3, double y3) : Shape(4)
-{
- setPoint(0, x1, y1);
- setPoint(1, x1, y3);
- setPoint(2, x3, y3);
- setPoint(3, x3, y1);
-}
-double Rectangle::getArea() const
-{
- Shape::point p0 = getPointAtIndex(0);
- Shape::point p1 = getPointAtIndex(1);
- Shape::point p3 = getPointAtIndex(3);
-
- return p0.getDist(p1) * p0.getDist(p3);
-
-}
-double Rectangle::getPer() const
-{
- Shape::point p0 = getPointAtIndex(0);
- Shape::point p1 = getPointAtIndex(1);
- Shape::point p3 = getPointAtIndex(3);
-
- return 2*(p0.getDist(p1) + p0.getDist(p3));
-}
-
-Shape* Rectangle::clone() const
-{
- Rectangle* copy = new Rectangle(*this);
- return copy;
-} \ No newline at end of file
diff --git a/Sem. 14/Shapes/Rectangle.h b/Sem. 14/Shapes/Rectangle.h
deleted file mode 100644
index baa4cb5..0000000
--- a/Sem. 14/Shapes/Rectangle.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#pragma once
-#include "Shape.h"
-
-class Rectangle : virtual public Shape
-{
-
-public:
- Rectangle(double x1, double y1, double x3, double y3);
- double getArea() const override;
- double getPer() const override;
-
- Shape* clone() const override;
-}; \ No newline at end of file
diff --git a/Sem. 14/Shapes/Rhombus.cpp b/Sem. 14/Shapes/Rhombus.cpp
deleted file mode 100644
index 62a3e8c..0000000
--- a/Sem. 14/Shapes/Rhombus.cpp
+++ /dev/null
@@ -1,25 +0,0 @@
-#include "Rhombus.h"
-
-Rhombus::Rhombus(double x1, double y1, double x2, double y2) : Shape(4)
-{
- setPoint(0, x1, y1);
- setPoint(1, x2, y2);
- double sideLength = getPointAtIndex(0).getDist(getPointAtIndex(1));
-
- setPoint(2, x2 + sideLength, y2);
- setPoint(3, x1 + sideLength, y1);
-}
-
-double Rhombus::getArea() const
-{
- return 0.5 * getPointAtIndex(0).getDist(getPointAtIndex(2)) * getPointAtIndex(1).getDist(getPointAtIndex(3));
-}
-double Rhombus::getPer() const
-{
- return 4 * getPointAtIndex(0).getDist(getPointAtIndex(1));
-}
-Shape* Rhombus::clone() const
-{
- Rhombus* copy = new Rhombus(*this);
- return copy;
-} \ No newline at end of file
diff --git a/Sem. 14/Shapes/Rhombus.h b/Sem. 14/Shapes/Rhombus.h
deleted file mode 100644
index 24e5a5b..0000000
--- a/Sem. 14/Shapes/Rhombus.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#pragma once
-#include "Shape.h"
-
-class Rhombus : virtual public Shape
-{
-public:
- Rhombus(double x1, double y1, double x2, double y2);
-
- double getArea() const override;
- double getPer() const override;
- Shape* clone() const override;
-}; \ No newline at end of file
diff --git a/Sem. 14/Shapes/Shape.cpp b/Sem. 14/Shapes/Shape.cpp
deleted file mode 100644
index 7bc24ef..0000000
--- a/Sem. 14/Shapes/Shape.cpp
+++ /dev/null
@@ -1,52 +0,0 @@
-#include "Shape.h"
-
-Shape::Shape(size_t pointsCount) : pointsCount(pointsCount)
-{
- points = new point[pointsCount]; // [0,0], [0,0]....
-}
-
-void Shape::copyFrom(const Shape& other)
-{
- points = new point[other.pointsCount];
-
- for (int i = 0; i < other.pointsCount; i++)
- points[i] = other.points[i];
-}
-void Shape::free()
-{
- delete[] points;
-}
-
-Shape::Shape(const Shape& other)
-{
- copyFrom(other);
-}
-Shape& Shape::operator= (const Shape& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
-}
-Shape::~Shape()
-{
- free();
-}
-
-const Shape::point& Shape::getPointAtIndex(size_t index) const
-{
- if (index >= pointsCount)
- throw std::exception("Invalid point index!");
-
- return points[index];
-}
-
-void Shape::setPoint(size_t pointIndex, double x, double y)
-{
- if (pointIndex >= pointsCount)
- throw std::exception("Invalid point index!");
-
- points[pointIndex] = point(x, y);
-}
diff --git a/Sem. 14/Shapes/Shape.h b/Sem. 14/Shapes/Shape.h
deleted file mode 100644
index caf7919..0000000
--- a/Sem. 14/Shapes/Shape.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#pragma once
-#include <iostream>
-
-class Shape // Abstract class - no instances of Shape are allowed!
-{
-protected:
- struct point
- {
- point() :x(0), y(0){}
- point(double x, double y) :x(x), y(y){}
- double x;
- double y;
- double getDist(const point& other) const
- {
- int dx = x - other.x;
- int dy = y - other.y;
-
- return sqrt(dx*dx + dy*dy);
- }
- };
- const point& getPointAtIndex(size_t index) const;
-private:
- point* points;
- size_t pointsCount;
-
- void copyFrom(const Shape& other);
- void free();
-
-
-public:
- Shape(size_t pointsCount);
-
- Shape(const Shape& other);
- Shape& operator=(const Shape& other);
- virtual ~Shape(); //!!!!!!
-
- void setPoint(size_t pointIndex, double x, double y);
-
- virtual double getArea() const = 0; //pure virtual
- virtual double getPer() const = 0; // pure virtual
-
- virtual Shape* clone() const = 0; //
-}; \ No newline at end of file
diff --git a/Sem. 14/Shapes/Square.cpp b/Sem. 14/Shapes/Square.cpp
deleted file mode 100644
index 555c340..0000000
--- a/Sem. 14/Shapes/Square.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "Square.h"
-
-Square::Square(double x, double y, double sideLength) : Rectangle(x, y, x + sideLength, y - sideLength), Rhombus(x, y, x, y - sideLength), Shape(4)
-{}
-
-double Square::getArea() const
-{
- return Rhombus::getArea();
-}
-double Square::getPer() const
-{
- return Rectangle::getPer();
-};
-
-Shape* Square::clone() const
-{
- Square* copy = new Square(*this);
- return copy;
-} \ No newline at end of file
diff --git a/Sem. 14/Shapes/Square.h b/Sem. 14/Shapes/Square.h
deleted file mode 100644
index fd78bd8..0000000
--- a/Sem. 14/Shapes/Square.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#include "Rhombus.h"
-#include "Rectangle.h"
-
-class Square : public Rhombus, public Rectangle
-{
-public:
- Square(double x, double y, double sideLength);
-
- double getArea() const override;
- double getPer() const override;
-
- Shape* clone() const override;
-}; \ No newline at end of file
diff --git a/Sem. 14/Shapes/Triangle.cpp b/Sem. 14/Shapes/Triangle.cpp
deleted file mode 100644
index e13d685..0000000
--- a/Sem. 14/Shapes/Triangle.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "Triangle.h"
-
-Triangle::Triangle(double x1, double y1, double x2, double y2, double x3, double y3) : Shape(3)
-{
- setPoint(0, x1, y1);
- setPoint(1, x2, y2);
- setPoint(2, x3, y3);
-}
-double Triangle::getArea() const
-{
- Shape::point p1 = getPointAtIndex(0);
- Shape::point p2 = getPointAtIndex(1);
- Shape::point p3 = getPointAtIndex(2);
-
- return abs(p1.x*p2.y + p2.x*p3.y + p3.x*p1.y - p1.y * p2.x - p2.y*p3.x - p3.y*p1.x) / 2.00;
-}
-double Triangle::getPer() const
-{
- Shape::point p1 = getPointAtIndex(0);
- Shape::point p2 = getPointAtIndex(1);
- Shape::point p3 = getPointAtIndex(2);
-
- return p1.getDist(p2) + p2.getDist(p3) + p3.getDist(p1);
-}
-
-Shape* Triangle::clone() const
-{
- Triangle* copy = new Triangle(*this);
- return copy;
-} \ No newline at end of file
diff --git a/Sem. 14/Shapes/Triangle.h b/Sem. 14/Shapes/Triangle.h
deleted file mode 100644
index 3a53901..0000000
--- a/Sem. 14/Shapes/Triangle.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#pragma once
-
-#include "Shape.h"
-
-class Triangle : public Shape
-{
-
-public:
- Triangle(double x1, double y1, double x2, double y2, double x3, double y3);
- double getArea() const override;
- double getPer() const override;
-
- Shape* clone() const override;
-}; \ No newline at end of file
diff --git a/Sem. 14/main.cpp b/Sem. 14/main.cpp
deleted file mode 100644
index 5d9401c..0000000
--- a/Sem. 14/main.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <iostream>
-#include "Collection/ShapesCollection.h"
-using namespace std;
-
-int main()
-{
- ShapesCollection s;
-
- s.addCircle(3, 4, 5);
- s.addTriangle(2, 3, 54, 3, 2, 1);
- s.addRectangle(1, 2, 3, 4);
- s.addRhombus(3, 2, 0, 0);
- s.addSquare(4, 4, 10);
-
- s.printAreas();
-}
diff --git a/Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.cpp b/Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.cpp
deleted file mode 100644
index ed9823d..0000000
--- a/Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.cpp
+++ /dev/null
@@ -1,69 +0,0 @@
-#include "ChessBoard.h"
-#include "../FigureFactory/FigureFactory.h"
-
-ChessBoard::ChessBoard()
-{
-
- for (int i = 0; i < BOARD_SIZE; i++)
- {
- board[1][i].f = FigureFactory::createFigure(false, PawnFigure);
- board[6][i].f = FigureFactory::createFigure(true, PawnFigure);
- }
-
- board[0][0].f = FigureFactory::createFigure(false, RookFigure);
- board[0][7].f = FigureFactory::createFigure(false, RookFigure);
-
- board[7][0].f = FigureFactory::createFigure(true, RookFigure);
- board[7][7].f = FigureFactory::createFigure(true, RookFigure);
-
-
- board[0][1].f = FigureFactory::createFigure(false, KnightFigure);
- board[0][6].f = FigureFactory::createFigure(false, KnightFigure);
- board[7][1].f = FigureFactory::createFigure(true, KnightFigure);;
- board[7][6].f = FigureFactory::createFigure(true, KnightFigure);
-
- board[0][2].f = FigureFactory::createFigure(false, BishopFigure);
- board[0][5].f = FigureFactory::createFigure(false, BishopFigure);;
- board[7][2].f = FigureFactory::createFigure(true, BishopFigure);
- board[7][5].f = FigureFactory::createFigure(true, BishopFigure);
-
- board[0][3].f = FigureFactory::createFigure(false, KingFigure);
- board[0][4].f = FigureFactory::createFigure(false, QueenFigure);
- board[7][4].f = FigureFactory::createFigure(true, QueenFigure);
- board[7][3].f = FigureFactory::createFigure(true, KingFigure);
-}
-
-void ChessBoard::print() const
-{
- std::cout << "--------" << std::endl;
- for (int i = 0; i < BOARD_SIZE; i++)
- {
- for (int j = 0; j < BOARD_SIZE; j++)
- {
- board[i][j].print();
- }
- std::cout << std::endl;
- }
- std::cout << "--------" << std::endl << std::endl << std::endl;
-}
-
-void ChessBoard::moveFigure(size_t x, size_t y, size_t destX, size_t destY)
-{
-
- Figure* current = board[x][y].f;
-
- if (current->getType() == PawnFigure)
- {
- //Some other logic..... El'passant and other
- }
- else
- {
- if (board[x][y].f && board[x][y].f->canBeMoved(x, y, destX, destY))
- {
- delete board[destX][destY].f;
- board[destX][destY].f = board[x][y].f;
- board[x][y].f = nullptr;
- }
- }
-
-} \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.h b/Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.h
deleted file mode 100644
index 315e492..0000000
--- a/Sem. 15/Chess_basic_prototype/ChessBoard/ChessBoard.h
+++ /dev/null
@@ -1,43 +0,0 @@
-#pragma once
-#include "../Figures/FigureBase/Figure.h"
-
-const size_t BOARD_SIZE = 8;
-class ChessBoard
-{
- struct Cell
- {
- Figure* f = nullptr;
- Cell() = default;
-
- Cell(const Cell& other) = delete;
- Cell& operator=(const Cell& other) = delete;
- bool isEmpty()
- {
- return f == nullptr;
- }
-
- void print() const
- {
- if (f != nullptr)
- f->print();
- else
- std::cout << ' ';
- }
-
- ~Cell()
- {
- delete f;
- }
- };
- Cell board[BOARD_SIZE][BOARD_SIZE];
-
-public:
- ChessBoard();
- ChessBoard(const ChessBoard& other) = delete;
- ChessBoard& operator=(const ChessBoard&) = delete;
-
- void print() const;
-
- void moveFigure(size_t x, size_t y, size_t destX, size_t destY);
-
-};
diff --git a/Sem. 15/Chess_basic_prototype/ConfigEnums/ConfigEnums.h b/Sem. 15/Chess_basic_prototype/ConfigEnums/ConfigEnums.h
deleted file mode 100644
index c3448e8..0000000
--- a/Sem. 15/Chess_basic_prototype/ConfigEnums/ConfigEnums.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-
-enum FigureType
-{
- KingFigure,
- QueenFigure,
- KnightFigure,
- BishopFigure,
- PawnFigure,
- RookFigure
-}; \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.cpp b/Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.cpp
deleted file mode 100644
index e9db605..0000000
--- a/Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.cpp
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "FigureFactory.h"
-#include "../Figures/Bishop/Bishop.h"
-#include "../Figures/King/King.h"
-#include "../Figures/Knight/Knight.h"
-#include "../Figures/Rook/Rook.h"
-#include "../Figures/Queen/Queen.h"
-#include "../Figures/Pawn/Pawn.h"
-
-Figure* FigureFactory::createFigure(bool isWhite, FigureType type)
-{
-
- switch (type)
- {
- case KingFigure:
- return new King(isWhite);
- case QueenFigure:
- return new Queen(isWhite);
- case KnightFigure:
- return new Knight(isWhite);
- case BishopFigure:
- return new Bishop(isWhite);
- case PawnFigure:
- return new Pawn(isWhite);
- case RookFigure:
- return new Rook(isWhite);
- }
-} \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.h b/Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.h
deleted file mode 100644
index 012a60c..0000000
--- a/Sem. 15/Chess_basic_prototype/FigureFactory/FigureFactory.h
+++ /dev/null
@@ -1,9 +0,0 @@
-#pragma once
-#include "../Figures/FigureBase/Figure.h"
-#include "../ConfigEnums/ConfigEnums.h"
-
-class FigureFactory
-{
-public:
- static Figure* createFigure(bool isWhite, FigureType); //enum
-}; \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/Figures/Bishop/Bishop.cpp b/Sem. 15/Chess_basic_prototype/Figures/Bishop/Bishop.cpp
deleted file mode 100644
index 786c9eb..0000000
--- a/Sem. 15/Chess_basic_prototype/Figures/Bishop/Bishop.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "Bishop.h"
-#include <cmath>
-
-Bishop::Bishop(bool isWhite) : Figure(isWhite, RookFigure)
-{}
-bool Bishop::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const
-{
- return abs((int)currentX - (int)destX) == abs((int)currentY - (int)destY);
-}
-void Bishop::print() const
-{
- if (getIsWhite())
- std::cout << 'B';
- else
- std::cout << 'b';
-}
diff --git a/Sem. 15/Chess_basic_prototype/Figures/Bishop/Bishop.h b/Sem. 15/Chess_basic_prototype/Figures/Bishop/Bishop.h
deleted file mode 100644
index 86949a7..0000000
--- a/Sem. 15/Chess_basic_prototype/Figures/Bishop/Bishop.h
+++ /dev/null
@@ -1,13 +0,0 @@
-#pragma once
-#include "../FigureBase/Figure.h"
-
-class Bishop : virtual public Figure
-{
-
-public:
- Bishop(bool isWhite);
- bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const override;
-
- void print() const override;
-
-}; \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/Figures/FigureBase/Figure.cpp b/Sem. 15/Chess_basic_prototype/Figures/FigureBase/Figure.cpp
deleted file mode 100644
index e69de29..0000000
--- a/Sem. 15/Chess_basic_prototype/Figures/FigureBase/Figure.cpp
+++ /dev/null
diff --git a/Sem. 15/Chess_basic_prototype/Figures/FigureBase/Figure.h b/Sem. 15/Chess_basic_prototype/Figures/FigureBase/Figure.h
deleted file mode 100644
index 9e2300a..0000000
--- a/Sem. 15/Chess_basic_prototype/Figures/FigureBase/Figure.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#pragma once
-#include <iostream>
-#include "../../ConfigEnums/ConfigEnums.h"
-
-class Figure
-{
- bool isWhite;
- FigureType type;
-
-public:
- Figure(bool isWhite, FigureType type) :isWhite(isWhite), type(type)
- {}
-
- virtual bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const = 0;
- virtual void print() const = 0;
-
- bool getIsWhite() const { return isWhite; };
- FigureType getType() const { return type; }
-
- virtual ~Figure(){};
-}; \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/Figures/King/King.cpp b/Sem. 15/Chess_basic_prototype/Figures/King/King.cpp
deleted file mode 100644
index 8ca67e8..0000000
--- a/Sem. 15/Chess_basic_prototype/Figures/King/King.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include "King.h"
-#include <cmath>
-
-King::King(bool isWhite) : Figure(isWhite, KingFigure)
-{}
-bool King::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const
-{
- return abs((int)currentX - (int)destX) <= 1 && abs((int)currentY - (int)destY) <= 1;
-}
-void King::print() const
-{
- if (getIsWhite())
- std::cout << '%';
- else
- std::cout << '$';
-} \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/Figures/King/King.h b/Sem. 15/Chess_basic_prototype/Figures/King/King.h
deleted file mode 100644
index 85a8e02..0000000
--- a/Sem. 15/Chess_basic_prototype/Figures/King/King.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-#include "../FigureBase/Figure.h"
-
-class King : public Figure
-{
-
-public:
- King(bool isWhite);
- bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const override;
- void print() const override;
-}; \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/Figures/Knight/Knight.cpp b/Sem. 15/Chess_basic_prototype/Figures/Knight/Knight.cpp
deleted file mode 100644
index 5713d7c..0000000
--- a/Sem. 15/Chess_basic_prototype/Figures/Knight/Knight.cpp
+++ /dev/null
@@ -1,26 +0,0 @@
-#include "Knight.h"
-#include <cmath>
-
-Knight::Knight(bool isWhite) : Figure(isWhite, KnightFigure)
-{}
-bool Knight::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const
-{
- int xMovеment[] = { 1, 1, -1, -1, 2, -2, 2, -2 };
- int yMovеment[] = { 2, -2, 2, -2, 1, 1, -1, -1 };
-
- for (int i = 0; i < 8; i++)
- {
- if (currentX + xMovеment[i] == destX &&
- currentY + yMovеment[i] == destY)
- return true;
- }
- return false;
-}
-
-void Knight::print() const
-{
- if (getIsWhite())
- std::cout << 'K';
- else
- std::cout << 'k';
-} \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/Figures/Knight/Knight.h b/Sem. 15/Chess_basic_prototype/Figures/Knight/Knight.h
deleted file mode 100644
index 72acfea..0000000
--- a/Sem. 15/Chess_basic_prototype/Figures/Knight/Knight.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-#include "../FigureBase/Figure.h"
-
-class Knight : public Figure
-{
-
-public:
- Knight(bool isWhite);
- bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const override;
- void print() const override;
-}; \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/Figures/Pawn/Pawn.cpp b/Sem. 15/Chess_basic_prototype/Figures/Pawn/Pawn.cpp
deleted file mode 100644
index 347032b..0000000
--- a/Sem. 15/Chess_basic_prototype/Figures/Pawn/Pawn.cpp
+++ /dev/null
@@ -1,20 +0,0 @@
-#include "Pawn.h"
-#include <cmath>
-Pawn::Pawn(bool isWhite) : Figure(isWhite, PawnFigure), isFirstMove(true)
-{}
-
-bool Pawn::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const
-{
- if (getIsWhite())
- return currentY - 1 == destY && abs((int)currentX - (int)destX) <= 1;
- else
- return currentY + 1 == destY && abs((int)currentX - (int)destX) <= 1;
-}
-
-void Pawn::print() const
-{
- if (getIsWhite())
- std::cout << 'P';
- else
- std::cout << 'p';
-} \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/Figures/Pawn/Pawn.h b/Sem. 15/Chess_basic_prototype/Figures/Pawn/Pawn.h
deleted file mode 100644
index 675bf0b..0000000
--- a/Sem. 15/Chess_basic_prototype/Figures/Pawn/Pawn.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-#include "../FigureBase/Figure.h"
-
-class Pawn : virtual public Figure
-{
- bool isFirstMove;
-public:
- Pawn(bool isWhite);
- bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const override;
- void print() const override;
-}; \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/Figures/Queen/Queen.cpp b/Sem. 15/Chess_basic_prototype/Figures/Queen/Queen.cpp
deleted file mode 100644
index 0e33198..0000000
--- a/Sem. 15/Chess_basic_prototype/Figures/Queen/Queen.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "Queen.h"
-
-Queen::Queen(bool isWhite) : Bishop(isWhite), Rook(isWhite), Figure(isWhite, QueenFigure)
-{}
-
-bool Queen::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const
-{
- return Bishop::canBeMoved(currentX, currentY, destX, destY)
- || Rook::canBeMoved(currentX, currentY, destX, destY);
-}
-
-void Queen::print() const
-{
- if (getIsWhite())
- std::cout << 'Q';
- else
- std::cout << 'q';
-} \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/Figures/Queen/Queen.h b/Sem. 15/Chess_basic_prototype/Figures/Queen/Queen.h
deleted file mode 100644
index c4fb1da..0000000
--- a/Sem. 15/Chess_basic_prototype/Figures/Queen/Queen.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-#include "../Bishop/Bishop.h"
-#include "../Rook/Rook.h"
-
-class Queen : public Bishop, public Rook
-{
-public:
- Queen(bool isWhite);
- bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const;
- void print() const;
-}; \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/Figures/Rook/Rook.cpp b/Sem. 15/Chess_basic_prototype/Figures/Rook/Rook.cpp
deleted file mode 100644
index 2cb96a3..0000000
--- a/Sem. 15/Chess_basic_prototype/Figures/Rook/Rook.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "Rook.h"
-
-Rook::Rook(bool isWhite) : Figure(isWhite, RookFigure)
-{}
-bool Rook::canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const
-{
- return currentX == destX || currentY == destY;
-}
-void Rook::print() const
-{
- if (getIsWhite())
- std::cout << 'R';
- else
- std::cout << 'r';
-}
diff --git a/Sem. 15/Chess_basic_prototype/Figures/Rook/Rook.h b/Sem. 15/Chess_basic_prototype/Figures/Rook/Rook.h
deleted file mode 100644
index f6190a8..0000000
--- a/Sem. 15/Chess_basic_prototype/Figures/Rook/Rook.h
+++ /dev/null
@@ -1,11 +0,0 @@
-#pragma once
-#include "../FigureBase/Figure.h"
-
-class Rook : virtual public Figure
-{
-
-public:
- Rook(bool isWhite);
- bool canBeMoved(size_t currentX, size_t currentY, size_t destX, size_t destY) const override;
- void print() const override;
-}; \ No newline at end of file
diff --git a/Sem. 15/Chess_basic_prototype/main.cpp b/Sem. 15/Chess_basic_prototype/main.cpp
deleted file mode 100644
index 6673ec8..0000000
--- a/Sem. 15/Chess_basic_prototype/main.cpp
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <iostream>
-#include "ChessBoard/ChessBoard.h"
-using namespace std;
-
-//ШАХ
-
-int main()
-{
- ChessBoard c;
-
- c.print();
-
- c.moveFigure(0, 1, 2, 0);
-
- c.print();
-} \ No newline at end of file
diff --git a/Sem. 15/README.md b/Sem. 15/README.md
deleted file mode 100644
index 8a445d4..0000000
--- a/Sem. 15/README.md
+++ /dev/null
@@ -1 +0,0 @@
-TBD
diff --git a/Sem. 16/LogicExpressions/LogicExpressions/LogicExpr.h b/Sem. 16/LogicExpressions/LogicExpressions/LogicExpr.h
deleted file mode 100644
index 9188541..0000000
--- a/Sem. 16/LogicExpressions/LogicExpressions/LogicExpr.h
+++ /dev/null
@@ -1,150 +0,0 @@
-#include <iostream>
-#include <algorithm>
-#include <string>
-#include <vector>
-
-using namespace std;
-
-namespace LogicExpressions
-{
-
- const int ENGLISH_ALPHABET_SIZE = 26;
- struct BooleanInterpretation
- {
- bool values[ENGLISH_ALPHABET_SIZE];
- BooleanInterpretation()
- {
- for (int i = 0; i < ENGLISH_ALPHABET_SIZE; i++)
- values[i] = false;
- }
- void setVarValue(char v, bool value)
- {
- values[v - 'a'] = value;
- }
-
- bool getVarValue(char v) const
- {
- return values[v - 'a'];
- }
- };
-
- struct LogicExpr
- {
- virtual void print() const = 0;
- LogicExpr() = default;
- LogicExpr(const LogicExpr&) = delete;
- LogicExpr& operator=(const LogicExpr& other) = delete;
-
- virtual bool evaluate(const BooleanInterpretation& interpret) const = 0;
- virtual ~LogicExpr(){};
- };
- struct Var : public LogicExpr
- {
- char v;
- Var(char v) :v(v){}
-
- void print() const
- {
- cout << v;
- }
-
- bool evaluate(const BooleanInterpretation& interpret) const
- {
- return interpret.getVarValue(v);
- }
- };
- struct Operation : public LogicExpr
- {
- LogicExpr* left;
- char op;
- LogicExpr* right;
-
- Operation(LogicExpr* lhs, char op, LogicExpr* rhs) : left(lhs), op(op), right(rhs){}
-
- void print() const
- {
- cout << "(";
- left->print();
- cout << op;
- right->print();
- cout << ")";
- }
- ~Operation()
- {
- delete left;
- delete right;
- }
-
- bool evaluate(const BooleanInterpretation& interpret) const
- {
- bool res1 = left->evaluate(interpret);
- bool res2 = right->evaluate(interpret);
-
- switch (op)
- {
- case '^':return res1 && res2;
- case '|':return res1 || res2;
- case '>':return !res1 || res2;
- case '+': return res1 ^ res2;
- case '-': return (res1 && res2) || (!res1 && !res2);
- }
-
- }
- };
- struct Negation : public LogicExpr
- {
- LogicExpr* current;
- Negation(LogicExpr* current) :current(current){}
-
- void print() const
- {
- cout << "!(";
- current->print();
- cout << ")";
- }
- ~Negation()
- {
- delete current;
- }
-
- bool evaluate(const BooleanInterpretation& interpret) const
- {
- bool result = current->evaluate(interpret);
- return !result;
- }
- };
-
- BooleanInterpretation convertNumberToInterpretation(size_t n, const std::vector<char>& vars)
- {
- BooleanInterpretation current;
- for (int i = vars.size() - 1; i >= 0; i--, n/=2)
- current.setVarValue(vars[i], n % 2);
-
- return std::move(current);
- }
-
- bool CheckValues(const LogicExpr* expr, const std::vector<char>& vars, bool value)
- {
- size_t checksCounts = 1 << vars.size();
-
- for (int i = 0; i < checksCounts; i++)
- {
- BooleanInterpretation currentInterpret = convertNumberToInterpretation(i, vars);
-
- if (expr->evaluate(currentInterpret) != value)
- return false;
- }
- return true;
- }
-
- bool isTautology(const LogicExpr* expr, const std::vector<char>& vars)
- {
- return CheckValues(expr, vars, true);
- }
-
- bool isContradiction(const LogicExpr* expr, const std::vector<char>& vars)
- {
- return CheckValues(expr, vars, false);
- }
-}
-
diff --git a/Sem. 16/LogicExpressions/Source.cpp b/Sem. 16/LogicExpressions/Source.cpp
deleted file mode 100644
index af86b62..0000000
--- a/Sem. 16/LogicExpressions/Source.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include "LogicExpressions/LogicExpr.h"
-
-using namespace LogicExpressions;
-
-// or |, and ^, negation !, implies >, iff -
-int main()
-{
- LogicExpr* expr = new Operation(new Var('p'), '|', new Negation(new Var('p'))); // p | !p
- expr->print();
- cout << " " << isTautology(expr, { 'p' }) << endl;
-
- LogicExpr* expr2 = new Operation(new Var('q'),'^',new Operation(new Var('p'), '^', new Negation(new Var('p')))); // q ^ (p ^ !p)
- expr2->print();
- cout << " " << isContradiction(expr2, { 'p', 'q' }) << endl;
-} \ No newline at end of file
diff --git a/Sem. 16/README.md b/Sem. 16/README.md
deleted file mode 100644
index 8a445d4..0000000
--- a/Sem. 16/README.md
+++ /dev/null
@@ -1 +0,0 @@
-TBD
diff --git a/Utills/KN_exams_poll/README.md b/Utills/KN_exams_poll/README.md
deleted file mode 100644
index a5a7125..0000000
--- a/Utills/KN_exams_poll/README.md
+++ /dev/null
@@ -1,15 +0,0 @@
-Събеседването ще се проведе **присъствено във ФМИ**.
-
-Събеседването ще се състои и 3-те дни от **16:00 в зала 101**.
-Разпределние по дни:
-| 29.06 | 01.07 | 02.07 |
-|-------|-------|-------|
-| 82097 | 82302 | 81864 |
-| 82264 | 82273 | 82291 |
-| 82178 | 82285 | 82266 |
-| 82281 | 82278 | 82275 |
-| 81930 | 82271 | 82103 |
-| 81928 | 82287 | 82090 |
-| | 82303 | 82268 |
-| | | 82262 |
-| | | 81448 |
diff --git a/Utills/KN_exams_poll/poll.txt b/Utills/KN_exams_poll/poll.txt
deleted file mode 100644
index 4ffc75f..0000000
--- a/Utills/KN_exams_poll/poll.txt
+++ /dev/null
@@ -1 +0,0 @@
-https://forms.gle/2ciPStWkxz319C8k9
diff --git a/Utills/KN_exams_poll/schedule.md b/Utills/KN_exams_poll/schedule.md
deleted file mode 100644
index 10f8757..0000000
--- a/Utills/KN_exams_poll/schedule.md
+++ /dev/null
@@ -1,8 +0,0 @@
-Дати:
-
- - 29.06
- - 01.07
- - 02.07
-
-[Анкета за ден за събеседване](https://forms.gle/2ciPStWkxz319C8k9)
-
diff --git a/Utills/si_14.06/task1/Optional/Optional.hpp b/Utills/si_14.06/task1/Optional/Optional.hpp
deleted file mode 100644
index cf1ec0d..0000000
--- a/Utills/si_14.06/task1/Optional/Optional.hpp
+++ /dev/null
@@ -1,109 +0,0 @@
-#include <iostream>
-
-template <typename T>
-class Optional
-{
- T* objPtr;
-
- void copyFrom(const Optional<T>& other);
- void free();
-
-public:
- Optional();
- Optional(const T& obj);
-
- Optional(const Optional& other);
- Optional<T>& operator=(const Optional<T>& other);
-
- ~Optional();
-
- void setValue(const T& obj);
- T getValue() const;
-
- bool containsValue() const;
-
- bool operator==(const Optional<T>& other) const;
- bool operator!=(const Optional<T>& other) const;
-};
-
-template <typename T>
-Optional<T>::Optional() : objPtr(nullptr)
-{};
-
-template <typename T>
-Optional<T>::Optional(const T& obj)
-{
- objPtr = new T(obj);
-}
-
-template <typename T>
-void Optional<T>::setValue(const T& obj)
-{
- delete objPtr;
- objPtr = new T(obj);
-}
-
-template <typename T>
-T Optional<T>::getValue() const
-{
- if (!obj)
- throw std::exception("No value assigned!");
- return *objPtr;
-}
-
-template <typename T>
-bool Optional<T>::containsValue() const
-{
- return objPtr != nullptr;
-}
-
-template <typename T>
-void Optional<T>::copyFrom(const Optional<T>& other)
-{
- if (!other.obj)
- objPtr = nullptr;
- else
- objPtr = new T(*other.obj);
-}
-
-template <typename T>
-void Optional<T>::free()
-{
- delete objPtr;
-}
-
-template <typename T>
-Optional<T>::Optional(const Optional<T>& other)
-{
- copyFrom(other);
-}
-
-template <typename T>
-Optional<T>& Optional<T>::operator=(const Optional<T>& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
-
- return *this;
-}
-
-template <typename T>
-Optional<T>::~Optional()
-{
- free();
-}
-
-template <typename T>
-bool Optional<T>::operator==(const Optional<T>& other) const
-{
- return (!objPtr && !other.objPtr) || (objPtr && other.objPtr && *objPtr == *other.objPtr);
-}
-
-template <typename T>
-bool Optional<T>::operator!=(const Optional<T>& other) const
-{
- return !operator==(other);
-}
diff --git a/Utills/si_14.06/task1/Source.cpp b/Utills/si_14.06/task1/Source.cpp
deleted file mode 100644
index d8397a0..0000000
--- a/Utills/si_14.06/task1/Source.cpp
+++ /dev/null
@@ -1,17 +0,0 @@
-#include <iostream>
-#include "Optional/Optional.hpp"
-
-
-
-int main()
-{
- Optional<int> o;
-
- std::cout << o.containsValue() << std::endl;
-
- o.setValue(12);
-
- Optional<int> o2(12);
-
- std::cout << (o == o2) << std::endl;
-} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Source.cpp b/Utills/si_14.06/task2/Source.cpp
deleted file mode 100644
index e8e1a2d..0000000
--- a/Utills/si_14.06/task2/Source.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <iostream>
-#include "ValueArray/ValueArray.h"
-
-int main()
-{
- ValueArray v;
-
- v.addDate("First school day",15, 9, 2021);
- v.addTime("Work day start", 10, 15);
- v.addDateTime("Portugal - Germany", 19, 06, 2021, 19, 10);
- v.addString("Name", "Test");
-
- v.print();
-} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/ValueArray/ValueArray.cpp b/Utills/si_14.06/task2/ValueArray/ValueArray.cpp
deleted file mode 100644
index 8e06a95..0000000
--- a/Utills/si_14.06/task2/ValueArray/ValueArray.cpp
+++ /dev/null
@@ -1,72 +0,0 @@
-#include <iostream>
-#include "ValueArray.h"
-#include "../Values/Date/Date.h"
-#include "../Values/Time/Time.h"
-#include "../Values/String/StringValue.h"
-#include "../Values/DateTime/DateTime.h"
-
-void ValueArray::print() const
-{
- std::cout << "[";
- for (int i = 0; i < arr.size(); i++)
- {
- std::cout << arr[i]->toString();
-
- if (i != arr.size() - 1)
- std::cout << ", ";
-
- }
- std::cout << "]";
-}
-
-
-void ValueArray::free()
-{
- for (int i = 0; i < arr.size(); i++)
- delete arr[i];
- arr.clear();
-}
-
-void ValueArray::copyFrom(const ValueArray& other)
-{
- arr.resize(other.arr.size());
-
- for (int i = 0; i < arr.size(); i++)
- arr[i] = other.arr[i]->clone();
-}
-
-void ValueArray::addDate(const std::string& name, unsigned day, unsigned month, unsigned year)
-{
- arr.push_back(new Date(name, day, month, year));
-}
-void ValueArray::addTime(const std::string& name, unsigned hours, unsigned mins)
-{
- arr.push_back(new Time(name, hours, mins));
-}
-void ValueArray::addString(const std::string& name, const std::string& value)
-{
- arr.push_back(new StringValue(name,value));
-}
-void ValueArray::addDateTime(const std::string& name, unsigned day, unsigned month, unsigned year, unsigned hours, unsigned mins)
-{
- arr.push_back(new DateTime(name, day, month, year, hours, mins));
-}
-
-ValueArray::ValueArray(const ValueArray& other)
-{
- copyFrom(other);
-}
-ValueArray& ValueArray::operator= (const ValueArray& other)
-{
- if (this != &other)
- {
- free();
- copyFrom(other);
- }
- return *this;
-}
-
-ValueArray::~ValueArray()
-{
- free();
-} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/ValueArray/ValueArray.h b/Utills/si_14.06/task2/ValueArray/ValueArray.h
deleted file mode 100644
index 39bdcbc..0000000
--- a/Utills/si_14.06/task2/ValueArray/ValueArray.h
+++ /dev/null
@@ -1,26 +0,0 @@
-#pragma once
-
-#include <vector>
-#include "../Values/ValueBase/Value.h"
-
-class ValueArray
-{
- std::vector<Value*> arr;
-
- void copyFrom(const ValueArray& other);
- void free();
-
-public:
- void print() const;
-
- ValueArray() = default;
- ValueArray(const ValueArray& other);
- ValueArray& operator=(const ValueArray& other);
-
- //factory pattern ?
- void addDate(const std::string& name, unsigned day, unsigned month, unsigned year);
- void addTime(const std::string& name, unsigned hours, unsigned mins);
- void addString(const std::string& name, const std::string& value);
- void addDateTime(const std::string& name, unsigned day, unsigned month, unsigned year, unsigned hours, unsigned mins);
- ~ValueArray();
-}; \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/Date/Date.cpp b/Utills/si_14.06/task2/Values/Date/Date.cpp
deleted file mode 100644
index 3d872d3..0000000
--- a/Utills/si_14.06/task2/Values/Date/Date.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "Date.h"
-
-//validation is needed for the date fields!
-Date::Date(const std::string& name, unsigned day, unsigned month, unsigned year) : Value(name), year(year), month(month), day(day)
-{}
-
-std::string Date::getDateString() const
-{
- return std::to_string(day) + "." + std::to_string(month) + "." + std::to_string(year);;
-}
-std::string Date::toString() const
-{
- return getPrefix() + getDateString() + "}";
-}
-
-Value* Date::clone() const
-{
- return new Date(*this);
-} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/Date/Date.h b/Utills/si_14.06/task2/Values/Date/Date.h
deleted file mode 100644
index 6194225..0000000
--- a/Utills/si_14.06/task2/Values/Date/Date.h
+++ /dev/null
@@ -1,22 +0,0 @@
-#pragma once
-
-#include "../ValueBase/Value.h"
-
-class Date : public virtual Value
-{
- unsigned day;
- unsigned month;
- unsigned year;
-
-protected:
-
- std::string getDateString() const;
-
-public:
-
- Date(const std::string& name, unsigned day, unsigned month, unsigned year);
-
- Value* clone() const;
-
- std::string toString() const;
-}; \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/DateTime/DateTime.cpp b/Utills/si_14.06/task2/Values/DateTime/DateTime.cpp
deleted file mode 100644
index b2e7e97..0000000
--- a/Utills/si_14.06/task2/Values/DateTime/DateTime.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "DateTime.h"
-
-DateTime::DateTime(const std::string& name, size_t day, size_t month, size_t year, size_t hours, size_t mins) : Value(name), Date(name, day, month, year), Time(name, hours,mins)
-{}
-
-std::string DateTime::toString() const
-{
- return getPrefix() + getDateString() + ", " + getTimeString() + "}";
-}
-
-Value* DateTime::clone() const
-{
- return new DateTime(*this);
-} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/DateTime/DateTime.h b/Utills/si_14.06/task2/Values/DateTime/DateTime.h
deleted file mode 100644
index 61d6a9a..0000000
--- a/Utills/si_14.06/task2/Values/DateTime/DateTime.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#pragma once
-
-#include "../Date/Date.h"
-#include "../Time/Time.h"
-
-class DateTime : public Date, public Time
-{
-public:
- DateTime(const std::string& name, size_t day, size_t month, size_t year, size_t hours, size_t mins);
-
- std::string toString() const;
-
- Value* clone() const;
-}; \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/String/StringValue.cpp b/Utills/si_14.06/task2/Values/String/StringValue.cpp
deleted file mode 100644
index 8d47f24..0000000
--- a/Utills/si_14.06/task2/Values/String/StringValue.cpp
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "StringValue.h"
-
-StringValue::StringValue(const std::string& name, const std::string& value) : Value(name), value(value)
-{}
-
-std::string StringValue::toString() const
-{
- return getPrefix() + '\"' + value + '\"' + "}";
-}
-
-Value* StringValue::clone() const
-{
- return new StringValue(*this);
-} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/String/StringValue.h b/Utills/si_14.06/task2/Values/String/StringValue.h
deleted file mode 100644
index 4e1500f..0000000
--- a/Utills/si_14.06/task2/Values/String/StringValue.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#pragma once
-
-#include "../ValueBase/Value.h"
-
-class StringValue : public Value
-{
- std::string value;
-public:
-
- StringValue(const std::string& name, const std::string& value);
-
- Value* clone() const;
-
- std::string toString() const;
-}; \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/Time/Time.cpp b/Utills/si_14.06/task2/Values/Time/Time.cpp
deleted file mode 100644
index 5b49e54..0000000
--- a/Utills/si_14.06/task2/Values/Time/Time.cpp
+++ /dev/null
@@ -1,19 +0,0 @@
-#include "Time.h"
-
-//validation is needed for the time fields!
-Time::Time(const std::string& name, unsigned hours, unsigned mins) : Value(name), hours(hours), mins(mins)
-{}
-
-std::string Time::getTimeString() const
-{
- return std::to_string(hours) + ":" + std::to_string(mins);
-}
-std::string Time::toString() const
-{
- return getPrefix() + getTimeString() + "}";
-}
-
-Value* Time::clone() const
-{
- return new Time(*this);
-} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/Time/Time.h b/Utills/si_14.06/task2/Values/Time/Time.h
deleted file mode 100644
index 1d93d49..0000000
--- a/Utills/si_14.06/task2/Values/Time/Time.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#pragma once
-
-#include "../ValueBase/Value.h"
-
-class Time : public virtual Value
-{
- unsigned hours;
- unsigned mins;
-
-protected:
- std::string Time::getTimeString() const;
-
-public:
- Time(const std::string& name, unsigned hours, unsigned mins);
-
- Value* clone() const;
-
- std::string toString() const;
-}; \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/ValueBase/Value.cpp b/Utills/si_14.06/task2/Values/ValueBase/Value.cpp
deleted file mode 100644
index cd7c821..0000000
--- a/Utills/si_14.06/task2/Values/ValueBase/Value.cpp
+++ /dev/null
@@ -1,11 +0,0 @@
-#include "Value.h"
-
-Value::Value(const std::string& valueName) : valueName(valueName)
-{
-
-}
-
-std::string Value::getPrefix() const
-{
- return "{ " + valueName + " : ";
-} \ No newline at end of file
diff --git a/Utills/si_14.06/task2/Values/ValueBase/Value.h b/Utills/si_14.06/task2/Values/ValueBase/Value.h
deleted file mode 100644
index e3320f3..0000000
--- a/Utills/si_14.06/task2/Values/ValueBase/Value.h
+++ /dev/null
@@ -1,18 +0,0 @@
-#pragma once
-#include <string>
-
-class Value
-{
-protected:
- std::string valueName;
-public:
- Value(const std::string& valueName);
-
- std::string getPrefix() const;
-
- virtual std::string toString() const = 0;
-
- virtual Value* clone() const = 0;
-
- virtual ~Value(){}
-}; \ No newline at end of file