├── Seminars ├── Sem.03 │ ├── Solutions │ │ ├── HexViewer │ │ │ ├── test.dat │ │ │ ├── cpp │ │ │ │ ├── HexViewer.cpp │ │ │ │ ├── stringHelperFunctions.cpp │ │ │ │ ├── commands.cpp │ │ │ │ └── fileOperations.cpp │ │ │ └── headers │ │ │ │ ├── startUp.h │ │ │ │ ├── file.h │ │ │ │ ├── stringHelperFunctions.h │ │ │ │ ├── fileOperations.h │ │ │ │ ├── commands.h │ │ │ │ ├── helperFunctions.h │ │ │ │ └── constants.h │ │ ├── task2.cpp │ │ ├── task3.cpp │ │ ├── ReadArrayOfInts.cpp │ │ ├── task1-write.cpp │ │ ├── task1-read.cpp │ │ └── DynamicNameStudent.cpp │ └── Pract.03 │ │ └── data.csv ├── Sem.02 │ ├── Solutions │ │ ├── Task03 │ │ │ ├── Constants.h │ │ │ ├── Student.h │ │ │ ├── Interface.h │ │ │ └── students.csv │ │ ├── Examples │ │ │ ├── constants.h │ │ │ ├── 03-positioning.cpp │ │ │ ├── 04-flags.cpp │ │ │ ├── 05-modes.cpp │ │ │ └── 01-console.cpp │ │ ├── getFileSize.cpp │ │ ├── temp-getLinesCount.cpp │ │ ├── printSourceCode.cpp │ │ ├── getCharCountFromFile.cpp │ │ └── copyFileContent.cpp │ ├── images │ │ ├── streams.png │ │ ├── hierarchy.png │ │ └── stream-flags.png │ └── Pract.02 │ │ ├── Task02.cpp │ │ ├── Task06.cpp │ │ └── Task01.cpp ├── Sem.05 │ ├── Pract. 05 │ │ ├── Task02 │ │ │ ├── GlobalConstants.h │ │ │ ├── ComplexNumbers.h │ │ │ └── Task02.cpp │ │ ├── Task04 │ │ │ ├── main.cpp │ │ │ └── Dates.h │ │ └── Task01 │ │ │ ├── Task01.cpp │ │ │ ├── Point.h │ │ │ └── Point.cpp │ └── Solutions │ │ ├── EventCollection │ │ ├── EventCollection.h │ │ └── EventCollection.cpp │ │ ├── Time │ │ └── Time.h │ │ ├── Date │ │ └── Date.h │ │ └── Event │ │ ├── Event.h │ │ └── Event.cpp ├── Sem.11 │ ├── img │ │ ├── VTable.PNG │ │ └── Diamond-problem.png │ └── Solutions │ │ ├── Lectures │ │ ├── Collection │ │ │ ├── CollectionOperation.cpp │ │ │ ├── Collection.h │ │ │ ├── CollectionOperation.h │ │ │ ├── NormalCollection.h │ │ │ ├── Union.h │ │ │ ├── Intersection.h │ │ │ ├── SortedCollection.h │ │ │ ├── Union.cpp │ │ │ ├── DynamicCollection.h │ │ │ ├── IntervalCollection.h │ │ │ ├── NormalCollection.cpp │ │ │ ├── Intersection.cpp │ │ │ ├── Source.cpp │ │ │ ├── readme.md │ │ │ └── DynamicCollection.cpp │ │ ├── Example_polymorphism │ │ │ ├── Rectangle.h │ │ │ ├── Circle.h │ │ │ ├── Triangle.h │ │ │ ├── Circle.cpp │ │ │ ├── Rectangle.cpp │ │ │ ├── Shape.h │ │ │ ├── Shape.cpp │ │ │ ├── main.cpp │ │ │ └── Triangle.cpp │ │ └── Example_mutualCatching │ │ │ ├── Rectangle.h │ │ │ ├── Triangle.h │ │ │ ├── Circle.h │ │ │ ├── main.cpp │ │ │ ├── Circle.cpp │ │ │ ├── Rectangle.cpp │ │ │ ├── Triangle.cpp │ │ │ ├── Shape.cpp │ │ │ └── Shape.h │ │ └── Shapes │ │ ├── hpp │ │ ├── Rectangle.h │ │ ├── Triangle.h │ │ ├── Circle.h │ │ └── Shape.h │ │ └── cpp │ │ ├── Circle.cpp │ │ ├── Rectangle.cpp │ │ ├── Shape.cpp │ │ ├── main.cpp │ │ └── Triangle.cpp ├── Sem.01 │ ├── images │ │ ├── union.JPG │ │ ├── padding.png │ │ ├── Paradigms.png │ │ ├── memory-types.png │ │ └── Selection-Sort.png │ ├── Pract.01 │ │ ├── img │ │ │ └── transpose.png │ │ ├── Task05.cpp │ │ ├── Task01.cpp │ │ ├── Task02.cpp │ │ ├── Task03.cpp │ │ └── Task04.cpp │ ├── Bonus │ │ ├── README.md │ │ ├── InsertionSort.cpp │ │ ├── SelectionSort.cpp │ │ ├── BubbleSort.cpp │ │ └── StableCountingSort.cpp │ └── memoryAllocation.cpp ├── Sem.10 │ ├── img │ │ ├── inher-img.png │ │ ├── visibility.png │ │ └── class-hierarchy.png │ └── Solutions │ │ ├── Person-Student-Teacher │ │ ├── Teacher │ │ │ └── Teacher.h │ │ ├── Student │ │ │ ├── Student.h │ │ │ └── Student.cpp │ │ └── Person │ │ │ ├── Person.h │ │ │ └── Person.cpp │ │ └── Small String Optimization (SSO) │ │ └── MyStringSSO.h ├── Sem.06 │ ├── Pract. 06 │ │ ├── img │ │ │ ├── csv.png │ │ │ └── shoppingcart.png │ │ ├── Task01 │ │ │ ├── MonsterCard.h │ │ │ ├── MagicCard.cpp │ │ │ ├── MonsterCard.cpp │ │ │ ├── MagicCard.h │ │ │ ├── Duelist.h │ │ │ └── Deck.h │ │ └── Task02 │ │ │ ├── Item.h │ │ │ ├── ShoppingCart.h │ │ │ └── Item.cpp │ └── Solutions │ │ ├── SetOfNumbers │ │ ├── exampleMain.cpp │ │ └── SetOfNumbers.h │ │ └── Person │ │ ├── Person.h │ │ └── Person.cpp ├── Sem.08 │ ├── Solutions │ │ ├── FlightsScanner - Exception handling task │ │ │ ├── inputFlights.txt │ │ │ ├── Utills.h │ │ │ ├── source.cpp │ │ │ ├── FlightsScanner.h │ │ │ └── Utills.cpp │ │ ├── CarDealership │ │ │ ├── Car │ │ │ │ ├── Car.h │ │ │ │ └── Car.cpp │ │ │ └── CarDealership │ │ │ │ ├── CarDealership.h │ │ │ │ └── CarDealership.cpp │ │ ├── Singleton │ │ │ ├── Singleton.h │ │ │ └── Singleton.cpp │ │ ├── SelfCounting │ │ │ ├── SelfCounting.h │ │ │ └── SelfCounting.cpp │ │ ├── StringView │ │ │ ├── StringView.h │ │ │ └── StringView.cpp │ │ ├── String │ │ │ └── String.h │ │ ├── Vector │ │ │ └── Vector.h │ │ └── StringPool │ │ │ └── StringPool.h │ └── Pract.08 │ │ └── Task01 │ │ ├── MyString.cpp │ │ ├── Teacher.h │ │ ├── Teacher.cpp │ │ ├── Grade.h │ │ ├── MyString.h │ │ ├── Student.h │ │ ├── Grade.cpp │ │ └── OOPcourse.h ├── Utils │ ├── TheoryExamples │ │ ├── Sem3.cpp │ │ ├── Sem4.cpp │ │ ├── Sem2.cpp │ │ ├── Sorting.cpp │ │ └── RuleOf4.cpp │ ├── Tasks │ │ ├── Task01 │ │ │ ├── main.cpp │ │ │ ├── Server │ │ │ │ └── Server.h │ │ │ └── User │ │ │ │ └── User.h │ │ └── Task02 │ │ │ ├── Passenger.h │ │ │ ├── Passenger.cpp │ │ │ ├── Bus.h │ │ │ ├── Bus.cpp │ │ │ ├── Trip.h │ │ │ ├── main.cpp │ │ │ └── BusStation.h │ └── Exam │ │ ├── Task02 │ │ ├── NaturalNumbersFunction.hpp │ │ └── ModifiableNaturalNumbersFunction.hpp │ │ └── Task01 │ │ └── EventDuringJanuary2023.h ├── Sem.13 │ ├── Solutions │ │ ├── swap.hpp │ │ ├── Pair │ │ │ ├── Source2.cpp │ │ │ └── Pair.hpp │ │ ├── Optional │ │ │ └── Source.cpp │ │ ├── TemplateFunctionSpecification.hpp │ │ └── FixedLengthStack │ │ │ └── FixedLengthStack.hpp │ └── README.md ├── Sem.09 │ ├── Pract.09 │ │ ├── Task01 │ │ │ ├── Product │ │ │ │ ├── Product.cpp │ │ │ │ └── Product.h │ │ │ ├── Order │ │ │ │ └── Order.h │ │ │ ├── Restaurant │ │ │ │ └── Restaurant.h │ │ │ ├── Foodpanda │ │ │ │ └── Foodpanda.h │ │ │ └── MyString │ │ │ │ └── MyString.h │ │ └── README.md │ └── Solutions │ │ ├── String │ │ ├── String.hpp │ │ └── String.cpp │ │ └── CompositionMoveSemantics.cpp ├── Sem.04 │ ├── Solutions │ │ ├── Interval │ │ │ ├── main.cpp │ │ │ └── Interval.h │ │ ├── Time │ │ │ └── Time.h │ │ └── Date │ │ │ └── Date.h │ └── Pract.04 │ │ ├── Task01 │ │ ├── Teacher.h │ │ └── Teacher.cpp │ │ ├── Task02 │ │ ├── main.cpp │ │ ├── Task.h │ │ ├── Exam.h │ │ └── Task.cpp │ │ ├── Task04 │ │ ├── Secret.h │ │ ├── OOP_Pract.cpp │ │ └── Secret.cpp │ │ └── Task03 │ │ ├── Game.h │ │ ├── GamePlatform.h │ │ └── main.cpp ├── Sem.07 │ └── Solution │ │ ├── NVector │ │ ├── Cartesian.h │ │ ├── Cartesian.cpp │ │ └── NVector.h │ │ ├── Rational │ │ └── Rational.h │ │ └── Complex │ │ └── ComplexNum.h ├── Sem.12 │ └── Solutions │ │ ├── Shapes │ │ ├── hpp │ │ │ ├── Rectangle.h │ │ │ ├── Triangle.h │ │ │ ├── Circle.h │ │ │ └── Shape.h │ │ └── cpp │ │ │ ├── Circle.cpp │ │ │ ├── Rectangle.cpp │ │ │ ├── Shape.cpp │ │ │ └── Triangle.cpp │ │ └── ShapeCollection │ │ └── ShapeCollection.h ├── Sem.14 │ ├── Pract. 14 │ │ ├── Bar │ │ │ ├── AlcoholDrink │ │ │ │ ├── AlcoholDrink.h │ │ │ │ └── AlcoholDrink.cpp │ │ │ ├── Drink │ │ │ │ ├── Drink.h │ │ │ │ └── Drink.cpp │ │ │ ├── Bar │ │ │ │ ├── Bar.h │ │ │ │ └── Bar.cpp │ │ │ ├── main.cpp │ │ │ ├── Pair │ │ │ │ └── Pair.hpp │ │ │ └── MyString │ │ │ │ └── MyString.h │ │ └── README.md │ └── Solutions │ │ ├── ExpressionCalculator │ │ ├── main.cpp │ │ └── MyString │ │ │ ├── StringView.h │ │ │ ├── StringView.cpp │ │ │ └── MyString.h │ │ └── MyString │ │ ├── StringView.h │ │ ├── StringView.cpp │ │ └── MyString.h └── Sem.15 │ └── Solutions │ └── Design-Patterns │ ├── README.md │ ├── Structural Patterns │ ├── README.md │ └── Adapter │ │ └── Adapter.ts │ ├── Behavioral Patterns │ └── README.md │ └── Creational Patterns │ └── README.md ├── Github-Workflow ├── images │ ├── fetch-origin.png │ ├── star-the-repo.png │ ├── repository-fork-settings.png │ └── repository-settings-menu.png └── Инструкции за работа с GitHub.pdf ├── README.md └── .gitignore /Seminars/Sem.03/Solutions/HexViewer/test.dat: -------------------------------------------------------------------------------- 1 | Aee -------------------------------------------------------------------------------- /Seminars/Sem.03/Pract.03/data.csv: -------------------------------------------------------------------------------- 1 | First,F,11111,5.2,BLACK 2 | Second,S,22222,5.5,BLONDE 3 | Third,T,33333,4.7,BLONDE -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/HexViewer/cpp/HexViewer.cpp: -------------------------------------------------------------------------------- 1 | #include "../startUp.h" 2 | 3 | int main() 4 | { 5 | run(); 6 | return 0; 7 | } -------------------------------------------------------------------------------- /Seminars/Sem.02/Solutions/Task03/Constants.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | const int FIELD_MAX_SIZE = 50; 4 | const int BUFFER_LINE_SIZE = 1024; 5 | -------------------------------------------------------------------------------- /Seminars/Sem.05/Pract. 05/Task02/GlobalConstants.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace GlobalConstants { 4 | const double EPSILON = 0.000001; 5 | } -------------------------------------------------------------------------------- /Seminars/Sem.11/img/VTable.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.11/img/VTable.PNG -------------------------------------------------------------------------------- /Seminars/Sem.01/images/union.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.01/images/union.JPG -------------------------------------------------------------------------------- /Seminars/Sem.01/images/padding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.01/images/padding.png -------------------------------------------------------------------------------- /Seminars/Sem.02/images/streams.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.02/images/streams.png -------------------------------------------------------------------------------- /Seminars/Sem.10/img/inher-img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.10/img/inher-img.png -------------------------------------------------------------------------------- /Seminars/Sem.10/img/visibility.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.10/img/visibility.png -------------------------------------------------------------------------------- /Seminars/Sem.01/images/Paradigms.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.01/images/Paradigms.png -------------------------------------------------------------------------------- /Seminars/Sem.02/images/hierarchy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.02/images/hierarchy.png -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/HexViewer/headers/startUp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "file.h" 4 | 5 | void startMenu(File& file); 6 | 7 | void run(); 8 | -------------------------------------------------------------------------------- /Seminars/Sem.06/Pract. 06/img/csv.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.06/Pract. 06/img/csv.png -------------------------------------------------------------------------------- /Github-Workflow/images/fetch-origin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Github-Workflow/images/fetch-origin.png -------------------------------------------------------------------------------- /Github-Workflow/images/star-the-repo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Github-Workflow/images/star-the-repo.png -------------------------------------------------------------------------------- /Seminars/Sem.01/images/memory-types.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.01/images/memory-types.png -------------------------------------------------------------------------------- /Seminars/Sem.02/images/stream-flags.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.02/images/stream-flags.png -------------------------------------------------------------------------------- /Seminars/Sem.10/img/class-hierarchy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.10/img/class-hierarchy.png -------------------------------------------------------------------------------- /Seminars/Sem.11/img/Diamond-problem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.11/img/Diamond-problem.png -------------------------------------------------------------------------------- /Seminars/Sem.01/Pract.01/img/transpose.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.01/Pract.01/img/transpose.png -------------------------------------------------------------------------------- /Seminars/Sem.01/images/Selection-Sort.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.01/images/Selection-Sort.png -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/FlightsScanner - Exception handling task/inputFlights.txt: -------------------------------------------------------------------------------- 1 | soF muN 32 2 | Ber LoN 434 3 | Rom Prs t5t 4 | Rome PlD 23 5 | Mad Mscs 444 6 | dsfs -------------------------------------------------------------------------------- /Seminars/Sem.08/Pract.08/Task01/MyString.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.08/Pract.08/Task01/MyString.cpp -------------------------------------------------------------------------------- /Seminars/Sem.06/Pract. 06/img/shoppingcart.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Seminars/Sem.06/Pract. 06/img/shoppingcart.png -------------------------------------------------------------------------------- /Github-Workflow/Инструкции за работа с GitHub.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Github-Workflow/Инструкции за работа с GitHub.pdf -------------------------------------------------------------------------------- /Github-Workflow/images/repository-fork-settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Github-Workflow/images/repository-fork-settings.png -------------------------------------------------------------------------------- /Github-Workflow/images/repository-settings-menu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Justsvetoslavov/Object-oriented_programming_FMI/HEAD/Github-Workflow/images/repository-settings-menu.png -------------------------------------------------------------------------------- /Seminars/Sem.02/Solutions/Examples/constants.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | const short BUFFER_SIZE = 1024; 4 | const char FILE_NAME[] = "test.txt"; 5 | const char INVALID_FILE_ERR_MSG[] = "Error opening the file"; 6 | -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/HexViewer/headers/file.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "constants.h" 4 | 5 | struct File { 6 | unsigned int size = 0; 7 | char name[FILE_NAME_SIZE]; 8 | char data[FILE_SIZE]; 9 | }; -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/CollectionOperation.cpp: -------------------------------------------------------------------------------- 1 | #include "CollectionOperation.h" 2 | 3 | CollectionOperation::CollectionOperation(Collection& l, Collection& r) : 4 | left(l), right(r) {} 5 | -------------------------------------------------------------------------------- /Seminars/Utils/TheoryExamples/Sem3.cpp: -------------------------------------------------------------------------------- 1 | // https://github.com/GeorgiTerziev02/Object-oriented_programming_FMI/tree/main/Sem.%2003 2 | // Check carefully reading and writing from/to binary file 3 | // in all scenarios -------------------------------------------------------------------------------- /Seminars/Sem.13/Solutions/swap.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | template 5 | void swap(T& lhs, T& rhs) { 6 | T temp = std::move(lhs); 7 | lhs = std::move(rhs); 8 | rhs = std::move(lhs); 9 | } -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/CarDealership/Car/Car.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Car { 4 | private: 5 | size_t number; 6 | 7 | public: 8 | Car(size_t number); 9 | size_t getNumber() const; 10 | void setNumber(size_t number); 11 | }; -------------------------------------------------------------------------------- /Seminars/Sem.13/Solutions/Pair/Source2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Pair.hpp" 3 | 4 | int main() { 5 | Pair p(3, 'd'); 6 | 7 | std::cout << p.getSecond(); 8 | 9 | p.setSecond('a'); 10 | 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /Seminars/Sem.02/Solutions/Task03/Student.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Constants.h" 3 | 4 | struct Student 5 | { 6 | char first_name[FIELD_MAX_SIZE]; 7 | char last_name[FIELD_MAX_SIZE]; 8 | char email[FIELD_MAX_SIZE]; 9 | unsigned fn = 0; 10 | }; -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/FlightsScanner - Exception handling task/Utills.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | bool isLower(char ch); 4 | bool isSymbol(char ch); 5 | void toUpper(char* str); 6 | unsigned charToDigit(char ch); 7 | unsigned convertToNumber(const char* str); -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/FlightsScanner - Exception handling task/source.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "FlightsScanner.h" 3 | 4 | int main() 5 | { 6 | FlightsScanner scanner("inputFlights.txt", "outputFlights.txt", 10); 7 | scanner.run(); 8 | } -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/HexViewer/headers/stringHelperFunctions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | int strLength(const char* str); 4 | 5 | char* subStr(const char* str, const int& startIndex, const int& endIndex); 6 | 7 | bool strCmp(const char* str1, const char* str2); -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/HexViewer/headers/fileOperations.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "file.h" 5 | 6 | bool saveToFile(const File& file, const char* fileName); 7 | 8 | int getFileSize(std::ifstream& file); 9 | 10 | bool readFile(File& file); -------------------------------------------------------------------------------- /Seminars/Sem.09/Pract.09/Task01/Product/Product.cpp: -------------------------------------------------------------------------------- 1 | #include "Product.h" 2 | #include 3 | 4 | Product::Product(const MyString& name) { 5 | this->name = MyString(name); 6 | } 7 | 8 | const MyString& Product::GetProductName() const { 9 | return this->name; 10 | } -------------------------------------------------------------------------------- /Seminars/Sem.09/Pract.09/Task01/Product/Product.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "MyString.h" 3 | class Product 4 | { 5 | private: 6 | MyString name; 7 | public: 8 | Product() = default; 9 | Product(const MyString& name); 10 | 11 | const MyString& GetProductName() const; 12 | }; -------------------------------------------------------------------------------- /Seminars/Sem.04/Solutions/Interval/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Interval.h" 3 | 4 | int main() 5 | { 6 | Interval i(1, 11); 7 | 8 | std::cout << i.CalcDiffrentDigitNumbersInTheInverval() << std::endl; 9 | 10 | std::cout << i.GetLength() << std::endl; 11 | } 12 | -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/CarDealership/Car/Car.cpp: -------------------------------------------------------------------------------- 1 | #include "Car.h" 2 | 3 | Car::Car(size_t number) { 4 | setNumber(number); 5 | } 6 | 7 | size_t Car::getNumber() const { 8 | return number; 9 | } 10 | 11 | void Car::setNumber(size_t number) { 12 | this->number = number; 13 | } -------------------------------------------------------------------------------- /Seminars/Sem.08/Pract.08/Task01/Teacher.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MyString.h" 4 | 5 | class Teacher { 6 | MyString _name; 7 | public: 8 | Teacher(); 9 | Teacher(const char* name); 10 | 11 | friend std::ostream& operator << (std::ostream& os, const Teacher& teacher); 12 | }; -------------------------------------------------------------------------------- /Seminars/Sem.13/Solutions/Optional/Source.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Optional.hpp" 3 | 4 | int main() { 5 | Optional d; //no value 6 | 7 | d.setData(3); 8 | 9 | d.getData(); 10 | 11 | d.clear(); 12 | 13 | std::cout << d.containsData(); 14 | 15 | return 0; 16 | } 17 | -------------------------------------------------------------------------------- /Seminars/Utils/Tasks/Task01/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "./Server/Server.h" 4 | 5 | void main() { 6 | Server s; 7 | s.readFromFile(); 8 | //s.addUser("Test", "Test"); 9 | //s.addUser("Test1", "Test1"); 10 | 11 | //s.writeToFile(); 12 | s.print(); 13 | } -------------------------------------------------------------------------------- /Seminars/Sem.02/Solutions/getFileSize.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size_t GetFileSize(std::ifstream& in) 5 | { 6 | size_t current = in.tellg(); 7 | in.seekg(0, std::ios::end); 8 | size_t size = in.tellg(); 9 | in.seekg(current, std::ios::beg); 10 | 11 | return size; 12 | } -------------------------------------------------------------------------------- /Seminars/Sem.05/Pract. 05/Task04/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Dates.h" 3 | 4 | int main() 5 | { 6 | Date d1(31, Months::March, 2014); 7 | Date d2; 8 | d1.addDays(1); 9 | d1.removeDays(1); 10 | d1.daysToXmas(); 11 | d1.isLeapYear(); 12 | d1.isEarlierThan(d2); 13 | } -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/Collection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class Collection 3 | { 4 | public: 5 | virtual void add(int) = 0; 6 | virtual void remove(int) = 0; 7 | virtual unsigned count(int) const = 0; 8 | virtual bool contains(int) const = 0; 9 | 10 | virtual ~Collection() = default; 11 | }; -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/CollectionOperation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Collection.h" 3 | 4 | class CollectionOperation : public Collection 5 | { 6 | protected: 7 | Collection& left; 8 | Collection& right; 9 | public: 10 | CollectionOperation(Collection& l, Collection& r); 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /Seminars/Sem.02/Pract.02/Task02.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | size_t GetFileSize(const char* name) 4 | { 5 | std::ifstream in(name); 6 | if (!in.is_open()) { 7 | return 0; 8 | } 9 | 10 | in.seekg(0, std::ios::end); 11 | size_t currentPos = in.tellg(); 12 | 13 | in.close(); 14 | return currentPos; 15 | } -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/HexViewer/headers/commands.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "file.h" 4 | 5 | void viewFile(const File& file); 6 | 7 | bool changeByteAtIndex(File& file, const char& character, int index); 8 | 9 | bool removeByteFromEnd(File& file); 10 | 11 | bool addByteToEnd(File& file, const char& character); -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Shapes/hpp/Rectangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Shape.h" 3 | 4 | class Rectangle : public Shape { 5 | public: 6 | Rectangle(int x1, int y1, int x3, int y3); 7 | 8 | double GetArea() const override; 9 | double GetPer() const override; 10 | bool IsPointIn(int x, int y) const override; 11 | }; -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Shapes/hpp/Triangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Shape.h" 4 | 5 | class Triangle : public Shape { 6 | public: 7 | Triangle(int x1, int y1, int x2, int y2, int x3, int y3); 8 | 9 | double GetArea() const override; 10 | double GetPer() const override; 11 | bool IsPointIn(int x, int y) const override; 12 | }; -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_polymorphism/Rectangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Shape.h" 3 | 4 | class Rectangle : public Shape 5 | { 6 | public: 7 | Rectangle(int x1, int y1, int x3, int y3); 8 | double getArea() const override; 9 | double getPer() const override; 10 | bool isPointIn(int x, int y) const override; 11 | 12 | }; -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Shapes/hpp/Circle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Shape.h" 3 | 4 | class Circle : public Shape { 5 | private: 6 | double radius; 7 | public: 8 | Circle(int x, int y, double radius); 9 | 10 | double GetArea() const override; 11 | double GetPer() const override; 12 | bool IsPointIn(int x, int y) const override; 13 | }; -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/NormalCollection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"DynamicCollection.h" 3 | 4 | class NormalCollection : public DynamicCollection 5 | { 6 | public: 7 | void add(int) override; 8 | void remove(int) override; 9 | unsigned count(int) const override; 10 | bool contains(int) const override; 11 | }; 12 | 13 | -------------------------------------------------------------------------------- /Seminars/Sem.02/Solutions/temp-getLinesCount.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "constants.h" 4 | 5 | size_t GetLinesCount(std::ifstream& in) 6 | { 7 | size_t counter = 0; 8 | while (!in.eof()) { 9 | char buffer[BUFFER_SIZE]; 10 | in.getline(buffer, BUFFER_SIZE, '\n'); 11 | counter++; 12 | } 13 | 14 | return counter; 15 | } -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/Union.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"CollectionOperation.h" 3 | class Union : public CollectionOperation 4 | { 5 | public: 6 | Union(Collection& l, Collection& r); 7 | 8 | void add(int) override; 9 | void remove(int) override; 10 | unsigned count(int) const override; 11 | bool contains(int) const override; 12 | }; -------------------------------------------------------------------------------- /Seminars/Sem.07/Solution/NVector/Cartesian.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "NVector.h" 3 | 4 | class Cartesian2D { 5 | private: 6 | Nvector first; 7 | Nvector second; 8 | public: 9 | Cartesian2D(const Nvector&, const Nvector&); 10 | 11 | Nvector getVectorByCoordinates(const Nvector&) const; 12 | Nvector getCoordinatesByVector(const Nvector&) const; 13 | }; 14 | -------------------------------------------------------------------------------- /Seminars/Sem.12/Solutions/Shapes/hpp/Rectangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Shape.h" 3 | 4 | class Rectangle : public Shape { 5 | public: 6 | Rectangle(int x1, int y1, int x3, int y3); 7 | 8 | double GetArea() const override; 9 | double GetPer() const override; 10 | bool IsPointIn(int x, int y) const override; 11 | virtual Shape* clone() const override; 12 | }; -------------------------------------------------------------------------------- /Seminars/Sem.08/Pract.08/Task01/Teacher.cpp: -------------------------------------------------------------------------------- 1 | #include "Teacher.h" 2 | 3 | const char* DEFAULT_NAME = ""; 4 | 5 | Teacher::Teacher() : Teacher(DEFAULT_NAME){ 6 | 7 | } 8 | 9 | Teacher::Teacher(const char* name) { 10 | _name = MyString(name); 11 | } 12 | 13 | std::ostream& operator << (std::ostream& os, const Teacher& teacher) { 14 | return os << teacher._name; 15 | } -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_polymorphism/Circle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Shape.h" 3 | 4 | class Circle : public Shape 5 | { 6 | double radius; 7 | 8 | public: 9 | Circle(int x, int y, double radius); 10 | 11 | double getArea() const override; 12 | double getPer() const override; 13 | bool isPointIn(int x, int y) const override; 14 | 15 | }; -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_polymorphism/Triangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Shape.h" 4 | 5 | class Triangle : public Shape 6 | { 7 | 8 | public: 9 | Triangle(int x1, int y1, int x2, int y2, int x3, int y3); 10 | double getArea() const override; 11 | double getPer() const override; 12 | bool isPointIn(int x, int y) const override; 13 | 14 | }; -------------------------------------------------------------------------------- /Seminars/Utils/Tasks/Task02/Passenger.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | const unsigned MAX_NAME_SIZE = 20; 5 | class Passenger 6 | { 7 | char name[MAX_NAME_SIZE]; 8 | int age; 9 | 10 | public: 11 | Passenger(); 12 | Passenger(const char* name, int age); 13 | const char* getName() const; 14 | int getAge() const; 15 | 16 | bool isStudent() const; 17 | }; -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/Singleton/Singleton.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Singleton { 4 | private: 5 | static Singleton* instance; 6 | Singleton(); 7 | 8 | public: 9 | Singleton(const Singleton&) = delete; 10 | Singleton& operator=(const Singleton&) = delete; 11 | static Singleton* getInstance(); 12 | static void freeInstance(); 13 | ~Singleton(); 14 | }; 15 | 16 | -------------------------------------------------------------------------------- /Seminars/Sem.12/Solutions/Shapes/hpp/Triangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Shape.h" 4 | 5 | class Triangle : public Shape { 6 | public: 7 | Triangle(int x1, int y1, int x2, int y2, int x3, int y3); 8 | 9 | double GetArea() const override; 10 | double GetPer() const override; 11 | bool IsPointIn(int x, int y) const override; 12 | virtual Shape* clone() const override; 13 | }; -------------------------------------------------------------------------------- /Seminars/Sem.12/Solutions/Shapes/hpp/Circle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Shape.h" 3 | 4 | class Circle : public Shape { 5 | private: 6 | double radius; 7 | public: 8 | Circle(int x, int y, double radius); 9 | 10 | double GetArea() const override; 11 | double GetPer() const override; 12 | bool IsPointIn(int x, int y) const override; 13 | virtual Shape* clone() const override; 14 | }; -------------------------------------------------------------------------------- /Seminars/Sem.14/Pract. 14/Bar/AlcoholDrink/AlcoholDrink.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../Drink/Drink.h" 3 | #include "../Queue/Queue.hpp" 4 | #include "../Pair/Pair.hpp" 5 | 6 | class AlcoholDrink : public Drink 7 | { 8 | int alcP; 9 | public: 10 | AlcoholDrink(); 11 | AlcoholDrink(const MyString& name, int ml, int alcP); 12 | 13 | void setAlcP(int alcP); 14 | int getAlcP() const; 15 | }; -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/Intersection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"CollectionOperation.h" 3 | class Intersection : public CollectionOperation 4 | { 5 | public: 6 | Intersection(Collection& left, Collection& right); 7 | 8 | void add(int) override; 9 | void remove(int) override; 10 | unsigned count(int) const override; 11 | bool contains(int) const override; 12 | }; 13 | 14 | -------------------------------------------------------------------------------- /Seminars/Sem.14/Pract. 14/Bar/Drink/Drink.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../MyString/MyString.h" 3 | 4 | class Drink 5 | { 6 | public: 7 | 8 | Drink(); 9 | Drink(const MyString& name, int ml); 10 | 11 | const MyString& getName() const; 12 | int getMl() const; 13 | 14 | void setName(const MyString& name); 15 | void setMl(int ml); 16 | 17 | private: 18 | MyString name; 19 | int ml; 20 | 21 | }; -------------------------------------------------------------------------------- /Seminars/Sem.02/Solutions/Task03/Interface.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #pragma warning (disable: 4996) 3 | #include "Student.h" 4 | 5 | int toSeparator(const char*); 6 | 7 | bool printStudent(const Student*, size_t, const int); 8 | 9 | bool editFirstName(Student*, size_t, const int, const char*); 10 | 11 | bool saveStudentsToFile(const Student* , size_t , const char*); 12 | 13 | void interface(Student* , const int); 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Материали от лекции, семинари и практикуми по "Обектно-ориентирано програмиране" 2 | #### летен семестър 2022/2023, спец. Софтуерно инженерство & Информационни системи 3 | - [Материали от упражнения](https://github.com/Justsvetoslavov/Object-oriented_programming_FMI/tree/master/Seminars) 4 | - [Инструкции за работа с Github](https://github.com/Justsvetoslavov/Object-oriented_programming_FMI/tree/master/Github-Workflow) 5 | -------------------------------------------------------------------------------- /Seminars/Sem.14/Solutions/ExpressionCalculator/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ExpressionCalculator.h" 3 | 4 | int main() { 5 | ExpressionCalculator ta("(Pv(!P))"); 6 | ExpressionCalculator c("(P^(!P))"); 7 | 8 | std::cout << ta.isTautology() << std::endl; 9 | std::cout << ta.isContradiction() << std::endl; 10 | 11 | std::cout << c.isTautology() << std::endl; 12 | std::cout << c.isContradiction() << std::endl; 13 | } -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/SelfCounting/SelfCounting.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class SelfCounting { 4 | private: 5 | const int constValue; 6 | 7 | static size_t liveObjectCount; 8 | static size_t createdCount; 9 | public: 10 | SelfCounting(); 11 | SelfCounting(int val); 12 | SelfCounting(const SelfCounting& other); 13 | ~SelfCounting(); 14 | 15 | static size_t getLiveObjectCount(); 16 | static size_t getCreatedCount(); 17 | }; 18 | -------------------------------------------------------------------------------- /Seminars/Sem.02/Solutions/Task03/students.csv: -------------------------------------------------------------------------------- 1 | Name,Last name,Email,Faculty number 2 | Peter,Ivanov,peter@mail.bg,81235 3 | Alexander,Popov,popov@abv.bg,81234 4 | Stefan,Velikov,velikov@mail.bg,81876 5 | Krasimir,Petkov,krasi@abv.bg,81234 6 | Stefani,Angelova,stef@gmail.com,81876 7 | Ivana,Marinova,ivana@abv.bg,81321 8 | Stefan,Velkov,stefan@yahoo.com,80000 9 | Krasimira,Markova,krasi@mail.bg,81234 10 | Wladimir,Klitschko,wlad@kiev.com,89999 11 | -------------------------------------------------------------------------------- /Seminars/Sem.05/Solutions/EventCollection/EventCollection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../Event/Event.h" 3 | 4 | class EventCollection { 5 | private: 6 | Event data[20]; 7 | unsigned count = 0; // 0 ... count - 1 са добавени. От count до 19 са обекти създадени с default-на стойност, 8 | public: 9 | EventCollection() = default; 10 | bool addEvent(const Event& event); 11 | void remove(unsigned ind); 12 | const Event& getByIndex(unsigned ind) const; 13 | }; 14 | -------------------------------------------------------------------------------- /Seminars/Sem.02/Pract.02/Task06.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int BUFFER_SIZE = 1024; 5 | 6 | bool PrintSourceCode(const char fileName[]) 7 | { 8 | std::ifstream in(fileName); 9 | 10 | if (!in.is_open()) { 11 | return false; 12 | } 13 | 14 | while (!in.eof()) { 15 | char buffer[BUFFER_SIZE]; 16 | in.getline(buffer, BUFFER_SIZE); 17 | std::cout << buffer << std::endl; 18 | } 19 | 20 | in.close(); 21 | return true; 22 | } -------------------------------------------------------------------------------- /Seminars/Sem.14/Pract. 14/Bar/AlcoholDrink/AlcoholDrink.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "AlcoholDrink.h" 3 | 4 | AlcoholDrink::AlcoholDrink():alcP(5) {} 5 | 6 | AlcoholDrink::AlcoholDrink(const MyString& name, int ml, int alcP) :Drink(name, ml) 7 | { 8 | setAlcP(alcP); 9 | } 10 | void AlcoholDrink::setAlcP(int alcP) 11 | { 12 | if (alcP < 5 || alcP > 98) 13 | alcP = 50; 14 | this->alcP = alcP; 15 | } 16 | int AlcoholDrink::getAlcP() const 17 | { 18 | return alcP; 19 | } -------------------------------------------------------------------------------- /Seminars/Sem.09/Solutions/String/String.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class String { 4 | private: 5 | char* data = nullptr; 6 | public: 7 | String() = default; 8 | String(const char*); 9 | String(const String&); 10 | String& operator=(const String&); 11 | ~String(); 12 | 13 | //move semantics 14 | String(String&&) noexcept; 15 | String& operator=(String&&) noexcept; 16 | 17 | void Print() const; 18 | private: 19 | void CopyFrom(const String&); 20 | void Free(); 21 | }; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore IDE folders 2 | .idea/* 3 | .vs/* 4 | .vscode/* 5 | 6 | # Prerequisites 7 | *.d 8 | 9 | # Compiled Object files 10 | *.slo 11 | *.lo 12 | *.o 13 | *.obj 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Compiled Dynamic libraries 20 | *.so 21 | *.dylib 22 | *.dll 23 | 24 | # Fortran module files 25 | *.mod 26 | *.smod 27 | 28 | # Compiled Static libraries 29 | *.lai 30 | *.la 31 | *.a 32 | *.lib 33 | 34 | # Executables 35 | *.exe 36 | *.out 37 | *.app 38 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Shapes/cpp/Circle.cpp: -------------------------------------------------------------------------------- 1 | #include "Circle.h" 2 | 3 | const double PI = 3.1415; 4 | 5 | Circle::Circle(int x, int y, double radius) : Shape(1), radius(radius) { 6 | setPoint(0, x, y); 7 | } 8 | 9 | double Circle::GetArea() const { 10 | return PI * radius * radius; 11 | } 12 | 13 | double Circle::GetPer() const { 14 | return 2 * PI * radius; 15 | } 16 | 17 | bool Circle::IsPointIn(int x, int y) const { 18 | return Point(x, y).getDist(getPointAtIndex(0)) <= radius; 19 | } -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_mutualCatching/Rectangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Shape.h" 3 | 4 | class Rectangle : public Shape 5 | { 6 | public: 7 | Rectangle(int x1, int y1, int x3, int y3); 8 | 9 | bool intersectsWith(const Shape* other) const override; 10 | 11 | bool intersectsWithTriangle(const Triangle* other) const override; 12 | bool intersectsWithRect(const Rectangle* other) const override; 13 | bool intersectsWithCircle(const Circle* other) const override; 14 | 15 | }; -------------------------------------------------------------------------------- /Seminars/Sem.02/Solutions/printSourceCode.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "constants.h" 4 | 5 | bool PrintSourceCode(const char* fileName) 6 | { 7 | std::ifstream in(fileName); 8 | 9 | if (!in.is_open()) { 10 | std::cout << INVALID_FILE_ERR_MSG; 11 | return false; 12 | } 13 | 14 | while (!in.eof()) { 15 | char buffer[BUFFER_SIZE]; 16 | in.getline(buffer, BUFFER_SIZE); 17 | std::cout << buffer << std::endl; 18 | } 19 | 20 | in.close(); 21 | return true; 22 | } -------------------------------------------------------------------------------- /Seminars/Utils/Tasks/Task02/Passenger.cpp: -------------------------------------------------------------------------------- 1 | #include "Passenger.h" 2 | #pragma warning (disable : 4996) 3 | 4 | Passenger::Passenger() : name(""), age(0) {} 5 | 6 | Passenger::Passenger(const char* name, int age) 7 | { 8 | strcpy(this->name, name); 9 | this->age = age; 10 | } 11 | 12 | const char* Passenger::getName() const 13 | { 14 | return name; 15 | } 16 | 17 | int Passenger::getAge() const 18 | { 19 | return age; 20 | } 21 | 22 | bool Passenger::isStudent() const 23 | { 24 | return age < 18; 25 | } -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_mutualCatching/Triangle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Shape.h" 4 | 5 | class Triangle : public Shape 6 | { 7 | 8 | public: 9 | Triangle(int x1, int y1, int x2, int y2, int x3, int y3); 10 | 11 | bool intersectsWith(const Shape* other) const override; 12 | 13 | bool intersectsWithTriangle(const Triangle* other) const override; 14 | bool intersectsWithRect(const Rectangle* other) const override; 15 | bool intersectsWithCircle(const Circle* other) const override; 16 | 17 | }; -------------------------------------------------------------------------------- /Seminars/Sem.01/Bonus/README.md: -------------------------------------------------------------------------------- 1 | ## Бонус: Алгоритми за сортиране 2 | 3 | От курса по УП трябва да знаете следните сортировки: 4 | * Bubble sort 5 | * Insertion sort 6 | * Selection sort 7 | * Counting sort 8 | 9 | Как работят нагледно: https://visualgo.net/en/sorting 10 | 11 | Разгледайте качените cpp-та успоредно с интерактивните примери в visualgo 12 | 13 | **Стабилна сортировка** - сортировка, при която два елемента с еднакви стойности остават в същата последователност в сортирания масив, в каквато са били и в първоначалния 14 | -------------------------------------------------------------------------------- /Seminars/Sem.05/Pract. 05/Task01/Task01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Point.h" 3 | 4 | int main() 5 | { 6 | Point p; // We cannot create a point like that because the default constructor here is the same as the one with default parameters 7 | Point p1(2, 5); 8 | p = p1; // Using the default operator= 9 | Point p2(p1); // Using the default copy constructor 10 | std::cout << p1.GetDistance(5, 3, 1); 11 | p2.SetX(1.5); // Won't work because we have forbidden setting x and y with double numbers 12 | } 13 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_polymorphism/Circle.cpp: -------------------------------------------------------------------------------- 1 | #include "Circle.h" 2 | 3 | const double PI = 3.1415; 4 | Circle::Circle(int x, int y, double radius) : Shape(1), radius(radius) 5 | { 6 | setPoint(0, x, y); 7 | } 8 | 9 | double Circle::getArea() const 10 | { 11 | return PI * radius * radius; 12 | } 13 | double Circle::getPer() const 14 | { 15 | return 2 * PI * radius; 16 | } 17 | bool Circle::isPointIn(int x, int y) const 18 | { 19 | Shape::point p(x, y); 20 | return p.getDist(getPointAtIndex(0)) <= radius; 21 | } 22 | -------------------------------------------------------------------------------- /Seminars/Sem.04/Pract.04/Task01/Teacher.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | const short MAX_NAME_LENGTH = 30; 4 | 5 | class Teacher { 6 | private: 7 | char name[MAX_NAME_LENGTH + 1]; 8 | size_t age; 9 | size_t experience; 10 | public: 11 | Teacher(const char* name, size_t age, size_t experience); 12 | 13 | const char* getName() const; 14 | size_t getAge() const; 15 | size_t getExperience() const; 16 | 17 | bool setName(const char* name); 18 | bool setAge(size_t age); 19 | bool setExperience(size_t experience); 20 | }; -------------------------------------------------------------------------------- /Seminars/Sem.02/Solutions/Examples/03-positioning.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "constants.h" 4 | 5 | void IfstreamPositioning() 6 | { 7 | std::ifstream in(FILE_NAME); 8 | char c; 9 | in >> c; 10 | std::cout << c << std::endl; 11 | in.seekg(-2, std::ios::end); 12 | std::cout << in.tellg() << std::endl; 13 | in >> c; 14 | std::cout << c << std::endl; 15 | } 16 | 17 | void OfstreamPositioning() 18 | { 19 | std::ofstream out(FILE_NAME, std::ios::_Nocreate); 20 | out.seekp(-5, std::ios::end); 21 | out << 'i'; 22 | } -------------------------------------------------------------------------------- /Seminars/Sem.02/Solutions/getCharCountFromFile.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size_t GetCharCountFromFile(std::ifstream& ifs, const char ch) 5 | { 6 | size_t currentPosition = ifs.tellg(); 7 | ifs.seekg(0, std::ios::beg); 8 | 9 | if (!ifs.is_open()) { 10 | return 0; 11 | } 12 | 13 | size_t count = 0; 14 | while (!ifs.eof()) 15 | { 16 | char current = ifs.get(); 17 | if (current == ch) { 18 | count++; 19 | } 20 | } 21 | 22 | ifs.clear(); 23 | ifs.seekg(currentPosition); 24 | return count; 25 | } -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/HexViewer/headers/helperFunctions.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void flushStream(); 4 | 5 | void printInputCharacter(); 6 | 7 | void printOperationResultMessage(bool result); 8 | 9 | bool isLetter(const char& character); 10 | 11 | void printLetter(const char& byte); 12 | 13 | void moveIndexToNextSeparator(const char* str, int& startIndex, const char& separator); 14 | 15 | void printHex(const char& byte); 16 | 17 | bool isValidHex(char* hex); 18 | 19 | int customPow(int number, int degree); 20 | 21 | int hexToDecimal(char* hex); -------------------------------------------------------------------------------- /Seminars/Sem.05/Pract. 05/Task01/Point.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class Point 3 | { 4 | private: 5 | int x; 6 | int y; 7 | 8 | public: 9 | Point() = default; 10 | Point(const Point& point) = default; 11 | Point& operator=(const Point& point) = default; 12 | ~Point() = default; 13 | explicit Point(int x = 0, int y = 0); 14 | int GetX() const; 15 | int GetY() const; 16 | void SetX(int x); 17 | void SetY(int y); 18 | void SetX(double x) = delete; 19 | void SetY(double y) = delete; 20 | double GetDistance(int a, int b, int c) const; 21 | }; 22 | 23 | -------------------------------------------------------------------------------- /Seminars/Sem.02/Solutions/copyFileContent.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "constants.h" 4 | 5 | bool CopyFileContent(const char* from, const char* to) 6 | { 7 | std::ifstream in(from); 8 | std::ofstream out(to); 9 | 10 | if (!in.is_open() || !out.is_open()) { 11 | std::cout << INVALID_FILE_ERR_MSG; 12 | return false; 13 | } 14 | 15 | while (!in.eof()) { 16 | char buffer[BUFFER_SIZE]; 17 | in.getline(buffer, BUFFER_SIZE); 18 | out << buffer; 19 | } 20 | 21 | in.close(); 22 | out.close(); 23 | retun true; 24 | } -------------------------------------------------------------------------------- /Seminars/Utils/Tasks/Task01/Server/Server.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../User/User.h" 3 | 4 | const short MAX_USERS_COUNT = 20; 5 | 6 | class Server { 7 | private: 8 | User users[MAX_USERS_COUNT]; 9 | size_t usersCount = 0; 10 | 11 | public: 12 | bool addUser(const char* userName, const char* password); 13 | bool removeUser(const char* userName); 14 | bool containsUser(const char* userName) const; 15 | void print() const; 16 | void printMostAccessedUser() const; 17 | 18 | void writeToFile() const; 19 | void readFromFile(); 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /Seminars/Sem.06/Solutions/SetOfNumbers/exampleMain.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "SetOFNumbers.h" 4 | 5 | int main() { 6 | SetOfNumbers s(10); 7 | 8 | s.AddNumber(4); 9 | s.AddNumber(8); 10 | 11 | 12 | s.print(); 13 | SetOfNumbers s2(10); 14 | 15 | s2.AddNumber(1); 16 | s2.AddNumber(4); 17 | s2.AddNumber(9); 18 | 19 | s2.print(); 20 | 21 | SetOfNumbers is = UnionOfSets(s, s2); 22 | SetOfNumbers us = IntersectionOfSets(s, s2); 23 | 24 | is.print(); 25 | us.print(); 26 | return 0; 27 | } 28 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/SortedCollection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"DynamicCollection.h" 3 | class SortedCollection : public DynamicCollection 4 | { 5 | // Взема най - лявото срещане на подадения елемент 6 | int lowerBound(int) const; 7 | 8 | // Взема най - дясното срещане на подадения елемент 9 | int upperBound(int) const; 10 | public: 11 | void add(int) override; 12 | void remove(int) override; 13 | unsigned count(int) const override; 14 | bool contains(int) const override; 15 | 16 | ~SortedCollection() = default; 17 | }; 18 | 19 | -------------------------------------------------------------------------------- /Seminars/Sem.06/Pract. 06/Task01/MonsterCard.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | const short MAX_SIZE = 26; 4 | 5 | class MonsterCard { 6 | private: 7 | char name[MAX_SIZE]; 8 | size_t attPoints; 9 | size_t defPoints; 10 | public: 11 | MonsterCard(); 12 | MonsterCard(const char*, size_t, size_t); 13 | 14 | MonsterCard(const MonsterCard& monsterCard) = default; 15 | MonsterCard& operator=(const MonsterCard& monsterCard) = default; 16 | ~MonsterCard() = default; 17 | 18 | size_t getAttPoints() const; 19 | size_t getDefPoints() const; 20 | const char* const getName() const; 21 | }; -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/Singleton/Singleton.cpp: -------------------------------------------------------------------------------- 1 | #include "Singleton.h" 2 | #include 3 | 4 | Singleton* Singleton::instance = nullptr; 5 | 6 | Singleton::Singleton() { 7 | std::cout << "Constructor" << std::endl; 8 | } 9 | 10 | Singleton::~Singleton(){ 11 | std::cout << "Destructor" << std::endl; 12 | } 13 | 14 | Singleton* Singleton::getInstance() { 15 | if (instance == nullptr) { 16 | instance = new Singleton(); 17 | } 18 | 19 | return instance; 20 | } 21 | 22 | void Singleton::freeInstance() { 23 | delete instance; 24 | instance = nullptr; 25 | } -------------------------------------------------------------------------------- /Seminars/Sem.12/Solutions/Shapes/cpp/Circle.cpp: -------------------------------------------------------------------------------- 1 | #include "Circle.h" 2 | 3 | const double PI = 3.1415; 4 | 5 | Circle::Circle(int x, int y, double radius) : Shape(1), radius(radius) { 6 | setPoint(0, x, y); 7 | } 8 | 9 | double Circle::GetArea() const { 10 | return PI * radius * radius; 11 | } 12 | 13 | double Circle::GetPer() const { 14 | return 2 * PI * radius; 15 | } 16 | 17 | bool Circle::IsPointIn(int x, int y) const { 18 | return Point(x, y).getDist(getPointAtIndex(0)) <= radius; 19 | } 20 | 21 | Shape* Circle::clone() const override { 22 | return new Circle(*this); 23 | } -------------------------------------------------------------------------------- /Seminars/Utils/Tasks/Task02/Bus.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Bus { 4 | unsigned id; 5 | unsigned maxSeats; 6 | unsigned ticketsPriceAdults; 7 | unsigned ticketsPriceStudents; 8 | bool isFree; 9 | 10 | public: 11 | Bus(); 12 | Bus(unsigned id, unsigned maxSeats, 13 | unsigned ticketsPriceAdults, 14 | unsigned ticketsPriceStudents); 15 | 16 | unsigned getId() const; 17 | unsigned getMaxSeats() const; 18 | unsigned getTicketsPriceAdults() const; 19 | unsigned getTicketsPriceStudents() const; 20 | 21 | bool isBusFree() const; 22 | void useBus(); 23 | void stopUsingBus(); 24 | }; -------------------------------------------------------------------------------- /Seminars/Sem.04/Pract.04/Task02/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Task02/Exam.h" 4 | 5 | int main() 6 | { 7 | Task tasks[3] = { 8 | Task("Task1", "Description", 15), 9 | Task("Task2", "Description1", 25), 10 | Task("Task3", "Description2", 35) 11 | }; 12 | 13 | Exam ex(5, tasks, 3); 14 | 15 | ex.WriteToFile("file.dat"); 16 | 17 | Exam ex1; 18 | ex1.ReadFromFile("file.dat"); 19 | 20 | std::cout << "======ORIGINAL======\n"; 21 | ex.Print(); 22 | std::cout << "======READ======\n"; 23 | ex1.Print(); 24 | } 25 | -------------------------------------------------------------------------------- /Seminars/Sem.05/Solutions/EventCollection/EventCollection.cpp: -------------------------------------------------------------------------------- 1 | #include "EventCollection.h" 2 | 3 | bool EventCollection::addEvent(const Event& event) { 4 | if (count == 20) return false; 5 | 6 | data[count++] = event; // copy!!! 7 | return true; 8 | } 9 | 10 | void EventCollection::remove(unsigned ind) { 11 | if (ind >= count) return; 12 | 13 | data[ind] = data[count - 1]; //std::swap(data[ind], data[count - 1]); 14 | count--; 15 | } 16 | 17 | const Event& EventCollection::getByIndex(unsigned ind) const { 18 | if (ind >= count) throw "Error"; 19 | 20 | return data[ind]; 21 | } 22 | -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/CarDealership/CarDealership/CarDealership.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Car.h" 3 | 4 | class CarDealership { 5 | private: 6 | Car** cars; 7 | size_t count; 8 | size_t capacity; 9 | 10 | void resize(); 11 | 12 | public: 13 | CarDealership(); 14 | CarDealership(const CarDealership&); 15 | CarDealership& operator=(const CarDealership&); 16 | ~CarDealership(); 17 | 18 | void addCar(const Car&); 19 | void deleteAtIndex(size_t index); 20 | const Car& getCar(size_t index) const; 21 | 22 | private: 23 | void free(); 24 | void copyFrom(const CarDealership&); 25 | }; -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_mutualCatching/Circle.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Shape.h" 3 | #include "Circle.h" 4 | #include "Rectangle.h" 5 | #include "Triangle.h" 6 | 7 | 8 | class Circle : public Shape 9 | { 10 | double radius; 11 | 12 | public: 13 | Circle(int x, int y, double radius); 14 | 15 | bool intersectsWith(const Shape* other) const override; 16 | 17 | bool intersectsWithTriangle(const Triangle* other) const override; 18 | bool intersectsWithRect(const Rectangle* other) const override; 19 | bool intersectsWithCircle(const Circle* other) const override; 20 | 21 | }; -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/task2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | size_t GetFileSize(std::ifstream& file) { 6 | size_t currentPosition = file.tellg(); 7 | file.seekg(0, std::ios::end); 8 | size_t result = file.tellg(); 9 | file.seekg(currentPosition); 10 | return result; 11 | } 12 | 13 | int main() { 14 | std::ifstream file("test.txt"); 15 | 16 | if(!file.is_open()) { 17 | std::cout << "Error while opening the file!" << std::endl; 18 | return 1; 19 | } 20 | 21 | std::cout << GetFileSize(file) << " bytes" << std::endl; 22 | 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /Seminars/Sem.05/Pract. 05/Task01/Point.cpp: -------------------------------------------------------------------------------- 1 | #include "Point.h" 2 | #include 3 | 4 | Point::Point(int x, int y) { 5 | SetX(x); 6 | SetY(y); 7 | } 8 | 9 | int Point::GetX() const { 10 | return x; 11 | } 12 | 13 | int Point::GetY() const { 14 | return y; 15 | } 16 | 17 | void Point::SetX(int x) { 18 | this->x = x; 19 | } 20 | 21 | void Point::SetY(int y) { 22 | this->y = y; 23 | } 24 | 25 | double Point::GetDistance(int a, int b, int c) const { 26 | int numerator = a * this->x + b * this->y + c; 27 | double denominator = sqrt(a * a + b * b); 28 | return abs(numerator / denominator); 29 | } 30 | -------------------------------------------------------------------------------- /Seminars/Sem.06/Solutions/Person/Person.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class Person { 5 | private: 6 | char* name = nullptr; 7 | int age = 0; 8 | public: 9 | Person() = default; 10 | Person(const char* name, int age); 11 | Person(const Person& other); 12 | Person& operator=(const Person& other); 13 | ~Person(); 14 | 15 | const char* getName() const; 16 | int getAge() const; 17 | 18 | void setName(const char* name); 19 | void setAge(int age); 20 | 21 | void print() const; 22 | private: 23 | void CopyFrom(const Person& other); 24 | void Free(); 25 | }; 26 | -------------------------------------------------------------------------------- /Seminars/Sem.14/Solutions/MyString/StringView.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "MyString.h" 4 | class StringView 5 | { 6 | const char* _begin; 7 | const char* _end; //1 element after the final char; 8 | 9 | public: 10 | StringView(const char* begin, const char* end); 11 | StringView(const char* str); //terminatedString 12 | StringView(const MyString& string); 13 | 14 | size_t length() const; 15 | char operator[](size_t ind) const; 16 | 17 | StringView substr(size_t from, size_t length) const; 18 | friend std::ostream& operator<<(std::ostream&, const StringView& strView); 19 | 20 | }; -------------------------------------------------------------------------------- /Seminars/Sem.10/Solutions/Person-Student-Teacher/Teacher/Teacher.h: -------------------------------------------------------------------------------- 1 | #include "../Person/Person.h" 2 | 3 | class Teacher : public Person 4 | { 5 | char** subjects; 6 | size_t subjectsCount; 7 | 8 | void free(); 9 | void copyFrom(const Teacher& other);// само нещата, които са от Teacher 10 | void moveFrom(Teacher&& other); 11 | 12 | public: 13 | Teacher(const char* name, int age, const char* const * subjects, size_t subjectsCount); 14 | 15 | Teacher(const Teacher& other); 16 | Teacher& operator=(const Teacher& other); 17 | 18 | Teacher(Teacher&& other); 19 | Teacher& operator=(Teacher&& other); 20 | ~Teacher(); 21 | }; -------------------------------------------------------------------------------- /Seminars/Sem.14/Solutions/ExpressionCalculator/MyString/StringView.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "MyString.h" 4 | class StringView 5 | { 6 | const char* _begin; 7 | const char* _end; //1 element after the final char; 8 | 9 | public: 10 | StringView(const char* begin, const char* end); 11 | StringView(const char* str); //terminatedString 12 | StringView(const MyString& string); 13 | 14 | size_t length() const; 15 | char operator[](size_t ind) const; 16 | 17 | StringView substr(size_t from, size_t length) const; 18 | friend std::ostream& operator<<(std::ostream&, const StringView& strView); 19 | 20 | }; -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/Union.cpp: -------------------------------------------------------------------------------- 1 | #include "Union.h" 2 | 3 | Union::Union(Collection& l, Collection& r) : 4 | CollectionOperation(l, r) {} 5 | 6 | void Union::add(int elem) 7 | { 8 | this->left.add(elem); 9 | } 10 | 11 | void Union::remove(int elem) 12 | { 13 | if (left.contains(elem)) 14 | { 15 | left.remove(elem); 16 | } 17 | else 18 | { 19 | right.remove(elem); 20 | } 21 | } 22 | 23 | unsigned Union::count(int elem) const 24 | { 25 | return left.count(elem) + right.count(elem); 26 | } 27 | 28 | bool Union::contains(int elem) const 29 | { 30 | return left.contains(elem) || right.contains(elem); 31 | } 32 | -------------------------------------------------------------------------------- /Seminars/Sem.01/Bonus/InsertionSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void Print(const int* arr, size_t length) 4 | { 5 | for (size_t i = 0; i < length; i++) { 6 | std::cout << arr[i] << " "; 7 | } 8 | } 9 | 10 | void InsertionSort(int* arr, size_t length) 11 | { 12 | for (size_t i = 1; i < length; i++) { 13 | int currentNumber = arr[i]; 14 | 15 | int j = i - 1; 16 | while (j >= 0 && arr[j] > currentNumber) { 17 | arr[j + 1] = arr[j]; 18 | j--; 19 | } 20 | 21 | arr[j + 1] = currentNumber; 22 | } 23 | } 24 | 25 | int main() 26 | { 27 | int arr[] = { 9, 5, 6, 3, 4, 7, 2, 1, 8 }; 28 | 29 | InsertionSort(arr, 9); 30 | Print(arr, 9); 31 | } -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/StringView/StringView.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "MyString.h" 4 | class StringView 5 | { 6 | const char* _begin; 7 | const char* _end; //1 element after the final char; 8 | 9 | public: 10 | StringView(const char* begin, const char* end); 11 | StringView(const char* str); //terminatedString 12 | StringView(const MyString& string); 13 | 14 | size_t length() const; 15 | char operator[](size_t ind) const; 16 | 17 | StringView substr(size_t from, size_t length) const; 18 | friend std::ostream& operator<<(std::ostream&, const StringView& strView); 19 | 20 | }; 21 | 22 | //TODO: implement comparison operators -------------------------------------------------------------------------------- /Seminars/Sem.10/Solutions/Person-Student-Teacher/Student/Student.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../Person/Person.h" 3 | 4 | class Student : public Person 5 | { 6 | size_t fn = 0; 7 | public: 8 | Student() = default; 9 | Student(const char* name, int age, size_t fn); 10 | 11 | size_t getFn() const; 12 | void setFn(size_t fn); 13 | 14 | 15 | // No need for big 4, since there is NO dyn. memory in Student 16 | // The compiler will generate valid: 17 | 18 | //Student(const Student& other); 19 | //Student& operator=(const Student& other); //no need 20 | // ~Student() 21 | 22 | //See on the .cpp file how the compiler creates them 23 | 24 | }; 25 | -------------------------------------------------------------------------------- /Seminars/Sem.06/Pract. 06/Task02/Item.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class Item { 3 | private: 4 | char* name = nullptr; 5 | bool isAvailable = false; 6 | double price = 0; 7 | 8 | public: 9 | Item(); 10 | Item(const char* name, bool isAvailable, double price); 11 | Item(const Item& other); 12 | Item& operator=(const Item& other); 13 | ~Item(); 14 | 15 | void SetName(const char* name); 16 | void SetAvailability(bool isAvailable); 17 | void SetPrice(double price); 18 | 19 | const char* GetName() const; 20 | bool GetAvailability() const; 21 | double GetPrice() const; 22 | 23 | private: 24 | void copyFrom(const Item& other); 25 | void free(); 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /Seminars/Sem.04/Pract.04/Task04/Secret.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | const unsigned short MAX_DESCRIPTION_LENGTH = 1024; 4 | const unsigned short MAX_PASSWORD_LENGTH = 64; 5 | 6 | class Secret 7 | { 8 | char taskDescription[MAX_DESCRIPTION_LENGTH + 1]; 9 | char password[MAX_PASSWORD_LENGTH + 1]; 10 | mutable size_t _failedLogins = 0; 11 | public: 12 | Secret() = delete; 13 | Secret(const char* taskDescription, const char* password); 14 | 15 | const char* getTask(const char* pwd) const; 16 | size_t getLoginFails() const; 17 | 18 | void setPassword(const char* newPassword, const char* oldPassword); 19 | void setTask(const char* newTask, const char* passwd); 20 | }; 21 | -------------------------------------------------------------------------------- /Seminars/Sem.06/Pract. 06/Task01/MagicCard.cpp: -------------------------------------------------------------------------------- 1 | #include "MagicCard.h" 2 | #include 3 | #pragma warning(disable : 4996) 4 | 5 | MagicCard::MagicCard() { 6 | name[0] = '\0'; 7 | effect[0] = '\0'; 8 | type = MagicCardType::unknown; 9 | } 10 | 11 | MagicCard::MagicCard(const char* name, const char* effect, const MagicCardType type){ 12 | strcpy(this->name, name); 13 | strcpy(this->effect, effect); 14 | this->type = type; 15 | } 16 | 17 | const char* const MagicCard::getName() const { 18 | return name; 19 | } 20 | const char* const MagicCard::getEffect() const { 21 | return effect; 22 | } 23 | MagicCardType MagicCard::getMagicCardType() const{ 24 | return type; 25 | } -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/task3.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void replaceInFile(char ch, char ch2, fstream& file) { 5 | char currentSymbol; 6 | while (!file.eof()) 7 | { 8 | char currentSymbol = file.get(); 9 | if (currentSybmol != ch) { 10 | continue; 11 | } 12 | file.seekp(-1, std::ios::cur); 13 | file.put(ch2); 14 | file.flush(); 15 | } 16 | } 17 | 18 | int main() 19 | { 20 | std::fstream file("treasureTrail.txt", std::ios::in | std::ios::out); 21 | 22 | if(!file.is_open()) { 23 | std::cout << "Error while opening the file!" << std::endl; 24 | return 1; 25 | } 26 | 27 | replaceInFile('a', 'X', file); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /Seminars/Sem.06/Pract. 06/Task01/MonsterCard.cpp: -------------------------------------------------------------------------------- 1 | #include "MonsterCard.h" 2 | #include 3 | #pragma warning(disable : 4996) 4 | 5 | MonsterCard::MonsterCard() { 6 | name[0] = '\0'; 7 | attPoints = 0; 8 | defPoints = 0; 9 | } 10 | 11 | MonsterCard::MonsterCard(const char* name, size_t attPoints, size_t defPoints) { 12 | strcpy(this->name, name); 13 | this->attPoints = attPoints; 14 | this->defPoints = defPoints; 15 | } 16 | 17 | const char* const MonsterCard::getName() const { 18 | return name; 19 | } 20 | 21 | size_t MonsterCard::getAttPoints() const{ 22 | return attPoints; 23 | } 24 | 25 | size_t MonsterCard::getDefPoints() const{ 26 | return defPoints; 27 | } 28 | -------------------------------------------------------------------------------- /Seminars/Sem.01/Pract.01/Task05.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct ComplexNumber 4 | { 5 | double real; 6 | double imaginary; 7 | }; 8 | 9 | ComplexNumber AddComplexNumbers(const ComplexNumber& lhs, const ComplexNumber& rhs) 10 | { 11 | return { 12 | lhs.real + rhs.real, 13 | lhs.imaginary + rhs.imaginary 14 | }; 15 | } 16 | 17 | void PrintComplexNumber(const ComplexNumber& complex) 18 | { 19 | std::cout << complex.real << " " << complex.imaginary << "\n"; 20 | } 21 | 22 | int main() 23 | { 24 | ComplexNumber cn1 = { 3, 4 }; 25 | ComplexNumber cn2 = { -10, 12 }; 26 | ComplexNumber sum = AddComplexNumbers(cn1, cn2); 27 | 28 | PrintComplexNumber(sum); 29 | } -------------------------------------------------------------------------------- /Seminars/Sem.04/Pract.04/Task02/Task.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | const int MAX_TASK_NAME_SIZE = 31; 4 | const int MAX_TASK_DESCRIPTION_SIZE = 127; 5 | 6 | class Task 7 | { 8 | private: 9 | char m_name[MAX_TASK_NAME_SIZE + 1]; 10 | char m_description[MAX_TASK_DESCRIPTION_SIZE + 1]; 11 | int m_points; 12 | public: 13 | Task(); 14 | Task(const char *name, const char *description, int points); 15 | 16 | void SetName(const char *name); 17 | 18 | void SetDescription(const char *description); 19 | 20 | void SetPoints(int points); 21 | 22 | const char *GetName() const; 23 | 24 | const char *GetDescription() const; 25 | 26 | int GetPoints() const; 27 | }; 28 | -------------------------------------------------------------------------------- /Seminars/Sem.05/Pract. 05/Task02/ComplexNumbers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class ComplexNumber 4 | { 5 | private: 6 | double real; 7 | double imag; 8 | public: 9 | ComplexNumber(); 10 | ComplexNumber(double real, double imag); 11 | 12 | double GetReal() const; 13 | double GetImag() const; 14 | 15 | bool IsEqual(const ComplexNumber& other) const; 16 | const ComplexNumber& Add(const ComplexNumber& other) const; 17 | const ComplexNumber& Subtract(const ComplexNumber& other) const; 18 | const ComplexNumber& Multiply(const ComplexNumber& num) const; 19 | void Conjugate(); 20 | const ComplexNumber& GetConjugated(const ComplexNumber& num); 21 | void Print() const; 22 | }; 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Seminars/Sem.05/Pract. 05/Task02/Task02.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ComplexNumbers.h" 3 | 4 | int main() 5 | { 6 | ComplexNumber number; 7 | ComplexNumber number2(3.5, 1.0); 8 | ComplexNumber number3(2, 2.5); 9 | number = number2.Multiply(number3); 10 | number.Print(); 11 | number3.Conjugate(); 12 | number3.Print(); 13 | ComplexNumber conjugated = number2.GetConjugated(number2); 14 | conjugated.Print(); 15 | ComplexNumber sum = number2.Add(number3); 16 | sum.Print(); 17 | if (number2.IsEqual(number3)) 18 | std::cout << "Num2 and num3 are equal!"; 19 | else 20 | std::cout << "Num2 and num3 aren't equal!"; 21 | } 22 | 23 | 24 | -------------------------------------------------------------------------------- /Seminars/Sem.01/Pract.01/Task01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int LowerNumberByCopy(const int num1, const int num2) 4 | { 5 | return num1 < num2 ? num1 : num2; 6 | } 7 | 8 | int LowerNumberByReference(const int& num1, const int& num2) 9 | { 10 | return num1 < num2 ? num1 : num2; 11 | } 12 | 13 | int LowerNumberByPointer(const int* num1, const int* num2) 14 | { 15 | return *num1 < *num2 ? *num1 : *num2; 16 | } 17 | 18 | int main() 19 | { 20 | int num1, num2; 21 | std::cin >> num1 >> num2; 22 | 23 | std::cout << LowerNumberByCopy(num1, num2) << std::endl; 24 | std::cout << LowerNumberByReference(num1, num2) << std::endl; 25 | std::cout << LowerNumberByPointer(&num1, &num2) << std::endl; 26 | } -------------------------------------------------------------------------------- /Seminars/Sem.08/Pract.08/Task01/Grade.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MyString.h" 4 | #include "Teacher.h" 5 | 6 | class Grade { 7 | double _value = 0; 8 | MyString _task; 9 | const Teacher* _teacher = nullptr; 10 | 11 | void setTask(const char* task); 12 | void setTeacher(const Teacher* teacher); 13 | 14 | public: 15 | Grade() = default; 16 | Grade(double value, const char* task, const Teacher* teacher); 17 | 18 | void setValue(double value); 19 | 20 | double getValue() const; 21 | const MyString& getTask() const; 22 | const Teacher* getTeacher() const; 23 | 24 | bool isValidGrade() const; 25 | 26 | friend std::ostream& operator<<(std::ostream& os, const Grade& grade); 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /Seminars/Sem.04/Pract.04/Task02/Exam.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Task.h" 4 | 5 | #include 6 | 7 | const int MAX_TASKS_IN_EXAM = 16; 8 | 9 | class Exam 10 | { 11 | private: 12 | Task m_tasks[MAX_TASKS_IN_EXAM]; 13 | int m_currentTaskIndex = 0; 14 | 15 | int m_minScore; 16 | public: 17 | Exam(); 18 | Exam(int minPoints); 19 | Exam(int minPoints, const Task* tasks, size_t tasksLength); 20 | 21 | void AddTask(const Task &task); 22 | 23 | void WriteToFile(const char* fileName) const; 24 | 25 | void ReadFromFile(const char* fileName); 26 | 27 | void ChangeMin(int min); 28 | 29 | int GetMaxScore() const; 30 | 31 | void Print() const; 32 | }; 33 | -------------------------------------------------------------------------------- /Seminars/Utils/TheoryExamples/Sem4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class Test { 4 | private: 5 | int a; 6 | Test(bool a) { 7 | this->a = a; 8 | } 9 | 10 | public: 11 | Test(int a) { 12 | setA(a); 13 | } 14 | 15 | int getA() const { 16 | return a; 17 | } 18 | 19 | void setA(int a) { 20 | this->a = a; 21 | } 22 | 23 | Test createConditionalDuplicate() const { 24 | return Test(a > 0); 25 | } 26 | }; 27 | 28 | void func() { 29 | Test t(-5); 30 | Test t2 = t.createConditionalDuplicate(); 31 | std::cout << t.getA() << std::endl; 32 | std::cout << t2.getA(); 33 | } 34 | 35 | void func2(const Test& t) { 36 | t.getA(); 37 | t.createConditionalDuplicate(); 38 | //t.setA(); // error 39 | } -------------------------------------------------------------------------------- /Seminars/Sem.10/Solutions/Person-Student-Teacher/Person/Person.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | class Person 4 | { 5 | char* name = nullptr; 6 | int age = 0; 7 | 8 | void copyFrom(const Person& other); 9 | void free(); 10 | void moveFrom(Person&& other); 11 | 12 | public: 13 | Person() = default; 14 | Person(const char* name, int age); 15 | 16 | Person(const Person& other); 17 | Person& operator=(const Person& other); 18 | 19 | Person(Person&& other); 20 | Person& operator=(Person&& other); 21 | 22 | const char* getName() const; 23 | int getAge() const; 24 | 25 | ~Person(); 26 | void print() const; 27 | 28 | protected: 29 | void setName(const char* name); 30 | void setAge(int age); 31 | }; 32 | -------------------------------------------------------------------------------- /Seminars/Sem.14/Pract. 14/Bar/Bar/Bar.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../Queue/Queue.hpp" 3 | #include "../Pair/Pair.hpp" 4 | #include "../AlcoholDrink/AlcoholDrink.h" 5 | 6 | class Bar 7 | { 8 | MyQueue> alcoholDrinks; 9 | MyQueue> drinks; 10 | 11 | public: 12 | struct Statistics 13 | { 14 | size_t soldDrinks; 15 | size_t soldAlcoholDrinks; 16 | size_t mlSold; 17 | } stats; 18 | 19 | 20 | Bar() = default; 21 | 22 | void addAlcoholDrink(const AlcoholDrink& dr, size_t count = 1); 23 | void addDrink(const Drink& dr, size_t count = 1); 24 | 25 | 26 | Drink getDrink(); 27 | AlcoholDrink getAlcDrink(); 28 | 29 | const Statistics& getStats() const; 30 | 31 | }; 32 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_mutualCatching/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Rectangle.h" 5 | #include "Circle.h" 6 | #include "Triangle.h" 7 | 8 | 9 | 10 | bool intersect(const Shape* sh1, const Shape* sh2) 11 | { 12 | return sh1->intersectsWith(sh2); 13 | } 14 | int main() 15 | { 16 | Shape** arr = new Shape*[4]; 17 | 18 | arr[0] = new Rectangle(3, 4, 6, 8); 19 | arr[1] = new Circle(3, 3, 4); 20 | arr[2] = new Circle(1, 4, 5); 21 | arr[3] = new Triangle(1, 1, 2, 2, 3, 3); 22 | 23 | intersect(arr[0], arr[1]); 24 | intersect(arr[1], arr[2]); 25 | intersect(arr[2], arr[3]); 26 | 27 | 28 | for (int i = 0; i < 4; i++) 29 | delete arr[i]; 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Seminars/Sem.04/Pract.04/Task04/OOP_Pract.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Secret.h" 3 | 4 | int main() 5 | { 6 | auto taskDesc = "A task description."; 7 | auto taskDesc2 = "Second task"; 8 | auto password = "123ili"; 9 | 10 | Secret task(taskDesc, password); 11 | 12 | std::cout << task.getLoginFails() << std::endl; 13 | 14 | std::cout << task.getTask("123ili") << std::endl; 15 | 16 | task.setTask(taskDesc2, "123ili"); 17 | std::cout << task.getTask("123ili") << std::endl; 18 | 19 | task.setPassword("123123", "123"); 20 | std::cout << task.getLoginFails() << std::endl; 21 | 22 | task.setPassword("123123", "123ili"); 23 | std::cout << task.getLoginFails() << std::endl; 24 | 25 | std::cout << task.getTask("123123"); 26 | } -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/SelfCounting/SelfCounting.cpp: -------------------------------------------------------------------------------- 1 | #include "SelfCounting.h" 2 | 3 | size_t SelfCounting::liveObjectCount = 0; 4 | size_t SelfCounting::createdCount = 0; 5 | 6 | SelfCounting::SelfCounting() : SelfCounting(0) {} 7 | 8 | SelfCounting::SelfCounting(int val) : constValue(val) { 9 | ++liveObjectCount; 10 | ++createdCount; 11 | } 12 | 13 | SelfCounting::SelfCounting(const SelfCounting& other) : constValue(other.constValue) { 14 | ++liveObjectCount; 15 | ++createdCount; 16 | } 17 | 18 | SelfCounting::~SelfCounting() { 19 | --liveObjectCount; 20 | } 21 | 22 | size_t SelfCounting::getLiveObjectCount() { 23 | return liveObjectCount; 24 | } 25 | 26 | size_t SelfCounting::getCreatedCount() { 27 | return createdCount; 28 | } -------------------------------------------------------------------------------- /Seminars/Sem.14/Pract. 14/Bar/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Bar/Bar.h" 3 | 4 | int main() 5 | { 6 | Bar b; 7 | 8 | b.addDrink(Drink("Coke", 330), 2); //2x Coca cola 330 ml 9 | 10 | b.addDrink(Drink("Fanta", 500)); //1x Fanta 500 ml 11 | 12 | b.addAlcoholDrink(AlcoholDrink("Zagorka", 500, 5)); //1x Zagorka, 5% alc, 500 ml 13 | 14 | std::cout << b.getAlcDrink().getName() << std::endl; // Zagorka 15 | 16 | std::cout << b.getDrink().getName() << std::endl; // Coke 17 | std::cout << b.getDrink().getName() << std::endl; // Coke 18 | std::cout << b.getDrink().getName() << std::endl; // Fanta 19 | 20 | std::cout<< b.getStats().soldAlcoholDrinks << std::endl; // 1 21 | std::cout << b.getStats().soldDrinks << std::endl; // 3 22 | 23 | } -------------------------------------------------------------------------------- /Seminars/Sem.06/Pract. 06/Task01/MagicCard.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | const short NAME_MAX_SIZE = 26; 4 | const short EFFECT_MAX_SIZE = 101; 5 | 6 | enum class MagicCardType { 7 | trap, 8 | buff, 9 | spell, 10 | unknown 11 | }; 12 | 13 | class MagicCard { 14 | private: 15 | char name[NAME_MAX_SIZE]; 16 | char effect[EFFECT_MAX_SIZE]; 17 | MagicCardType type; 18 | public: 19 | MagicCard(); 20 | MagicCard(const char* name, const char* effect, const MagicCardType type); 21 | 22 | MagicCard(const MagicCard& magicCard) = default; 23 | MagicCard& operator=(const MagicCard& magicCard) = default; 24 | ~MagicCard() = default; 25 | 26 | const char* const getName() const; 27 | const char* const getEffect() const; 28 | MagicCardType getMagicCardType() const; 29 | }; -------------------------------------------------------------------------------- /Seminars/Sem.13/Solutions/TemplateFunctionSpecification.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | template 4 | void print(T* arr, size_t size) { 5 | for (size_t i = 0; i < size; i++) { 6 | std::cout << arr[i] << " "; 7 | } 8 | std::cout << std::endl; 9 | } 10 | 11 | template<> 12 | void print(char* arr, size_t size) { 13 | for (size_t i = 0; i < size; i++) { 14 | std::cout << arr[i] << " ---- "; 15 | } 16 | std::cout << std::endl; 17 | } 18 | 19 | void printV2() { 20 | char arr2[] = { 'a', 'b' }; 21 | print(arr2, 2); 22 | } 23 | 24 | // This is not a specialization 25 | // void print(char* arr, size_t size) { 26 | // for (size_t i = 0; i < size; i++) { 27 | // std::cout << arr[i] << " ---- "; 28 | // } 29 | // std::cout << std::endl; 30 | // } -------------------------------------------------------------------------------- /Seminars/Sem.08/Pract.08/Task01/MyString.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class MyString 6 | { 7 | char* _data; 8 | size_t size; 9 | 10 | void copyFrom(const MyString& data); 11 | void free(); 12 | public: 13 | 14 | MyString(); 15 | MyString(const char* data); 16 | 17 | 18 | MyString(const MyString& other); 19 | MyString& operator=(const MyString& other); 20 | 21 | friend std::ostream& operator<<(std::ostream& os, const MyString& str); 22 | 23 | size_t length() const; 24 | MyString& operator+=(const MyString& other); 25 | 26 | const char* c_str() const; 27 | 28 | char& operator[](size_t index); 29 | char operator[](size_t index) const; 30 | ~MyString(); 31 | }; 32 | 33 | MyString operator+(const MyString& lhs, const MyString& rhs); -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/FlightsScanner - Exception handling task/FlightsScanner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class FlightsScanner 5 | { 6 | char inputFileName[1024] = ""; 7 | char outputFileName[1024] = ""; 8 | int sec = -1; 9 | unsigned lineIndex = 0; 10 | 11 | 12 | struct FlightRecord 13 | { 14 | char origin[64]; 15 | char dest[64]; 16 | unsigned amount; 17 | }; 18 | 19 | void handleAirport(char* airport) const; 20 | void parseLine(const char* line, FlightRecord& record) const; 21 | bool readAndExportData(std::ifstream& input); 22 | void saveRecord(std::ofstream& ofs, const FlightRecord& record) const; 23 | 24 | public: 25 | FlightsScanner(const char* input, const char* output, int scanInterval); 26 | void run(); 27 | }; 28 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/DynamicCollection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Collection.h" 3 | #include // size_t 4 | 5 | class DynamicCollection : public Collection 6 | { 7 | protected: 8 | int* data = nullptr; 9 | size_t size = 0; 10 | size_t capacity = 0; 11 | 12 | void free(); 13 | void copyFrom(const DynamicCollection& other); 14 | void moveFrom(DynamicCollection&&); 15 | 16 | void resize(size_t); 17 | public: 18 | DynamicCollection(); 19 | 20 | DynamicCollection(const DynamicCollection& other); 21 | DynamicCollection(DynamicCollection&& other); 22 | 23 | DynamicCollection& operator=(const DynamicCollection& other); 24 | DynamicCollection& operator=(DynamicCollection&& other); 25 | 26 | ~DynamicCollection(); 27 | }; 28 | 29 | -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/ReadArrayOfInts.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size_t GetFileSize(std::ifstream& file) { 5 | size_t currentPos = file.tellg(); 6 | file.seekg(0, std::ios::end); 7 | size_t fileSize = file.tellg(); 8 | file.seekg(currentPos); 9 | return fileSize; 10 | } 11 | 12 | int main() 13 | { 14 | std::ifstream ifs("myfile.dat", std::ios::in | std::ios::binary); 15 | 16 | if(!ifs.is_open()) { 17 | return 1; 18 | } 19 | 20 | size_t fileSize = GetFileSize(ifs); 21 | size_t arrSize = fileSize / sizeof(int); 22 | int* arr = new int[arrSize]; 23 | 24 | ifs.read((char*)arr, fileSize); 25 | 26 | for (size_t i = 0; i < arrSize; ++i) { 27 | std::cout << arr[i] << " "; 28 | } 29 | 30 | delete[] arr; 31 | ifs.close(); 32 | } -------------------------------------------------------------------------------- /Seminars/Sem.04/Solutions/Time/Time.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Time { 4 | private: 5 | unsigned hours, minutes, seconds; 6 | public: 7 | Time(); 8 | Time(unsigned hours, unsigned minutes, unsigned seconds); 9 | 10 | unsigned getHours() const; 11 | unsigned getMinutes() const; 12 | unsigned getSeconds() const; 13 | 14 | void setHours(unsigned newValue); 15 | void setMinutes(unsigned newValue); 16 | void setSeconds(unsigned newValue); 17 | 18 | void addSecond(); 19 | Time getDifference(const Time& other) const; 20 | int compare(const Time& other) const; 21 | 22 | Time getTimeToMidnight() const; 23 | bool isDinnerTime() const; 24 | bool isPartyTime() const; 25 | 26 | unsigned getTotalSeconds() const; 27 | void print() const; 28 | private: 29 | Time(unsigned seconds); 30 | }; 31 | -------------------------------------------------------------------------------- /Seminars/Sem.05/Solutions/Time/Time.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Time { 4 | private: 5 | unsigned hours, minutes, seconds; 6 | public: 7 | Time(); 8 | Time(unsigned hours, unsigned minutes, unsigned seconds); 9 | 10 | unsigned getHours() const; 11 | unsigned getMinutes() const; 12 | unsigned getSeconds() const; 13 | 14 | void setHours(unsigned newValue); 15 | void setMinutes(unsigned newValue); 16 | void setSeconds(unsigned newValue); 17 | 18 | void addSecond(); 19 | Time getDifference(const Time& other) const; 20 | int compare(const Time& other) const; 21 | 22 | Time getTimeToMidnight() const; 23 | bool isDinnerTime() const; 24 | bool isPartyTime() const; 25 | 26 | unsigned getTotalSeconds() const; 27 | void print() const; 28 | private: 29 | Time(unsigned seconds); 30 | }; 31 | -------------------------------------------------------------------------------- /Seminars/Sem.04/Solutions/Interval/Interval.h: -------------------------------------------------------------------------------- 1 | class Interval { 2 | private: 3 | int a; 4 | int b; 5 | public: 6 | Interval(); 7 | Interval(int, int); 8 | 9 | //Accessors 10 | int getA() const; 11 | int getB() const; 12 | 13 | //Mutators 14 | bool setA(int); 15 | bool setB(int); 16 | 17 | size_t GetLength() const; 18 | bool IsMemberOfInterval(int) const; 19 | 20 | size_t CalcPrimeNumbersInTheInterval() const; 21 | size_t CalcPalindromicNumbersInTheInterval() const; 22 | size_t CalcDiffrentDigitNumbersInTheInverval() const; 23 | 24 | bool RreStartAndEndPowersOfTwo() const; 25 | 26 | Interval Intersect(const Interval&) const; 27 | 28 | bool IsSuperInterval(const Interval&) const; 29 | private: 30 | size_t CountNumbersInIntervalCondition(bool(*pred)(int)) const; 31 | }; 32 | -------------------------------------------------------------------------------- /Seminars/Utils/Exam/Task02/NaturalNumbersFunction.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | using UnaryUnsignedFunction = unsigned(*)(unsigned); 4 | 5 | class NaturalNumbersFunction { 6 | public: 7 | NaturalNumbersFunction(); 8 | explicit NaturalNumbersFunction(UnaryUnsignedFunction pFunc); 9 | virtual ~NaturalNumbersFunction() = default; 10 | 11 | public: 12 | unsigned CountFixedPoints(int lowerBound, int upperBound) const; 13 | 14 | virtual unsigned Eval(unsigned value) const; 15 | virtual void SetFunction(UnaryUnsignedFunction pFunc); 16 | 17 | protected: 18 | UnaryUnsignedFunction m_pFunc; 19 | 20 | }; 21 | 22 | bool CheckBounds(int& lowerBound, int& upperBound); 23 | bool CheckFunctionsInInterval(const NaturalNumbersFunction& lhs, const NaturalNumbersFunction& rhs, 24 | int lowerBound, int upperBound); -------------------------------------------------------------------------------- /Seminars/Sem.02/Solutions/Examples/04-flags.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "constants.h" 4 | 5 | int Test() 6 | { 7 | std::ifstream file(FILE_NAME); 8 | //file.good(); // all operations went good 9 | //file.clear(); // clears all failures, sets good to true 10 | //file.fail(); // last operation failed 11 | //file.bad(); // input/output operation went bad 12 | //file.eof(); // reached the end of file 13 | 14 | return 0; 15 | } 16 | 17 | int FailExample() 18 | { 19 | int a; 20 | std::cin >> a; 21 | std::cout << std::cin.fail() << std::endl; // true 22 | std::cout << std::cin.good() << std::endl; // false 23 | std::cin.clear(); 24 | std::cout << std::cin.fail() << std::endl; // false 25 | std::cout << std::cin.good() << std::endl; // true 26 | 27 | return 0; 28 | } -------------------------------------------------------------------------------- /Seminars/Sem.04/Solutions/Date/Date.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class Date { 5 | private: 6 | unsigned MAX_DAYS[12] = { 7 | 31,28,31,30,31, 30, 31, 31, 30, 31, 30, 31 8 | }; 9 | unsigned day = 1; 10 | unsigned month = 1; 11 | unsigned year = 1; 12 | 13 | mutable bool isModified = true; 14 | mutable int dayOfWeek = -1; 15 | public: 16 | Date(unsigned day, unsigned month, unsigned year); 17 | unsigned getDay() const; 18 | unsigned getMonth() const; 19 | unsigned getYear() const; 20 | 21 | void setDay(unsigned day); 22 | void setMonth(unsigned month); 23 | void setYear(unsigned year); 24 | 25 | bool isEqualTo(const Date& d) const; 26 | 27 | void print() const; 28 | void goToNextDay(); 29 | int getDayOfWeek() const; 30 | private: 31 | bool isLeapYear() const; 32 | }; 33 | -------------------------------------------------------------------------------- /Seminars/Sem.05/Solutions/Date/Date.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class Date { 5 | private: 6 | unsigned MAX_DAYS[12] = { 7 | 31,28,31,30,31, 30, 31, 31, 30, 31, 30, 31 8 | }; 9 | unsigned day = 1; 10 | unsigned month = 1; 11 | unsigned year = 1; 12 | 13 | mutable bool isModified = true; 14 | mutable int dayOfWeek = -1; 15 | public: 16 | Date(unsigned day, unsigned month, unsigned year); 17 | unsigned getDay() const; 18 | unsigned getMonth() const; 19 | unsigned getYear() const; 20 | 21 | void setDay(unsigned day); 22 | void setMonth(unsigned month); 23 | void setYear(unsigned year); 24 | 25 | bool isEqualTo(const Date& d) const; 26 | 27 | void print() const; 28 | void goToNextDay(); 29 | int getDayOfWeek() const; 30 | private: 31 | bool isLeapYear() const; 32 | }; 33 | -------------------------------------------------------------------------------- /Seminars/Sem.10/Solutions/Person-Student-Teacher/Student/Student.cpp: -------------------------------------------------------------------------------- 1 | #include "Student.h" 2 | 3 | Student::Student(const char* name, int age, size_t fn) : Person(name, age) 4 | { 5 | setFn(fn); 6 | } 7 | 8 | size_t Student::getFn() const 9 | { 10 | return fn; 11 | } 12 | 13 | void Student::setFn(size_t fn) 14 | { 15 | 16 | if (fn < 100) 17 | fn = 100; 18 | this->fn = fn; 19 | } 20 | 21 | // The compiler will make: 22 | 23 | //Student(const Student& other) : Person(other), fn(other.fn), grade(other.grade) OK!!! 24 | //{} 25 | 26 | //Student& operator=(const Student& other) OK!!!! 27 | //{ 28 | // if (this != &other) 29 | // { 30 | // Person::operator=(other); //handles the deletion and copying of the base class 31 | // fn = other.fn; 32 | // } 33 | // return *this; 34 | //} -------------------------------------------------------------------------------- /Seminars/Sem.05/Solutions/Event/Event.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "../Time/Time.h" 3 | #include "../Date/Date.h" 4 | 5 | class Event { 6 | char name[20 + 1]; 7 | Date date; 8 | Time startTime; 9 | Time endTime; 10 | 11 | void setName(const char* str); 12 | void validateTimes(); 13 | 14 | public: 15 | Event(); 16 | Event(const char* name, const Date& date, const Time& startTime, const Time& endTime); 17 | 18 | Event(const char* name, unsigned day, unsigned month, unsigned year, 19 | unsigned startTimeHours, unsigned startTimeMins, unsigned startTimeSecs, 20 | unsigned endTimeHours, unsigned endTimeMins, unsigned endTimeSecs); 21 | 22 | const char* getName() const; 23 | const Date& getDate() const; 24 | const Time& getStartTime() const; 25 | const Time& getEndTime() const; 26 | }; 27 | -------------------------------------------------------------------------------- /Seminars/Utils/Exam/Task01/EventDuringJanuary2023.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class EventDuringJanuary2023 { 6 | private: 7 | const static unsigned FirstDay = 7; 8 | 9 | public: 10 | bool AddDay(unsigned day); 11 | bool RemoveDay(unsigned day); 12 | bool ContainsDay(unsigned long day) const; 13 | bool CheckIfDayIsPresent(unsigned day) const; 14 | unsigned HowManyOnDayOfWeek(unsigned dayOfWeek); 15 | 16 | bool SaveToFile(const char* fileName); 17 | bool ReadFromFile(const char* fileName); 18 | 19 | friend EventDuringJanuary2023 Union(const EventDuringJanuary2023& lhs, const EventDuringJanuary2023& rhs); 20 | friend EventDuringJanuary2023 Interaction(const EventDuringJanuary2023& lhs, const EventDuringJanuary2023& rhs); 21 | 22 | private: 23 | uint32_t m_days = 0; 24 | 25 | }; 26 | -------------------------------------------------------------------------------- /Seminars/Sem.06/Pract. 06/Task01/Duelist.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Deck.h" 3 | 4 | class Duelist { 5 | char* name; 6 | Deck deck; 7 | public: 8 | Duelist(); 9 | Duelist(const char*, const Deck&); 10 | Duelist(const Duelist&); 11 | Duelist& operator=(const Duelist&); 12 | ~Duelist(); 13 | 14 | void setName(const char*); 15 | void setDeck(const Deck&); 16 | 17 | const char* getName() const; 18 | Deck getDeck() const; 19 | 20 | bool addMonsterCard(const MonsterCard& monsterCard); 21 | bool addMagicCard(const MagicCard& MagicCard); 22 | 23 | bool changeMonsterCardAtIndex(const MonsterCard& monsterCard, const int index); 24 | bool changeMagicCardAtIndex(const MagicCard& magicCard, const int index); 25 | 26 | void display() const; 27 | private: 28 | void copy(const Duelist& duelist); 29 | void free(); 30 | }; 31 | -------------------------------------------------------------------------------- /Seminars/Utils/Tasks/Task01/User/User.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class User { 6 | private: 7 | char* userName = nullptr; 8 | char* password = nullptr; 9 | mutable size_t accessCounter = 0; 10 | 11 | void copyUserName(const char* userName); 12 | void copyPassword(const char* password); 13 | 14 | public: 15 | User() = default; 16 | User(const char* userName, const char* password); 17 | User(const User& other); 18 | User& operator=(const User& other); 19 | ~User(); 20 | 21 | const char* getUserName() const; 22 | size_t getAccessCounter() const; 23 | void setUserName(const char* userName); 24 | void setPassword(const char* password); 25 | 26 | void writeToFile(std::ofstream& out) const; 27 | void readFromFile(std::ifstream& in); 28 | 29 | private: 30 | void free(); 31 | void copyFrom(const User& other); 32 | }; -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_mutualCatching/Circle.cpp: -------------------------------------------------------------------------------- 1 | #include "Circle.h" 2 | 3 | const double PI = 3.1415; 4 | Circle::Circle(int x, int y, double radius) : Shape(1), radius(radius) 5 | { 6 | setPoint(0, x, y); 7 | } 8 | 9 | bool Circle::intersectsWith(const Shape* other) const 10 | { 11 | return other->intersectsWithCircle(this); 12 | } 13 | 14 | bool Circle::intersectsWithTriangle(const Triangle* other) const 15 | { 16 | std::cout << "Formula for circle with triangle" << std::endl; 17 | return true; 18 | } 19 | bool Circle::intersectsWithRect(const Rectangle* other) const 20 | { 21 | std::cout << "Formula for circle with rect" << std::endl; 22 | return true; 23 | } 24 | bool Circle::intersectsWithCircle(const Circle* other) const 25 | { 26 | std::cout << "Formula for circle with circle" << std::endl; 27 | return true; 28 | } 29 | -------------------------------------------------------------------------------- /Seminars/Sem.12/Solutions/ShapeCollection/ShapeCollection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Shape.h" 4 | 5 | class ShapeCollection { 6 | private: 7 | Shape** shapes; 8 | size_t shapesCount; 9 | size_t capacity; 10 | public: 11 | ShapeCollection(); 12 | ShapeCollection(const ShapeCollection& other); 13 | ShapeCollection& operator=(const ShapeCollection& other); 14 | ~ShapeCollection(); 15 | 16 | void AddRectangle(int, int, int, int); 17 | void AddCircle(int, int, int ); 18 | void AddTriangle(int, int, int, int, int, int); 19 | 20 | double GetPerOfFigureByIndex(size_t) const; 21 | double GetAreaOfFigureByIndex(size_t) const; 22 | double GetIfPointInShapeByIndex(size_t, int, int) const; 23 | private: 24 | void Resize(); 25 | void AddShape(const Shape* shape); 26 | 27 | void Free(); 28 | void CopyFrom(const ShapeCollection& other); 29 | 30 | }; -------------------------------------------------------------------------------- /Seminars/Sem.04/Pract.04/Task03/Game.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | const char TITLE_MAX_SIZE = 64; 4 | const int CHEAPEST_PRICE = 100000; 5 | const int MOST_EXPENSIVE_PRICE = -100000; 6 | const int FIELD_MAX_SIZE = 256; 7 | 8 | class Game { 9 | private: 10 | double price; 11 | bool isAvailable; 12 | char title[TITLE_MAX_SIZE + 1]; 13 | public: 14 | Game(); 15 | Game(const char* title, double price, bool isAvailable); 16 | 17 | const char* GetTitle() const; 18 | double GetPrice() const; 19 | bool GetAvailability() const; 20 | 21 | bool SetTitle(const char* title); 22 | bool SetPrice(double price); 23 | void SetAvailability(bool isAvailable); 24 | 25 | bool IsFree() const; 26 | void Print() const; 27 | bool IsEqualTo(const Game& game) const; 28 | private: 29 | bool IsInvalidTitle(const char* title) const; 30 | bool IsInvalidPrice(double price) const; 31 | }; -------------------------------------------------------------------------------- /Seminars/Sem.04/Pract.04/Task03/GamePlatform.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Game.h" 3 | 4 | const int GAMES_MAX_COUNT = 15; 5 | 6 | class GamePlatform { 7 | private: 8 | Game games[GAMES_MAX_COUNT]; 9 | size_t gamesCount = 0; 10 | public: 11 | GamePlatform() = default; 12 | GamePlatform(const Game* games, int gamesCount); 13 | 14 | size_t GetGamesCount() const; 15 | const Game GetGameByID(int id) const; 16 | const Game ReturnCheapestGame() const; 17 | const Game ReturnMostExpensiveGame() const; 18 | 19 | bool AddGame(const Game& game); 20 | void RemoveGameFromLibrary(const Game& game); 21 | 22 | void WriteGamePlatformToFile(const char* filePath) const; 23 | void ReadGamePlatformFromFile(const char* filePath); 24 | 25 | void PrintAllGames() const; 26 | void PrintAllFreeGames() const; 27 | private: 28 | void CheckIfThereAreAnyGames() const; 29 | }; 30 | -------------------------------------------------------------------------------- /Seminars/Sem.01/Bonus/SelectionSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void Swap(int& a, int& b) 4 | { 5 | int temp = a; 6 | a = b; 7 | b = temp; 8 | } 9 | 10 | void Print(const int* arr, size_t length) 11 | { 12 | for (size_t i = 0; i < length; i++) { 13 | std::cout << arr[i]<< " "; 14 | } 15 | } 16 | 17 | void SelectionSort(int* arr, size_t length) 18 | { 19 | for (size_t i = 0; i < length - 1; i++) { 20 | size_t minIndex = i; 21 | 22 | // first i numbers are already ordered 23 | for (size_t j = i + 1; j < length; j++) { 24 | if (arr[minIndex] > arr[j]) { 25 | minIndex = j; 26 | } 27 | } 28 | 29 | if (minIndex != i) { // if minIndex changed - swap 30 | Swap(arr[i], arr[minIndex]); 31 | } 32 | } 33 | } 34 | 35 | int main() 36 | { 37 | int arr[] = { 9, 5, 6, 3, 4, 7, 2, 1, 8 }; 38 | 39 | SelectionSort(arr, 9); 40 | Print(arr, 9); 41 | } -------------------------------------------------------------------------------- /Seminars/Sem.07/Solution/NVector/Cartesian.cpp: -------------------------------------------------------------------------------- 1 | #include "Cartesian.h" 2 | 3 | Cartesian2D::Cartesian2D(const Nvector& first, const Nvector& second) { 4 | this->first = first; 5 | this->second = second; 6 | } 7 | 8 | Nvector Cartesian2D::getVectorByCoordinates(const Nvector& other) const { 9 | double coordinates[2]; 10 | coordinates[0] = other[0] * first[0] + other[1] * second[0]; 11 | coordinates[1] = other[0] * first[1] + other[1] * second[1]; 12 | Nvector temp(coordinates, 2); 13 | return temp; 14 | } 15 | 16 | Nvector Cartesian2D::getCoordinatesByVector(const Nvector& other) const { 17 | double coordinates[2]; 18 | coordinates[1] = (first[0] * other[1] - first[1] * other[0]) / (first[0] * second[1] - first[1] * second[0]); 19 | coordinates[0] = (other[0] - (second[0] * coordinates[1]))/first[0]; 20 | Nvector temp(coordinates,2); 21 | return temp; 22 | } 23 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/IntervalCollection.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include"Collection.h" 3 | 4 | class IntervalCollection : public Collection 5 | { 6 | private: 7 | int* data; 8 | int start; 9 | int end; 10 | 11 | void free(); 12 | void copyFrom(const IntervalCollection&); 13 | void moveFrom(IntervalCollection&& other); 14 | public: 15 | IntervalCollection(int start, int end); 16 | 17 | IntervalCollection(const IntervalCollection&); 18 | IntervalCollection(IntervalCollection&&); 19 | 20 | IntervalCollection& operator=(const IntervalCollection&); 21 | IntervalCollection& operator=(IntervalCollection&&); 22 | 23 | unsigned intervalLength() const; 24 | 25 | void add(int) override; 26 | void remove(int) override; 27 | unsigned count(int) const override; 28 | bool contains(int) const override; 29 | 30 | ~IntervalCollection(); 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /Seminars/Sem.01/Bonus/BubbleSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void Swap(int& a, int& b) 4 | { 5 | int temp = a; 6 | a = b; 7 | b = temp; 8 | } 9 | 10 | void Print(const int* arr, size_t length) 11 | { 12 | for (size_t i = 0; i < length; i++) { 13 | std::cout << arr[i]<< " "; 14 | } 15 | } 16 | 17 | void BubbleSort(int* arr, size_t length) 18 | { 19 | for (size_t i = 0; i < length - 1; i++) { 20 | bool hasSwaps = false; 21 | 22 | // last i numbers are already ordered 23 | for (size_t j = 0; j < length - i - 1; j++) { 24 | if (arr[j] > arr[j + 1]) { 25 | Swap(arr[j], arr[j + 1]); 26 | hasSwaps = true; 27 | } 28 | } 29 | 30 | if (!hasSwaps) {// if no swaps were made - array is ordered 31 | break; 32 | } 33 | } 34 | } 35 | 36 | int main() 37 | { 38 | int arr[] = { 9, 5, 6, 3, 4, 7, 2, 1, 8 }; 39 | 40 | BubbleSort(arr, 9); 41 | Print(arr, 9); 42 | } 43 | -------------------------------------------------------------------------------- /Seminars/Sem.01/Pract.01/Task02.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void InputArr(int* arr, const int size) 4 | { 5 | for (size_t i = 0; i < size; i++) { 6 | std::cin >> arr[i]; 7 | } 8 | } 9 | 10 | int CountBiggerSymbols(const int* arr, const int size, const char symbol) 11 | { 12 | int counter = 0; 13 | for (size_t i = 0; i < size; i++) { 14 | if (arr[i] > symbol) { 15 | counter++; 16 | } 17 | } 18 | 19 | return counter; 20 | } 21 | 22 | int main() 23 | { 24 | int N; 25 | cout << "Enter the number of elements in the array: "; 26 | cin >> N; 27 | 28 | int *arr = new int[N]; 29 | InputElements(arr, N); 30 | 31 | char symbol; 32 | cout << "Enter the symbol: "; 33 | cin >> symbol; 34 | 35 | cout << "The number of elements greater than the symbol: " << CountSymbol(arr, N, symbol) << endl; 36 | 37 | delete[] arr; 38 | return 0; 39 | } 40 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_mutualCatching/Rectangle.cpp: -------------------------------------------------------------------------------- 1 | #include "Rectangle.h" 2 | 3 | Rectangle::Rectangle(int x1, int y1, int x3, int y3) : Shape(4) 4 | { 5 | setPoint(0, x1, y1); 6 | setPoint(1, x1, y3); 7 | setPoint(2, x3, y3); 8 | setPoint(3, x3, y1); 9 | } 10 | 11 | bool Rectangle::intersectsWith(const Shape* other) const 12 | { 13 | return other->intersectsWithRect(this); 14 | } 15 | 16 | bool Rectangle::intersectsWithTriangle(const Triangle* other) const 17 | { 18 | std::cout << "Formula for rect with triangle" << std::endl; 19 | return true; 20 | } 21 | bool Rectangle::intersectsWithRect(const Rectangle* other) const 22 | { 23 | std::cout << "Formula for rect with rect" << std::endl; 24 | return true; 25 | } 26 | bool Rectangle::intersectsWithCircle(const Circle* other) const 27 | { 28 | std::cout << "Formula for rect with circle" << std::endl; 29 | return true; 30 | } -------------------------------------------------------------------------------- /Seminars/Sem.06/Pract. 06/Task02/ShoppingCart.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Item.h" 3 | #include 4 | 5 | class ShoppingCart{ 6 | private: 7 | Item* items = nullptr; 8 | int itemsCount = 0; 9 | int maxItemsCount = 0; 10 | 11 | public: 12 | ShoppingCart(); 13 | ShoppingCart(const ShoppingCart& cart); 14 | ShoppingCart& operator=(const ShoppingCart& cart); 15 | ~ShoppingCart(); 16 | 17 | bool AddItem(const Item& item); 18 | bool RemoveItem(const char* name); 19 | int ItemsCount() const; 20 | bool Exists(const char* name) const; 21 | bool IsEmpty() const; 22 | double GetPriceOf(const char* name) const; 23 | double TotalPrice() const; 24 | void SortByName(); 25 | bool Save(const char* fileName) const; 26 | 27 | private: 28 | void copyFrom(const ShoppingCart& cart); 29 | void free(); 30 | void IncreaseItemsCount(); 31 | void Resize(); 32 | int Find(const char* name) const; 33 | }; 34 | 35 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_mutualCatching/Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include "Triangle.h" 2 | #include 3 | 4 | Triangle::Triangle(int x1, int y1, int x2, int y2, int x3, int y3) : Shape(3) 5 | { 6 | setPoint(0, x1, y1); 7 | setPoint(1, x2, y2); 8 | setPoint(2, x3, y3); 9 | } 10 | 11 | bool Triangle::intersectsWith(const Shape* other) const 12 | { 13 | return other->intersectsWithTriangle(this); 14 | } 15 | 16 | bool Triangle::intersectsWithTriangle(const Triangle* other) const 17 | { 18 | std::cout << "Formula for triangle with triangle" << std::endl; 19 | return true; 20 | } 21 | bool Triangle::intersectsWithRect(const Rectangle* other) const 22 | { 23 | std::cout << "Formula for triangle with rect" << std::endl; 24 | return true; 25 | } 26 | bool Triangle::intersectsWithCircle(const Circle* other) const 27 | { 28 | std::cout << "Formula for triangle with circle" << std::endl; 29 | return true; 30 | } -------------------------------------------------------------------------------- /Seminars/Sem.08/Pract.08/Task01/Student.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Grade.h" 4 | 5 | const int MAX_NUMBER_OF_GRADES = 7; 6 | 7 | class Student { 8 | Grade _grades[MAX_NUMBER_OF_GRADES]; 9 | unsigned _numberOfGrades = 0; 10 | unsigned _FN = 0; 11 | MyString _name; 12 | 13 | public: 14 | Student() = default; 15 | Student(const char* name, unsigned FN); 16 | 17 | const Grade* getGrades() const; 18 | unsigned getNumberOfGrades() const; 19 | unsigned getFN() const; 20 | const MyString& getName() const; 21 | 22 | void setName(const char* name); 23 | void setFN(unsigned FN); 24 | 25 | int getTaskIndex(const char* task) const; 26 | 27 | void addGrade(double value, const char* task, const Teacher& teacher); 28 | 29 | double getGradeValueAtIndex(size_t ind) const; 30 | void setGradeAtIndex(size_t ind, double newValue); 31 | 32 | friend std::ostream& operator << (std::ostream& os, const Student& st); 33 | }; -------------------------------------------------------------------------------- /Seminars/Sem.09/Pract.09/Task01/Order/Order.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "MyString.h" 3 | #include "Product.h" 4 | class Order 5 | { 6 | private: 7 | Product* products = nullptr; 8 | MyString restaurantName; 9 | size_t productsCount = 0; 10 | size_t productsCapacity = 0; 11 | 12 | public: 13 | Order() = default; 14 | Order(const MyString& restaurantName, size_t productCapacity); 15 | Order(const Order& other); 16 | Order& operator=(const Order& other); 17 | 18 | Order(Order&& other) noexcept; 19 | Order& operator=(Order&& other) noexcept; 20 | ~Order(); 21 | 22 | void AddProduct(const char* productName); 23 | const char* GetRestaurantName() const; 24 | const Product* GetProducts() const; 25 | size_t GetProductsCount() const; 26 | 27 | void ReceiveOrder(const Order& order); 28 | private: 29 | void CopyFrom(const Order& other); 30 | void MoveFrom(Order&& other); 31 | void Resize(size_t newCapacity); 32 | void Free(); 33 | }; -------------------------------------------------------------------------------- /Seminars/Sem.06/Solutions/SetOfNumbers/SetOfNumbers.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class SetOfNumbers { 4 | private: 5 | unsigned char* data; 6 | unsigned maxNumber; 7 | public: 8 | SetOfNumbers() = default; 9 | SetOfNumbers(unsigned n); 10 | SetOfNumbers(const SetOfNumbers& other); 11 | SetOfNumbers& operator=(const SetOfNumbers& other); 12 | ~SetOfNumbers(); 13 | 14 | bool Contains(unsigned number) const; 15 | bool AddNumber(unsigned number); 16 | bool RemoveNumber(unsigned number); 17 | 18 | void print() const; 19 | 20 | friend SetOfNumbers UnionOfSets(const SetOfNumbers& lhs, const SetOfNumbers& rhs); 21 | friend SetOfNumbers IntersectionOfSets(const SetOfNumbers& lhs, const SetOfNumbers& rhs); 22 | private: 23 | unsigned GetBucketIndex(unsigned number) const; 24 | unsigned GetBucketCount() const; 25 | unsigned char GetMask(unsigned number) const; 26 | 27 | void CopyFrom(const SetOfNumbers& other); 28 | void Free(); 29 | }; 30 | -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/HexViewer/headers/constants.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // 10 kb 4 | const int FILE_SIZE = 10 * 1024; 5 | const int FILE_NAME_SIZE = 50; 6 | const int INPUT_BUFFER_SIZE = 70; 7 | const int COMMAND_SIZE = 20; 8 | // MAX IS 255 - FF 9 | const int HEX_SIZE = 3; 10 | 11 | const char VIEW_COMMAND[] = "view"; 12 | const char CHANGE_COMMAND[] = "change"; 13 | const char REMOVE_COMMAND[] = "remove"; 14 | const char ADD_COMMAND[] = "add"; 15 | const char SAVE_COMMAND[] = "save"; 16 | 17 | const char OPEN_FILE_ERROR_MESSAGE[] = "Error opening the file"; 18 | const char SUCCESSFUL_OPERATION_MESSAGE[] = "Operation successfully executed!"; 19 | const char UNSUCCESSFUL_OPERATION_MESSAGE[] = "Operation didn't execute successfully!"; 20 | 21 | const int UPPERCASE_A_ASCII_CODE = 65; 22 | const int UPPERCASE_F_ASCII_CODE = 70; 23 | const int UPPERCASE_Z_ASCII_CODE = 90; 24 | const int LOWERCASE_A_ASCII_CODE = 97; 25 | const int LOWERCASE_Z_ASCII_CODE = 122; 26 | -------------------------------------------------------------------------------- /Seminars/Utils/Tasks/Task02/Bus.cpp: -------------------------------------------------------------------------------- 1 | #include "Bus.h" 2 | 3 | Bus::Bus():id(0), maxSeats(0), ticketsPriceAdults(0), ticketsPriceStudents(0), isFree(false) {} 4 | 5 | Bus::Bus(unsigned id, unsigned maxSeats, unsigned ticketsPriceAdults, unsigned ticketsPriceStudents) : 6 | id(id), maxSeats(maxSeats), ticketsPriceAdults(ticketsPriceAdults), 7 | ticketsPriceStudents(ticketsPriceStudents), isFree(true) {} 8 | 9 | unsigned Bus::getId() const 10 | { 11 | return id; 12 | } 13 | 14 | unsigned Bus::getMaxSeats() const 15 | { 16 | return maxSeats; 17 | } 18 | 19 | unsigned Bus::getTicketsPriceAdults() const 20 | { 21 | return ticketsPriceAdults; 22 | } 23 | 24 | unsigned Bus::getTicketsPriceStudents() const 25 | { 26 | return ticketsPriceStudents; 27 | } 28 | 29 | bool Bus::isBusFree() const 30 | { 31 | return isFree; 32 | } 33 | 34 | void Bus::useBus() 35 | { 36 | isFree = false; 37 | } 38 | 39 | void Bus::stopUsingBus() 40 | { 41 | isFree = true; 42 | } 43 | -------------------------------------------------------------------------------- /Seminars/Sem.02/Pract.02/Task01.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const char FILE_NAME[] = "results.txt"; 5 | 6 | bool WriteSumAndProductToFile(int num1, int num2, int num3) 7 | { 8 | std::ofstream file(FILE_NAME); 9 | 10 | if (!file.is_open()) { 11 | return false; 12 | } 13 | 14 | file << num1 + num2 + num3 << " " << num1 * num2 * num3 << "\n"; 15 | file.close(); 16 | return true; 17 | } 18 | 19 | bool ReadSumAndProductFromFile() 20 | { 21 | std::ifstream file(FILE_NAME); 22 | if (!file.is_open()) { 23 | return false; 24 | } 25 | 26 | int sum, product; 27 | file >> sum >> product; 28 | std::cout << sum - product << std::endl; 29 | 30 | file.close(); 31 | return true; 32 | } 33 | 34 | int main() 35 | { 36 | int num1, num2, num3; 37 | std::cin >> num1 >> num2 >> num3; 38 | 39 | WriteSumAndProductToFile(num1, num2, num3); 40 | ReadSumAndProductFromFile(); 41 | } -------------------------------------------------------------------------------- /Seminars/Sem.09/Pract.09/Task01/Restaurant/Restaurant.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Product.h" 3 | #include "Order.h" 4 | const int NAME_MAX_SIZE = 25; 5 | class Restaurant 6 | { 7 | private: 8 | Product* products; 9 | char name[NAME_MAX_SIZE + 1]; 10 | size_t productsCount = 0; 11 | size_t productsCapacity = 0; 12 | 13 | public: 14 | Restaurant(); 15 | Restaurant(const char* restaurantName, size_t capacity); 16 | Restaurant(const Restaurant& other); 17 | Restaurant& operator=(const Restaurant& other); 18 | 19 | Restaurant(Restaurant&& other) noexcept; 20 | Restaurant& operator=(Restaurant&& other) noexcept; 21 | 22 | ~Restaurant(); 23 | 24 | void AddProduct(const MyString& productName); 25 | void ReceiveOrder(const Order& order); 26 | 27 | const char* GetRestaurantName() const; 28 | 29 | private: 30 | void CopyFrom(const Restaurant& other); 31 | void Free(); 32 | void MoveFrom(Restaurant&& other); 33 | void Resize(size_t newCapacity); 34 | }; 35 | 36 | -------------------------------------------------------------------------------- /Seminars/Sem.13/Solutions/Pair/Pair.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template 4 | class Pair { 5 | T first; 6 | D second; 7 | public: 8 | Pair() = default; 9 | Pair(const T& first, const D& second); 10 | const T& getFirst() const; 11 | const D& getSecond() const; 12 | 13 | void setFirst(const T& newValue); 14 | void setSecond(const D& newValue); 15 | }; 16 | 17 | template 18 | Pair::Pair(const T& first, const D& second) : first(first), second(second) 19 | {} 20 | 21 | template 22 | const T& Pair::getFirst() const { 23 | return first; 24 | } 25 | 26 | template 27 | const D& Pair::getSecond() const { 28 | return second; 29 | } 30 | 31 | template 32 | void Pair::setFirst(const T& newValue) { 33 | first = newValue; 34 | } 35 | 36 | template 37 | void Pair::setSecond(const D& newValue) { 38 | second = newValue; 39 | } -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Shapes/cpp/Rectangle.cpp: -------------------------------------------------------------------------------- 1 | #include "Rectangle.h" 2 | 3 | Rectangle::Rectangle(int x1, int y1, int x3, int y3) : Shape(4) { 4 | setPoint(0, x1, y1); 5 | setPoint(1, x1, y3); 6 | setPoint(2, x3, y3); 7 | setPoint(3, x3, y1); 8 | } 9 | 10 | double Rectangle::GetArea() const { 11 | const Shape::point& p0 = getPointAtIndex(0); 12 | const Shape::point& p1 = getPointAtIndex(1); 13 | const Shape::point& p3 = getPointAtIndex(3); 14 | 15 | return p0.getDist(p1) * p0.getDist(p3); 16 | } 17 | 18 | double Rectangle::GetPer() const { 19 | const Shape::point& p0 = getPointAtIndex(0); 20 | const Shape::point& p1 = getPointAtIndex(1); 21 | const Shape::point& p3 = getPointAtIndex(3); 22 | 23 | return 2 * (p0.getDist(p1) + p0.getDist(p3)); 24 | } 25 | 26 | bool Rectangle::IsPointIn(int x, int y) const { 27 | Shape::point p(x, y); 28 | return p.x >= getPointAtIndex(0).x && p.y >= getPointAtIndex(1).x && 29 | p.y <= getPointAtIndex(0).y && p.y >= getPointAtIndex(2).y; 30 | } 31 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Shapes/hpp/Shape.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Shape { 6 | private: 7 | Point* points = nullptr; 8 | size_t pointsCount = 0; 9 | protected: 10 | struct Point { 11 | int x = 0, y = 0; 12 | 13 | Point() = default; 14 | Point(int x, int y) : x(x), y(y) {} 15 | 16 | double GetDist(const point& other) const { 17 | int dx = x - other.x; 18 | int dy = y - other.y; 19 | 20 | return sqrt(dx * dx + dy * dy); 21 | } 22 | }; 23 | 24 | void SetPoint(size_t pointIndex, int x, int y); 25 | const Point& GetPointAtIndex(size_t index) const; 26 | public: 27 | Shape() = default; 28 | explicit Shape(size_t pointsCount); 29 | Shape(const Shape& other); 30 | Shape& operator=(const Shape& other); 31 | virtual ~Shape(); 32 | 33 | virtual double GetArea() const = 0; 34 | virtual double GetPer() const = 0; 35 | virtual bool IsPointIn(int x, int y) const = 0; 36 | private: 37 | void CopyFrom(const Shape& other); 38 | void Free(); 39 | }; -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/StringView/StringView.cpp: -------------------------------------------------------------------------------- 1 | #include "StringView.h" 2 | 3 | StringView::StringView(const char* begin, const char* end): _begin(begin), _end(end) 4 | {} 5 | 6 | StringView::StringView(const char* str) : StringView(str, str + strlen(str)) {} 7 | 8 | StringView::StringView(const MyString& str) : StringView(str.c_str()) {} 9 | 10 | size_t StringView::length() const 11 | { 12 | return _end - _begin; 13 | } 14 | char StringView::operator[](size_t index) const 15 | { 16 | return _begin[index]; 17 | } 18 | 19 | StringView StringView::substr(size_t from, size_t length) const 20 | { 21 | if (_begin + from + length > _end) 22 | throw std::length_error("Error, Substr out of range"); 23 | 24 | return StringView(_begin + from, _begin + from + length); 25 | } 26 | 27 | std::ostream& operator<<(std::ostream& os, const StringView& strView) 28 | { 29 | const char* iter = strView._begin; 30 | 31 | while (iter != strView._end) 32 | { 33 | os << *iter; 34 | iter++; 35 | } 36 | return os; 37 | } -------------------------------------------------------------------------------- /Seminars/Sem.14/Solutions/MyString/StringView.cpp: -------------------------------------------------------------------------------- 1 | #include "StringView.h" 2 | 3 | StringView::StringView(const char* begin, const char* end) : _begin(begin), _end(end) 4 | {} 5 | 6 | StringView::StringView(const char* str) : StringView(str, str + strlen(str)) {} 7 | 8 | StringView::StringView(const MyString& str) : StringView(str.c_str()) {} 9 | 10 | size_t StringView::length() const 11 | { 12 | return _end - _begin; 13 | } 14 | char StringView::operator[](size_t index) const 15 | { 16 | return _begin[index]; 17 | } 18 | 19 | StringView StringView::substr(size_t from, size_t length) const 20 | { 21 | if (_begin + from + length > _end) 22 | throw std::length_error("Error, Substr out of range"); 23 | 24 | return StringView(_begin + from, _begin + from + length); 25 | } 26 | 27 | std::ostream& operator<<(std::ostream& os, const StringView& strView) 28 | { 29 | const char* iter = strView._begin; 30 | 31 | while (iter != strView._end) 32 | { 33 | os << *iter; 34 | iter++; 35 | } 36 | return os; 37 | } -------------------------------------------------------------------------------- /Seminars/Sem.02/Solutions/Examples/05-modes.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "constants.h" 4 | 5 | int Modes() 6 | { 7 | std::fstream file(FILE_NAME, std::ios_base::ate | std::ios_base::out | std::ios_base::_Nocreate); 8 | // std::ios_base::in - read mode - base ifstream mode 9 | // std::ios_base::out - read mode - base ofstream mode 10 | // std::ios_base::binary - binary mode - next time 11 | // std::ios_base::trunc - if the file exists delets the content 12 | // std::ios_base::app - seekp at the end, write operations can be performed ONLY at the end 13 | // std::ios_base::ate - seekp at the end, write operations can be performed anywhere, we can move the seekp 14 | // std::ios_base::nocreate - opens the file only if it exist 15 | // std::ios_base::noreplace - opens the file only if it DOES NOT exist 16 | 17 | if (!file.is_open()) { 18 | std::cout << INVALID_FILE_ERR_MSG; 19 | return -1; 20 | } 21 | 22 | file.seekp(0, std::ios::beg); 23 | 24 | file << "fsdaf"; 25 | } 26 | -------------------------------------------------------------------------------- /Seminars/Sem.07/Solution/Rational/Rational.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class Rational { 5 | int num; 6 | int denom; 7 | public: 8 | Rational(); 9 | Rational(int, int); 10 | 11 | int GetNuminator() const; 12 | int GetDenominator() const; 13 | 14 | void SetNuminator(int); 15 | void SetDenominator(int); 16 | 17 | void rationalize(); 18 | 19 | void Print() const; 20 | 21 | Rational& operator+=(const Rational&); 22 | Rational& operator-=(const Rational&); 23 | Rational& operator*=(const Rational&); 24 | Rational& operator/=(const Rational&); 25 | 26 | friend std::ostream& operator<<(std::ostream&, const Rational&); 27 | friend std::istream& operator>>(std::istream&, Rational&); 28 | }; 29 | 30 | Rational operator+(const Rational&, const Rational&); 31 | Rational operator-(const Rational&, const Rational&); 32 | Rational operator*(const Rational&, const Rational&); 33 | Rational operator/(const Rational&, const Rational&); 34 | 35 | bool operator==(const Rational&, const Rational&); 36 | -------------------------------------------------------------------------------- /Seminars/Utils/Tasks/Task02/Trip.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | #include "Bus.h" 4 | #include "Passenger.h" 5 | 6 | class Trip 7 | { 8 | char* destination; 9 | Bus* bus; 10 | Passenger* passengers; 11 | unsigned passengersCount; 12 | unsigned passengersCapacity; 13 | bool isUpcomming; 14 | 15 | void copyFrom(const Trip& other); 16 | void copyDest(const char* dest); 17 | void copyPassengers(const Passenger* pass, unsigned count, unsigned capacity); 18 | void free(); 19 | 20 | public: 21 | Trip(); 22 | Trip(const char* destination, Bus* bus); 23 | Trip(const Trip& other); 24 | Trip& operator=(const Trip& other); 25 | ~Trip(); 26 | 27 | const Bus* getBus() const; 28 | const char* getDestination() const; 29 | 30 | void addPassenger(const Passenger& passenger); 31 | unsigned getPriceForTrip() const; 32 | unsigned getFreeSeats() const; 33 | 34 | bool doesPassergerHaveSeat(const char* name) const; 35 | void startTrip(); 36 | bool isTripUpcomming() const; 37 | void printTrip() const; 38 | bool isFull() const; 39 | }; -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_polymorphism/Rectangle.cpp: -------------------------------------------------------------------------------- 1 | #include "Rectangle.h" 2 | 3 | Rectangle::Rectangle(int x1, int y1, int x3, int y3) : Shape(4) 4 | { 5 | setPoint(0, x1, y1); 6 | setPoint(1, x1, y3); 7 | setPoint(2, x3, y3); 8 | setPoint(3, x3, y1); 9 | } 10 | double Rectangle::getArea() const 11 | { 12 | const Shape::point& p0 = getPointAtIndex(0); 13 | const Shape::point& p1 = getPointAtIndex(1); 14 | const Shape::point& p3 = getPointAtIndex(3); 15 | 16 | return p0.getDist(p1) * p0.getDist(p3); 17 | 18 | } 19 | double Rectangle::getPer() const 20 | { 21 | const Shape::point& p0 = getPointAtIndex(0); 22 | const Shape::point& p1 = getPointAtIndex(1); 23 | const Shape::point& p3 = getPointAtIndex(3); 24 | 25 | return 2*(p0.getDist(p1) + p0.getDist(p3)); 26 | } 27 | 28 | bool Rectangle::isPointIn(int x, int y) const 29 | { 30 | Shape::point p(x, y); 31 | return p.x >= getPointAtIndex(0).x && p.y >= getPointAtIndex(1).x && 32 | p.y <= getPointAtIndex(0).y && p.y >= getPointAtIndex(2).y; 33 | } 34 | -------------------------------------------------------------------------------- /Seminars/Sem.14/Solutions/ExpressionCalculator/MyString/StringView.cpp: -------------------------------------------------------------------------------- 1 | #include "StringView.h" 2 | 3 | StringView::StringView(const char* begin, const char* end) : _begin(begin), _end(end) 4 | {} 5 | 6 | StringView::StringView(const char* str) : StringView(str, str + strlen(str)) {} 7 | 8 | StringView::StringView(const MyString& str) : StringView(str.c_str()) {} 9 | 10 | size_t StringView::length() const 11 | { 12 | return _end - _begin; 13 | } 14 | char StringView::operator[](size_t index) const 15 | { 16 | return _begin[index]; 17 | } 18 | 19 | StringView StringView::substr(size_t from, size_t length) const 20 | { 21 | if (_begin + from + length > _end) 22 | throw std::length_error("Error, Substr out of range"); 23 | 24 | return StringView(_begin + from, _begin + from + length); 25 | } 26 | 27 | std::ostream& operator<<(std::ostream& os, const StringView& strView) 28 | { 29 | const char* iter = strView._begin; 30 | 31 | while (iter != strView._end) 32 | { 33 | os << *iter; 34 | iter++; 35 | } 36 | return os; 37 | } -------------------------------------------------------------------------------- /Seminars/Sem.06/Pract. 06/Task01/Deck.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "MagicCard.h" 4 | #include "MonsterCard.h" 5 | 6 | const short MAX_DECK_SIZE = 40; 7 | 8 | class Deck { 9 | private: 10 | MagicCard magicCards[MAX_DECK_SIZE / 2]; 11 | MonsterCard monsterCards[MAX_DECK_SIZE / 2]; 12 | 13 | bool monsterCardUsedPositions[MAX_DECK_SIZE / 2]; 14 | bool magicCardUsedPositions[MAX_DECK_SIZE / 2]; 15 | 16 | size_t magicCardsSize; 17 | size_t monsterCardsSize; 18 | public: 19 | Deck(); 20 | 21 | Deck(const Deck& deck) = default; 22 | Deck& operator=(const Deck& deck) = default; 23 | ~Deck() = default; 24 | 25 | size_t getMagicCardsSize() const; 26 | size_t getMonsterCardsSize() const; 27 | 28 | bool addMagicCardToDeck(const MagicCard& magicCard); 29 | bool addMonsterCardToDeck(const MonsterCard& monsterdrCard); 30 | 31 | bool addMagicCardToDeckAtIndex(const MagicCard& magicCard, const int index); 32 | bool addMonsterCardToDeckAtIndex(const MonsterCard& monsterdrCard, const int index); 33 | 34 | void info() const; 35 | }; 36 | -------------------------------------------------------------------------------- /Seminars/Sem.12/Solutions/Shapes/hpp/Shape.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Shape { 6 | private: 7 | Point* points = nullptr; 8 | size_t pointsCount = 0; 9 | protected: 10 | struct Point { 11 | int x = 0, y = 0; 12 | 13 | Point() = default; 14 | Point(int x, int y) : x(x), y(y) {} 15 | 16 | double GetDist(const point& other) const { 17 | int dx = x - other.x; 18 | int dy = y - other.y; 19 | 20 | return sqrt(dx * dx + dy * dy); 21 | } 22 | }; 23 | 24 | void SetPoint(size_t pointIndex, int x, int y); 25 | const Point& GetPointAtIndex(size_t index) const; 26 | public: 27 | Shape() = default; 28 | explicit Shape(size_t pointsCount); 29 | Shape(const Shape& other); 30 | Shape& operator=(const Shape& other); 31 | virtual ~Shape(); 32 | 33 | virtual double GetArea() const = 0; 34 | virtual double GetPer() const = 0; 35 | virtual bool IsPointIn(int x, int y) const = 0; 36 | 37 | virtual Shape* clone() const = 0; 38 | private: 39 | void CopyFrom(const Shape& other); 40 | void Free(); 41 | }; -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/HexViewer/cpp/stringHelperFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include "../stringHelperFunctions.h" 2 | 3 | int strLength(const char* str) { 4 | int size = 0; 5 | while (str[size] != '\0') { size++; } 6 | 7 | return size; 8 | } 9 | 10 | char* subStr(const char* str, const int& startIndex, const int& endIndex) { 11 | int resultSize = endIndex - startIndex + 2; 12 | char* result = new char[resultSize]; 13 | 14 | int length = strLength(str); 15 | if (startIndex > endIndex || endIndex >= length) 16 | { 17 | return result; 18 | } 19 | 20 | for (size_t i = 0; i < resultSize - 1; i++) 21 | { 22 | result[i] = str[startIndex + i]; 23 | } 24 | 25 | result[resultSize - 1] = '\0'; 26 | 27 | return result; 28 | } 29 | 30 | bool strCmp(const char* str1, const char* str2) { 31 | int length1 = strLength(str1); 32 | int length2 = strLength(str2); 33 | 34 | if (length1 != length2) return false; 35 | 36 | for (size_t i = 0; i < length1; i++) 37 | { 38 | if (str1[i] != str2[i]) return false; 39 | } 40 | 41 | return true; 42 | } 43 | -------------------------------------------------------------------------------- /Seminars/Sem.14/Pract. 14/Bar/Pair/Pair.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | template 4 | class Pair 5 | { 6 | T first; 7 | mutable D second; // For Drinks task!! 8 | public: 9 | Pair() = default; 10 | Pair(const T& first, const D& second); 11 | const T& getFirst() const; 12 | const D& getSecond() const; 13 | 14 | void setFirst(const T& newValue); 15 | void setSecond(const D& newValue) const ; 16 | }; 17 | 18 | template 19 | Pair::Pair(const T& first, const D& second) : first(first), second(second) 20 | {} 21 | 22 | template 23 | const T& Pair::getFirst() const 24 | { 25 | return first; 26 | } 27 | template 28 | const D& Pair::getSecond() const 29 | { 30 | return second; 31 | } 32 | 33 | template 34 | void Pair::setFirst(const T& newValue) 35 | { 36 | first = newValue; 37 | } 38 | 39 | template 40 | void Pair::setSecond(const D& newValue) const 41 | { 42 | second = newValue; 43 | } -------------------------------------------------------------------------------- /Seminars/Utils/Tasks/Task02/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "BusStation.h" 3 | 4 | int main() 5 | { 6 | Passenger p1("Ivan", 17); 7 | Passenger p2("Georgi", 17); 8 | Passenger p3("Maria", 23); 9 | 10 | Bus b1(1, 2, 10, 5); 11 | Bus b2(2, 2, 10, 5); 12 | 13 | BusStation bs; 14 | bs.addBus(b1); 15 | bs.addBus(b2); 16 | 17 | std::cout << bs.addTrip("Kazanlak") << std::endl; //1 18 | std::cout << bs.addTrip("Burgas") << std::endl; //1 19 | std::cout << bs.addTrip("Burgas") << std::endl; //0 20 | 21 | bs.printCurrentBusses(); 22 | 23 | std::cout << bs.addPassenger(p1, "Burgas") << std::endl; //1 24 | std::cout << bs.addPassenger(p2, "Burgas") << std::endl; //1 25 | std::cout << bs.addPassenger(p3, "Burgas") << std::endl; //0 26 | 27 | bs.busArrives(2); 28 | std::cout << bs.addTrip("Burgas") << std::endl; //1 29 | std::cout << bs.addPassenger(p3, "Burgas") << std::endl; //1 30 | 31 | bs.printCurrentBusses(); 32 | std::cout << bs.getTotalProfit() << std::endl; //20 33 | } 34 | -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/HexViewer/cpp/commands.cpp: -------------------------------------------------------------------------------- 1 | #include "commands.h" 2 | #include "../helperFunctions.h" 3 | #include 4 | 5 | using namespace std; 6 | 7 | void viewFile(const File& file) { 8 | int index = 0; 9 | while (index < file.size) 10 | { 11 | printHex(file.data[index++]); 12 | } 13 | 14 | cout << endl; 15 | 16 | index = 0; 17 | while (index < file.size) 18 | { 19 | printLetter(file.data[index++]); 20 | } 21 | 22 | cout << endl; 23 | } 24 | 25 | bool changeByteAtIndex(File& file, const char& character, int index) { 26 | if (index >= file.size) 27 | { 28 | return false; 29 | } 30 | 31 | file.data[index] = character; 32 | return true; 33 | } 34 | 35 | bool removeByteFromEnd(File& file) { 36 | if (file.size == 0) 37 | { 38 | return false; 39 | } 40 | 41 | file.data[--file.size] = '\0'; 42 | return true; 43 | } 44 | 45 | bool addByteToEnd(File& file, const char& character) { 46 | if (file.size == FILE_SIZE) 47 | { 48 | return false; 49 | } 50 | 51 | file.data[file.size++] = character; 52 | return true; 53 | } -------------------------------------------------------------------------------- /Seminars/Sem.04/Pract.04/Task02/Task.cpp: -------------------------------------------------------------------------------- 1 | #include "Task.h" 2 | 3 | #include 4 | 5 | Task::Task() 6 | : Task("", "", 0) 7 | {} 8 | 9 | Task::Task(const char *name, const char *description, int points) 10 | { 11 | strcpy_s(m_name, name); 12 | strcpy_s(m_description, description); 13 | m_points = points; 14 | } 15 | 16 | void Task::SetName(const char *name) 17 | { 18 | if(!name || strlen(name) >= MAX_TASK_NAME_SIZE) 19 | return; 20 | 21 | strcpy_s(m_name, name); 22 | } 23 | 24 | void Task::SetDescription(const char *description) 25 | { 26 | if(!description || strlen(description) >= MAX_TASK_DESCRIPTION_SIZE) 27 | return; 28 | 29 | strcpy_s(m_description, description); 30 | } 31 | 32 | void Task::SetPoints(int points) 33 | { 34 | m_points = points; 35 | } 36 | 37 | const char *Task::GetName() const 38 | { 39 | return m_name; 40 | } 41 | 42 | const char *Task::GetDescription() const 43 | { 44 | return m_description; 45 | } 46 | 47 | int Task::GetPoints() const 48 | { 49 | return m_points; 50 | } 51 | -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/task1-write.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | struct Student 7 | { 8 | char name[30]; 9 | int age; 10 | int fn; 11 | }; 12 | 13 | void initStudent(Student& st, const char* name, int age, int fn) 14 | { 15 | strcpy(st.name, name); 16 | st.age = age; 17 | st.fn = fn; 18 | } 19 | 20 | void saveToFile(const Student* students, size_t count, ofstream& file) 21 | { 22 | file.write((const char*)students, count * sizeof(Student)); 23 | } 24 | 25 | int main() 26 | { 27 | Student* arr = new Student[4]; 28 | initStudent(arr[0], "ivan", 44, 1234); 29 | initStudent(arr[1], "petur", 12, 765); 30 | initStudent(arr[2], "alex", 15, 44); 31 | initStudent(arr[3], "katerina", 19, 12134); 32 | 33 | ofstream file("students.dat", ios::binary); 34 | 35 | if(!file.is_open()) 36 | { 37 | std::cout << "Error while opening the file!" << std::endl; 38 | delete[] arr; //! 39 | return -1; 40 | } 41 | 42 | saveToFile(arr, 4, file); 43 | 44 | delete[] arr; 45 | 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_polymorphism/Shape.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class Shape // Abstract class - no instances of Shape are allowed! 5 | { 6 | protected: 7 | struct point 8 | { 9 | point() :x(0), y(0){} 10 | point(int x, int y) :x(x), y(y){} 11 | int x; 12 | int y; 13 | double getDist(const point& other) const 14 | { 15 | int dx = x - other.x; 16 | int dy = y - other.y; 17 | 18 | return sqrt(dx*dx + dy*dy); 19 | } 20 | }; 21 | const point& getPointAtIndex(size_t index) const; 22 | private: 23 | point* points; 24 | size_t pointsCount; 25 | 26 | void copyFrom(const Shape& other); 27 | void free(); 28 | 29 | 30 | public: 31 | Shape(size_t pointsCount); 32 | 33 | Shape(const Shape& other); 34 | Shape& operator=(const Shape& other); 35 | virtual ~Shape(); //!!!!!! 36 | 37 | void setPoint(size_t pointIndex, int x, int y); 38 | 39 | virtual double getArea() const = 0; //pure virtual 40 | virtual double getPer() const = 0; // pure virtual 41 | virtual bool isPointIn(int x, int y) const = 0; 42 | 43 | }; -------------------------------------------------------------------------------- /Seminars/Sem.04/Pract.04/Task04/Secret.cpp: -------------------------------------------------------------------------------- 1 | #include "Secret.h" 2 | #include 3 | #pragma warning(disable : 4996) 4 | 5 | Secret::Secret(const char* taskDescription, const char* password) { 6 | strcpy(this->_taskDescription, taskDescription); 7 | strcpy(this->_password, password); 8 | failedLogins = 0; 9 | } 10 | 11 | const char* Secret::getTask(const char* pwd) const { 12 | if (strcmp(this->_password, pwd) == 0) { 13 | return this->_taskDescription; 14 | } 15 | 16 | this->failedLogins++; 17 | return ""; 18 | } 19 | 20 | void Secret::setPassword(const char* newPassword, const char* oldPassword) { 21 | if (strcmp(this->_password, oldPassword) == 0) { 22 | strcpy(this->_password, newPassword); 23 | } else { 24 | this->failedLogins++; 25 | } 26 | } 27 | 28 | void Secret::setTask(const char* newTask, const char* passwd) 29 | { 30 | if (strcmp(this->password, passwd) == 0) { 31 | strcpy(this->taskDescription, newTask); 32 | } else { 33 | this->failedLogins++; 34 | } 35 | } 36 | 37 | size_t Secret::getLoginFails() const { 38 | return this->failedLogins; 39 | } -------------------------------------------------------------------------------- /Seminars/Sem.09/Pract.09/Task01/Foodpanda/Foodpanda.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Restaurant.h" 3 | class Foodpanda 4 | { 5 | private: 6 | Restaurant* restaurants = nullptr; 7 | size_t restaurantsCount = 0; 8 | size_t restaurantsCapacity = 0; 9 | 10 | public: 11 | Foodpanda() = default; 12 | Foodpanda(size_t restaurantsCapacity); 13 | Foodpanda(const Foodpanda& other); 14 | Foodpanda& operator=(const Foodpanda& other); 15 | ~Foodpanda(); 16 | 17 | Foodpanda(Foodpanda&& other) noexcept; 18 | Foodpanda& operator=(Foodpanda&& other) noexcept; 19 | 20 | void AddRestaurant(const MyString& restaurantName, size_t restaurantCapacity); 21 | void AddNewProductsInRestaurant(const MyString& restaurantName, 22 | const MyString* products, size_t productsCount); 23 | void ReadOrder(const MyString& restaurantName, const Order& order); 24 | private: 25 | void CopyFrom(const Foodpanda& other); 26 | void MoveFrom(Foodpanda&& other); 27 | void Resize(size_t newCapacity); 28 | void Free(); 29 | 30 | bool ThisRestaurantExists(const char* restaurantName, int& id) const; 31 | }; 32 | 33 | -------------------------------------------------------------------------------- /Seminars/Sem.12/Solutions/Shapes/cpp/Rectangle.cpp: -------------------------------------------------------------------------------- 1 | #include "Rectangle.h" 2 | 3 | Rectangle::Rectangle(int x1, int y1, int x3, int y3) : Shape(4) { 4 | setPoint(0, x1, y1); 5 | setPoint(1, x1, y3); 6 | setPoint(2, x3, y3); 7 | setPoint(3, x3, y1); 8 | } 9 | 10 | double Rectangle::GetArea() const { 11 | const Shape::point& p0 = getPointAtIndex(0); 12 | const Shape::point& p1 = getPointAtIndex(1); 13 | const Shape::point& p3 = getPointAtIndex(3); 14 | 15 | return p0.getDist(p1) * p0.getDist(p3); 16 | } 17 | 18 | double Rectangle::GetPer() const { 19 | const Shape::point& p0 = getPointAtIndex(0); 20 | const Shape::point& p1 = getPointAtIndex(1); 21 | const Shape::point& p3 = getPointAtIndex(3); 22 | 23 | return 2 * (p0.getDist(p1) + p0.getDist(p3)); 24 | } 25 | 26 | bool Rectangle::IsPointIn(int x, int y) const { 27 | Shape::point p(x, y); 28 | return p.x >= getPointAtIndex(0).x && p.y >= getPointAtIndex(1).x && 29 | p.y <= getPointAtIndex(0).y && p.y >= getPointAtIndex(2).y; 30 | } 31 | 32 | Shape* Rectangle::clone() const override { 33 | return new Rectangle(*this); 34 | } -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/NormalCollection.cpp: -------------------------------------------------------------------------------- 1 | #include "NormalCollection.h" 2 | #include 3 | 4 | void NormalCollection::add(int elem) 5 | { 6 | if (size == capacity) 7 | { 8 | resize(2 * size); 9 | } 10 | 11 | data[size++] = elem; 12 | } 13 | 14 | void NormalCollection::remove(int elem) 15 | { 16 | int elemIndex = -1; 17 | 18 | for (size_t i = 0; i < size; i++) 19 | { 20 | if (data[i] == elem) 21 | { 22 | elemIndex = i; 23 | break; 24 | } 25 | } 26 | 27 | if (elemIndex != -1) 28 | { 29 | std::swap(data[elemIndex], data[size - 1]); 30 | size--; 31 | } 32 | } 33 | 34 | unsigned NormalCollection::count(int elem) const 35 | { 36 | unsigned elementCounter = 0; 37 | 38 | for (size_t i = 0; i < size; i++) 39 | { 40 | if (data[i] == elem) 41 | { 42 | ++elementCounter; 43 | } 44 | } 45 | 46 | return elementCounter; 47 | } 48 | 49 | bool NormalCollection::contains(int elem) const 50 | { 51 | for (size_t i = 0; i < size; i++) 52 | { 53 | if (data[i] == elem) 54 | { 55 | return true; 56 | } 57 | } 58 | return false; 59 | } 60 | -------------------------------------------------------------------------------- /Seminars/Sem.08/Pract.08/Task01/Grade.cpp: -------------------------------------------------------------------------------- 1 | #include "Grade.h" 2 | 3 | #include 4 | #pragma warning(disable : 4996) 5 | 6 | 7 | bool Grade::isValidGrade() const { 8 | return (_value >= 2 && _value <= 6) && _task.length() != 0 && _teacher != nullptr; 9 | } 10 | 11 | void Grade::setValue(double value) { 12 | if (value >= 2 && value <= 6) { 13 | _value = value; 14 | } 15 | } 16 | 17 | void Grade::setTask(const char* task) { 18 | _task = MyString(task); 19 | } 20 | 21 | void Grade::setTeacher(const Teacher* teacher){ 22 | _teacher = teacher; 23 | } 24 | 25 | double Grade::getValue() const { 26 | return _value; 27 | } 28 | 29 | const MyString& Grade::getTask() const { 30 | return _task; 31 | } 32 | 33 | const Teacher* Grade::getTeacher() const{ 34 | return _teacher; 35 | } 36 | 37 | Grade::Grade(double value, const char* task, const Teacher* teacher) { 38 | setValue(value); 39 | setTask(task); 40 | setTeacher(teacher); 41 | } 42 | 43 | std::ostream& operator<<(std::ostream& os, const Grade& grade) { 44 | return os << grade._task << " " << *grade._teacher << " " << grade._value; 45 | } -------------------------------------------------------------------------------- /Seminars/Utils/TheoryExamples/Sem2.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | size_t getFileSize(std::ifstream& in) { 5 | size_t current = in.tellg(); 6 | in.seekg(0, std::ios::end); 7 | size_t size = in.tellg(); 8 | in.seekg(current, std::ios::beg); 9 | 10 | return size; 11 | } 12 | 13 | unsigned getCharCountFromFile(std::ifstream& in, char ch) { 14 | size_t currentPosition = in.tellg(); 15 | in.seekg(0, std::ios::beg); 16 | 17 | if (!in.is_open()) { 18 | return 0; 19 | } 20 | 21 | unsigned int count = 0; 22 | char current; 23 | while (true) { 24 | in.get(current); // current = in.get(); 25 | if (in.eof()) { 26 | break; 27 | } 28 | 29 | if (current == ch) { 30 | count++; 31 | } 32 | } 33 | 34 | in.clear(); 35 | in.seekg(currentPosition); 36 | return count; 37 | } 38 | 39 | unsigned getLinesCount(const char* fileName) { 40 | std::ifstream in(fileName); 41 | 42 | if (!in.is_open()) { 43 | return 0; 44 | } 45 | 46 | return getCharCountFromFile(in, '\n') + 1; 47 | } 48 | 49 | int main3() 50 | { 51 | std::cout << getLinesCount("file.txt"); 52 | return 0; 53 | } -------------------------------------------------------------------------------- /Seminars/Sem.15/Solutions/Design-Patterns/README.md: -------------------------------------------------------------------------------- 1 | # Design Patterns 2 | 3 | Design patterns са стандартни решения на често срещани проблеми в софтуерния дизайн. 4 | Те не са специфичен код, който да може да copy paste-нете във вашия проект, а са концепция по какъв начин да решите даден проблем. 5 | Всеки design pattern е шаблон, по който да се реши различен проблем. 6 | 7 | ### Плюсове: 8 | - Общ език между различните членове на екипа 9 | - Вече тествани решения на често срещани проблеми в софтуерния дизайн 10 | - Увеличават абстракцията 11 | - Увеличават гъвкавостта и преизползването на код 12 | - Улесняват development-a при скалиране на приложението 13 | 14 | ### Минуси: 15 | - Използване без да се разбират достатъчно добре 16 | - [Golden Hammer](https://sourcemaking.com/antipatterns/golden-hammer) ``` If all you have is a hammer, everything looks like a nail. ``` 17 | 18 | ## Видове 19 | Могат да бъдат категоризирани по тяхната цел и предназначение. 20 | Техните категории са три - Behavioral, Creational и Structural 21 | 22 | Полезни линкове: 23 | - [Refactoring Guru](https://refactoring.guru/design-patterns) 24 | -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/FlightsScanner - Exception handling task/Utills.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | //we don't make them static, because we want to use the in other cpp files. 4 | 5 | bool isLower(char ch) { return ch >= 'a' && ch <= 'z'; } 6 | 7 | bool isSymbol(char ch) 8 | { 9 | return ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z'; 10 | } 11 | 12 | void toUpper(char* str) 13 | { 14 | if (str == nullptr) 15 | throw std::invalid_argument("The given string does not exist"); 16 | 17 | static int diff = 'a' - 'A'; 18 | while (*str) 19 | { 20 | if (!isSymbol(*str)) 21 | throw std::bad_cast(); 22 | if (isLower(*str)) 23 | *str = *str - diff; 24 | str++; 25 | } 26 | } 27 | 28 | unsigned charToDigit(char ch) 29 | { 30 | if (ch < '0' || ch > '9') 31 | throw std::bad_cast(); 32 | 33 | return ch - '0'; 34 | } 35 | 36 | unsigned convertToNumber(const char* str) 37 | { 38 | if (!str) 39 | throw std::invalid_argument("The given string does not exist"); 40 | 41 | unsigned result = 0; 42 | while (*str) 43 | { 44 | result *= 10; 45 | result += charToDigit(*str); 46 | str++; 47 | } 48 | return result; 49 | } -------------------------------------------------------------------------------- /Seminars/Sem.14/Pract. 14/Bar/Drink/Drink.cpp: -------------------------------------------------------------------------------- 1 | #include "Drink.h" 2 | 3 | Drink::Drink() : Drink("Unknown", 0) 4 | {} 5 | 6 | const MyString& Drink::getName() const 7 | { 8 | return name; 9 | } 10 | int Drink::getMl() const 11 | { 12 | return ml; 13 | } 14 | 15 | bool isLower(char ch) 16 | { 17 | return ch >= 'a' && ch <= 'z'; 18 | } 19 | 20 | bool areAllLowerCase(const char* str) 21 | { 22 | while (*str) 23 | { 24 | if (!isLower(*str)) 25 | return false; 26 | str++; 27 | } 28 | return true; 29 | } 30 | 31 | bool isUpper(char ch) 32 | { 33 | return ch >= 'A' && ch <= 'Z'; 34 | } 35 | 36 | bool isNameValid(const char* name) 37 | { 38 | return isUpper(*name) && areAllLowerCase(name + 1); 39 | } 40 | 41 | void Drink::setName(const MyString& name) 42 | { 43 | if (isNameValid(name.c_str())) 44 | this->name = name; 45 | } 46 | void Drink::setMl(int ml) 47 | { 48 | const int MAX_ML = 1000; 49 | const int MIN_ML = 100; 50 | 51 | ml = MIN_ML; 52 | if (MIN_ML <= ml && ml <= MAX_ML) 53 | this->ml = ml; 54 | 55 | } 56 | 57 | Drink::Drink(const MyString& name, int ml) 58 | { 59 | setName(name); 60 | setMl(ml); 61 | } 62 | 63 | -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/task1-read.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | struct Student 7 | { 8 | char name[30]; 9 | int age; 10 | int fn; 11 | }; 12 | 13 | size_t getFileSize(ifstream& f) 14 | { 15 | size_t currentPos = f.tellg(); 16 | f.seekg(0, ios::end); 17 | size_t size = f.tellg(); 18 | 19 | f.seekg(currentPos); 20 | return size; 21 | } 22 | 23 | void readFromFile(Student*& ptr, size_t& studentsCount, ifstream& f) 24 | { 25 | size_t sizeOfFile = getFileSize(f); 26 | studentsCount = sizeOfFile / sizeof(Student); 27 | ptr = new Student[studentsCount]; 28 | f.read((char*)ptr, sizeOfFile); 29 | } 30 | 31 | int main() 32 | { 33 | Student* arr; 34 | size_t count; 35 | ifstream file("students.dat"); 36 | 37 | if(!file.is_open()) 38 | { 39 | std::cout << "Error while opening the file!" << std::endl; 40 | return -1; 41 | } 42 | 43 | readFromFile(arr, count, file); 44 | 45 | for (int i = 0; i < count; i++) 46 | std::cout << "Name: " << arr[i].name << ", age: " << arr[i].age << ", fn: " << arr[i].fn << std::endl; 47 | 48 | delete[] arr; 49 | 50 | return 0; 51 | } 52 | -------------------------------------------------------------------------------- /Seminars/Sem.07/Solution/Complex/ComplexNum.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class ComplexNum 5 | { 6 | private: 7 | double real; 8 | double imaginary; 9 | public: 10 | ComplexNum(); 11 | ComplexNum(double real, double imaginary); 12 | 13 | ComplexNum(const ComplexNum& other) = default; 14 | ComplexNum& operator=(const ComplexNum& other) = default; 15 | ~ComplexNum() = default; 16 | 17 | ComplexNum getConjugated() const; 18 | 19 | ComplexNum& operator+=(const ComplexNum& other); 20 | ComplexNum& operator-=(const ComplexNum& other); 21 | ComplexNum& operator*=(const ComplexNum& other); 22 | ComplexNum& operator/=(const ComplexNum& other); 23 | 24 | friend ComplexNum operator+(const ComplexNum& lhs, const ComplexNum& rhs); 25 | friend ComplexNum operator-(const ComplexNum& lhs, const ComplexNum& rhs); 26 | friend ComplexNum operator*(const ComplexNum& lhs, const ComplexNum& rhs) ; 27 | friend ComplexNum operator/(const ComplexNum& lhs, const ComplexNum& rhs); 28 | 29 | friend std::ostream& operator<<(std::ostream& os, const ComplexNum& complexNum); 30 | friend std::istream& operator>>(std::istream& is, ComplexNum& complexNum); 31 | }; 32 | -------------------------------------------------------------------------------- /Seminars/Utils/Tasks/Task02/BusStation.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Bus.h" 3 | #include "Trip.h" 4 | 5 | const unsigned MAX_BUSSES_COUNT = 30; 6 | 7 | class BusStation 8 | { 9 | Bus busses[MAX_BUSSES_COUNT]; 10 | unsigned bussesCount; 11 | Trip* trips; 12 | unsigned tripsCount; 13 | unsigned tripsCapacity; 14 | 15 | void copyFrom(const BusStation& other); 16 | void copyBusses(const Bus* b, unsigned count); 17 | void copyTrips(const Trip* t, unsigned count, unsigned capacity); 18 | void free(); 19 | void resize(unsigned newCapacity); 20 | 21 | int findTripWithDestination(const char* dest) const; 22 | int findFreeBus() const; 23 | int findBusById(unsigned id) const; 24 | 25 | public: 26 | BusStation(); 27 | BusStation(const BusStation& other); 28 | BusStation& operator=(const BusStation& other); 29 | ~BusStation(); 30 | 31 | bool doesPassengerHaveSeat(const char* name, const Trip& trip) const; 32 | bool addPassenger(const Passenger& passenger, const char* dest); 33 | 34 | void busArrives(unsigned id); 35 | 36 | bool addBus(const Bus& bus); 37 | bool addTrip(const char* dest); 38 | 39 | unsigned getTotalProfit() const; 40 | void printCurrentBusses() const; 41 | }; -------------------------------------------------------------------------------- /Seminars/Sem.05/Pract. 05/Task04/Dates.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Date 4 | { 5 | private: 6 | int days, month, year; 7 | public: 8 | Date(); //Default to 01.01.2000; 9 | Date(const int,const int,const int); //Constructor dd/mm/yy 10 | 11 | //Accessors 12 | int getDays() const; 13 | int getMonth() const; 14 | int getYear() const; 15 | 16 | void addDays(const int); //Add N days to the Date 17 | void removeDays(const int); //Substract N days from the Date 18 | 19 | bool isLeapYear() const; //Check if it is leap year 20 | bool isEarlierThan(const Date&) const; //True if given Date is after our Date 21 | 22 | long long daysToXmas() const; 23 | long long daysToNewYear() const; 24 | long long daysBetweenDates(const Date&) const; 25 | 26 | void print() const; //Display Date/Print Date 27 | private: 28 | int isLeap(int) const;//Check if year is Leap 29 | int NumDaysInMonth(int, int) const; //Calculates number of days in current month 30 | long long sumOfDays(const Date&) const;//Extract total sum of days from a specific Date 31 | }; 32 | -------------------------------------------------------------------------------- /Seminars/Sem.14/Pract. 14/Bar/MyString/MyString.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | class MyString 5 | { 6 | char* str; 7 | size_t size; 8 | 9 | void copyFrom(const MyString& other); 10 | void free(); 11 | 12 | void concatFrom(const MyString& other); 13 | 14 | public: 15 | MyString(); 16 | MyString(const char*); 17 | MyString(size_t n); //convert constructor 18 | 19 | MyString(const MyString&); 20 | 21 | MyString(MyString&&); //move constructor that accepts rvalue; 22 | 23 | MyString& operator=(const MyString& other); 24 | MyString& operator=(MyString&& other); //move op= that accepts rvalue; 25 | 26 | ~MyString(); 27 | 28 | size_t getSize() const; 29 | 30 | const char* c_str() const; 31 | 32 | MyString& operator+=(const MyString& other); 33 | 34 | friend std::ostream& operator<<(std::ostream& stream, const MyString& str); 35 | friend std::istream& operator>>(std::istream& stream, MyString& str); 36 | 37 | }; 38 | 39 | MyString operator+(const MyString& lhs, const MyString& rhs); 40 | 41 | bool operator==(const MyString& lhs, const MyString& rhs); 42 | bool operator<=(const MyString& lhs, const MyString& rhs); 43 | bool operator<(const MyString& lhs, const MyString& rhs); 44 | -------------------------------------------------------------------------------- /Seminars/Sem.01/Bonus/StableCountingSort.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void StableCountingSort(char* arr, size_t length) 5 | { 6 | size_t arrLength = strlen(arr); 7 | char* copy = new char[arrLength]; 8 | // copy the original 9 | for (size_t i = 0; i < arrLength; i++) { 10 | copy[i] = arr[i]; 11 | } 12 | 13 | int counter[256] = { 0 }; 14 | // count every char 15 | for (size_t i = 0; i < length; i++) { 16 | counter[arr[i]]++; 17 | } 18 | 19 | // the counter will become the index where the next element 20 | // of every different type should be placed 21 | for (size_t i = 1; i < 256; i++) { 22 | counter[i] += counter[i - 1]; 23 | } 24 | 25 | // put the characters in the initial array sorted 26 | // started backwards so that the sorting is stable 27 | for (int i = arrLength - 1; i >= 0; i--) { 28 | // counter[copy[i] - 1 => where the element should be placed 29 | arr[counter[copy[i]] - 1] = copy[i]; 30 | // the next element of this type should be placed one index behind this one 31 | --counter[copy[i]]; 32 | } 33 | 34 | delete[] copy; 35 | } 36 | 37 | int main() 38 | { 39 | char arr[] = "ababababababa"; 40 | StableCountingSort(arr, 13); 41 | std::cout << arr; 42 | } 43 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_polymorphism/Shape.cpp: -------------------------------------------------------------------------------- 1 | #include "Shape.h" 2 | 3 | Shape::Shape(size_t pointsCount) : pointsCount(pointsCount) 4 | { 5 | points = new point[pointsCount]; // [0,0], [0,0].... 6 | } 7 | 8 | void Shape::copyFrom(const Shape& other) 9 | { 10 | points = new point[other.pointsCount]; 11 | 12 | for (int i = 0; i < other.pointsCount; i++) 13 | points[i] = other.points[i]; 14 | 15 | pointsCount = other.pointsCount; 16 | } 17 | void Shape::free() 18 | { 19 | delete[] points; 20 | } 21 | 22 | Shape::Shape(const Shape& other) 23 | { 24 | copyFrom(other); 25 | } 26 | Shape& Shape::operator= (const Shape& other) 27 | { 28 | if (this != &other) 29 | { 30 | free(); 31 | copyFrom(other); 32 | } 33 | return *this; 34 | } 35 | Shape::~Shape() 36 | { 37 | free(); 38 | } 39 | 40 | const Shape::point& Shape::getPointAtIndex(size_t index) const 41 | { 42 | if (index >= pointsCount) 43 | throw std::exception("Invalid point index!"); 44 | 45 | return points[index]; 46 | } 47 | 48 | void Shape::setPoint(size_t pointIndex, int x, int y) 49 | { 50 | if (pointIndex >= pointsCount) 51 | throw std::exception("Invalid point index!"); 52 | 53 | points[pointIndex] = point(x, y); 54 | } 55 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Shapes/cpp/Shape.cpp: -------------------------------------------------------------------------------- 1 | #include "Shape.h" 2 | 3 | const Shape::point& Shape::GetPointAtIndex(size_t index) const 4 | { 5 | if (index >= pointsCount) { 6 | throw std::out_of_range("Invalid index!"); 7 | } 8 | 9 | return points[index]; 10 | } 11 | 12 | void Shape::SetPoint(size_t pointIndex, int x, int y) 13 | { 14 | if (pointIndex >= pointsCount) { 15 | throw std::out_of_range("Invalid index!"); 16 | } 17 | 18 | points[pointIndex] = point(x, y); 19 | } 20 | 21 | Shape::Shape(size_t pointsCount) : pointsCount(pointsCount) { 22 | points = new point[pointsCount]; // [0,0], [0,0].... 23 | } 24 | 25 | Shape::Shape(const Shape& other) { 26 | copyFrom(other); 27 | } 28 | 29 | Shape& Shape::operator= (const Shape& other) { 30 | if (this != &other) 31 | { 32 | Free(); 33 | CopyFrom(other); 34 | } 35 | return *this; 36 | } 37 | 38 | Shape::~Shape() { 39 | Free(); 40 | } 41 | 42 | void Shape::CopyFrom(const Shape& other) { 43 | points = new point[other.pointsCount]; 44 | 45 | for (size_t i = 0; i < other.pointsCount; ++i) { 46 | points[i] = other.points[i]; 47 | } 48 | 49 | pointsCount = other.pointsCount; 50 | } 51 | 52 | void Shape::Free() { 53 | delete[] points; 54 | } 55 | -------------------------------------------------------------------------------- /Seminars/Sem.12/Solutions/Shapes/cpp/Shape.cpp: -------------------------------------------------------------------------------- 1 | #include "Shape.h" 2 | 3 | const Shape::point& Shape::GetPointAtIndex(size_t index) const 4 | { 5 | if (index >= pointsCount) { 6 | throw std::out_of_range("Invalid index!"); 7 | } 8 | 9 | return points[index]; 10 | } 11 | 12 | void Shape::SetPoint(size_t pointIndex, int x, int y) 13 | { 14 | if (pointIndex >= pointsCount) { 15 | throw std::out_of_range("Invalid index!"); 16 | } 17 | 18 | points[pointIndex] = point(x, y); 19 | } 20 | 21 | Shape::Shape(size_t pointsCount) : pointsCount(pointsCount) { 22 | points = new point[pointsCount]; // [0,0], [0,0].... 23 | } 24 | 25 | Shape::Shape(const Shape& other) { 26 | copyFrom(other); 27 | } 28 | 29 | Shape& Shape::operator= (const Shape& other) { 30 | if (this != &other) 31 | { 32 | Free(); 33 | CopyFrom(other); 34 | } 35 | return *this; 36 | } 37 | 38 | Shape::~Shape() { 39 | Free(); 40 | } 41 | 42 | void Shape::CopyFrom(const Shape& other) { 43 | points = new point[other.pointsCount]; 44 | 45 | for (size_t i = 0; i < other.pointsCount; ++i) { 46 | points[i] = other.points[i]; 47 | } 48 | 49 | pointsCount = other.pointsCount; 50 | } 51 | 52 | void Shape::Free() { 53 | delete[] points; 54 | } 55 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_mutualCatching/Shape.cpp: -------------------------------------------------------------------------------- 1 | #include "Shape.h" 2 | 3 | Shape::Shape(size_t pointsCount) : pointsCount(pointsCount) 4 | { 5 | points = new point[pointsCount]; // [0,0], [0,0].... 6 | } 7 | 8 | void Shape::copyFrom(const Shape& other) 9 | { 10 | points = new point[other.pointsCount]; 11 | 12 | for (int i = 0; i < other.pointsCount; i++) 13 | points[i] = other.points[i]; 14 | 15 | pointsCount = other.pointsCount; 16 | } 17 | void Shape::free() 18 | { 19 | delete[] points; 20 | } 21 | 22 | Shape::Shape(const Shape& other) 23 | { 24 | copyFrom(other); 25 | } 26 | Shape& Shape::operator= (const Shape& other) 27 | { 28 | if (this != &other) 29 | { 30 | free(); 31 | copyFrom(other); 32 | } 33 | return *this; 34 | } 35 | Shape::~Shape() 36 | { 37 | free(); 38 | } 39 | 40 | const Shape::point& Shape::getPointAtIndex(size_t index) const 41 | { 42 | if (index >= pointsCount) 43 | throw std::exception("Invalid point index!"); 44 | 45 | return points[index]; 46 | } 47 | 48 | void Shape::setPoint(size_t pointIndex, int x, int y) 49 | { 50 | if (pointIndex >= pointsCount) 51 | throw std::exception("Invalid point index!"); 52 | 53 | points[pointIndex] = point(x, y); 54 | } 55 | -------------------------------------------------------------------------------- /Seminars/Sem.09/Solutions/String/String.cpp: -------------------------------------------------------------------------------- 1 | #include "String.hpp" 2 | #include 3 | #include 4 | 5 | #pragma warning(disable:4996) 6 | 7 | String::String(const char* data) { 8 | printf("Constr with param\n"); 9 | 10 | this->data = new char[strlen(data) + 1]; 11 | strcpy(this->data, data); 12 | } 13 | 14 | String::String(const String& other) { 15 | printf("Copy constr\n"); 16 | 17 | 18 | CopyFrom(other); 19 | } 20 | String& String::operator=(const String& other) { 21 | printf("Copy assignment\n"); 22 | 23 | if (this != &other) { 24 | Free(); 25 | CopyFrom(other); 26 | } 27 | 28 | return *this; 29 | } 30 | String::~String() { 31 | Free(); 32 | } 33 | 34 | void String::Print() const { 35 | std::cout << data << std::endl; 36 | } 37 | 38 | void String::CopyFrom(const String& other) { 39 | this->data = new char[strlen(other.data) + 1]; 40 | strcpy(data, other.data); 41 | } 42 | void String::Free() { 43 | delete[] data; 44 | } 45 | 46 | String::String(String&& other) { 47 | data = other.data; 48 | 49 | other.data = nullptr; 50 | } 51 | 52 | String& String::operator=(String&& other) { 53 | if (this != &other) { 54 | Free(); 55 | 56 | data = other.data; 57 | other.data = nullptr; 58 | } 59 | } -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/HexViewer/cpp/fileOperations.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../fileOperations.h" 4 | 5 | using namespace std; 6 | 7 | bool readFile(File& file) { 8 | ifstream inputFile(file.name, ios::binary); 9 | 10 | if (!inputFile.is_open()) 11 | { 12 | cout << OPEN_FILE_ERROR_MESSAGE << endl; 13 | return false; 14 | } 15 | 16 | int size = getFileSize(inputFile); 17 | file.size = size; 18 | 19 | int index = 0; 20 | while (!inputFile.eof()) 21 | { 22 | inputFile.read((char*)&file.data[index++], sizeof(char)); 23 | } 24 | 25 | inputFile.close(); 26 | return true; 27 | } 28 | 29 | int getFileSize(std::ifstream& file) { 30 | int current = file.tellg(); 31 | file.seekg(0, ios::end); 32 | int size = file.tellg(); 33 | file.seekg(current, ios::beg); 34 | 35 | return size; 36 | } 37 | 38 | bool saveToFile(const File& file, const char* fileName) { 39 | ofstream outputFile(fileName); 40 | 41 | if (!outputFile.is_open()) 42 | { 43 | cout << OPEN_FILE_ERROR_MESSAGE << endl; 44 | return false; 45 | } 46 | 47 | for (size_t i = 0; i < file.size; i++) 48 | { 49 | outputFile.write((char*)&file.data[i], sizeof(char)); 50 | } 51 | 52 | outputFile.close(); 53 | return true; 54 | } -------------------------------------------------------------------------------- /Seminars/Sem.13/README.md: -------------------------------------------------------------------------------- 1 | ## Шаблони 2 | Функция/клас, която работи не с променливи от някакъв дефиниран тип, а с абстрактни променливи, се нарича шаблонна функция/клас 3 | ```c++ 4 | #include 5 | using namespace std; 6 | 7 | template 8 | T sum(const T& a, const T& b) { 9 | return a + b; 10 | } 11 | 12 | int main() { 13 | int a = 4; 14 | int b = 9; 15 | std::cout << sum(a, b) << std::endl; 16 | 17 | double c = 3.14; 18 | double d = 4.5; 19 | std::cout << sum(c,d) << std::endl; 20 | 21 | return 0; 22 | } 23 | ``` 24 | Компилаторът генерира т. нар. шаблонна функция, като замества параметрите на шаблона с типовете на съответните фактически параметри. 25 | 26 | **Задача:** 27 | Релизирайте структурата от данни FixedLengthStack
28 | 29 | **Пример**: 30 | ```c++ 31 | int main() { 32 | FixedLengthStack st; 33 | 34 | for(size_t i = 0; i < 5; ++i) { // if i < 6 it should throw an error 35 | st.push(i); 36 | } 37 | 38 | Stack st1 = st; 39 | Stack st2; 40 | st2 = st1; 41 | Stack st3 = std::move(st1); 42 | 43 | while (!st2.empty()) { 44 | std::cout << st2.pop() << ' '; 45 | } 46 | std::cout << std::endl; 47 | return 0; 48 | } 49 | ``` 50 | -------------------------------------------------------------------------------- /Seminars/Sem.02/Solutions/Examples/01-console.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void NewLineError() 4 | { 5 | int a; 6 | std::cin >> a; 7 | 8 | char arr[10]; 9 | //std::cin >> arr; 10 | //std::cin.ignore(); 11 | std::cin.getline(arr, 10); 12 | 13 | std::cout << a << " " << arr; 14 | } 15 | 16 | void InfiniteLoop() 17 | { 18 | char c; 19 | std::cin.putback('a'); 20 | while (std::cin >> c) { 21 | std::cout << c; 22 | std::cin.putback(c); 23 | } 24 | } 25 | 26 | void GetAndPutbackExamples() 27 | { 28 | { 29 | //Example 1 - get function 30 | char ch1, ch2; 31 | std::cin.get(ch1); 32 | std::cin.get(ch2); 33 | std::cout << ch1 << " " << ch2 << std::endl; 34 | } 35 | 36 | { 37 | //Example 2 - putback 38 | char c; 39 | std::cin.putback('a'); 40 | std::cin.get(c); 41 | std::cout << c; 42 | } 43 | 44 | { 45 | // Above stream buffer is not cleared 46 | std::cin.clear(); // clear stream buffer for last example 47 | char ch1, ch2; 48 | ch1 = std::cin.peek(); 49 | std::cin.get(ch2); 50 | std::cin.putback('d'); 51 | std::cin.get(ch2); 52 | } 53 | } 54 | 55 | void ReadExample() 56 | { 57 | char c; 58 | std::cin.putback('a').putback('b'); 59 | char info[3] = { '\0' }; 60 | std::cin.read(info, 2); 61 | std::cout << info; 62 | } -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_mutualCatching/Shape.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | 5 | class Triangle; 6 | class Rectangle; 7 | class Circle; 8 | 9 | class Shape // Abstract class - no instances of Shape are allowed! 10 | { 11 | protected: 12 | struct point 13 | { 14 | point() :x(0), y(0){} 15 | point(int x, int y) :x(x), y(y){} 16 | int x; 17 | int y; 18 | double getDist(const point& other) const 19 | { 20 | int dx = x - other.x; 21 | int dy = y - other.y; 22 | 23 | return sqrt(dx*dx + dy*dy); 24 | } 25 | }; 26 | const point& getPointAtIndex(size_t index) const; 27 | private: 28 | point* points; 29 | size_t pointsCount; 30 | 31 | void copyFrom(const Shape& other); 32 | void free(); 33 | 34 | 35 | public: 36 | Shape(size_t pointsCount); 37 | 38 | Shape(const Shape& other); 39 | Shape& operator=(const Shape& other); 40 | virtual ~Shape(); //!!!!!! 41 | 42 | void setPoint(size_t pointIndex, int x, int y); 43 | 44 | 45 | virtual bool intersectsWith(const Shape* other) const = 0; 46 | 47 | virtual bool intersectsWithTriangle(const Triangle* other) const = 0; 48 | virtual bool intersectsWithRect(const Rectangle* other) const = 0; 49 | virtual bool intersectsWithCircle(const Circle* other) const = 0; 50 | }; -------------------------------------------------------------------------------- /Seminars/Sem.07/Solution/NVector/NVector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class NVector { 5 | private: 6 | int* data = nullptr; 7 | size_t size = 0; 8 | public: 9 | NVector() = delete; 10 | NVector(size_t); 11 | NVector(const NVector&); 12 | NVector& operator=(const NVector&); 13 | ~NVector(); 14 | 15 | int operator[](size_t) const; 16 | int& operator[](size_t); 17 | 18 | NVector& operator+=(const NVector&); 19 | NVector& operator-=(const NVector&); 20 | NVector& operator*=(size_t); 21 | 22 | size_t GetSize() const; 23 | //size_t operator~() const; // return size 24 | 25 | void Print() const; 26 | 27 | friend bool IsParralel(const NVector&, const NVector&); 28 | friend bool IsPerpendicular(const NVector&, const NVector&); 29 | 30 | friend std::ostream& operator<<(std::ostream& os, const NVector&); 31 | friend std::istream& operator>>(std::istream& in, NVector&); 32 | private: 33 | void CopyFrom(const NVector&); 34 | void Free(); 35 | }; 36 | 37 | NVector operator+(const NVector&, const NVector&); 38 | NVector operator-(const NVector&, const NVector&); 39 | NVector operator*(size_t, const NVector&); 40 | NVector operator*(const NVector&, size_t); 41 | 42 | //bool operator||(const NVector&, const NVector&); 43 | //bool operator|=(const NVector&, const NVector&); -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/Intersection.cpp: -------------------------------------------------------------------------------- 1 | #include "Intersection.h" 2 | 3 | Intersection::Intersection(Collection& left, Collection& right) : 4 | CollectionOperation(left, right) {} 5 | 6 | // Добавяме към по - малкия 7 | // Ако са равен брой добавяме и към двете 8 | void Intersection::add(int elem) 9 | { 10 | int lCount = left.count(elem); 11 | int rCount = right.count(elem); 12 | 13 | if (lCount > rCount) 14 | { 15 | right.add(elem); 16 | } 17 | else 18 | { 19 | left.add(elem); 20 | 21 | if (lCount == rCount) 22 | { 23 | right.add(elem); 24 | } 25 | } 26 | 27 | } 28 | 29 | // Аналогично с добавянето 30 | void Intersection::remove(int elem) 31 | { 32 | int lCount = left.count(elem); 33 | int rCount = right.count(elem); 34 | 35 | if (lCount > rCount) 36 | { 37 | right.remove(elem); 38 | } 39 | else 40 | { 41 | left.remove(elem); 42 | 43 | if (lCount == rCount) 44 | { 45 | right.remove(elem); 46 | } 47 | } 48 | } 49 | 50 | unsigned Intersection::count(int elem) const 51 | { 52 | int lCount = left.count(elem); 53 | int rCount = right.count(elem); 54 | return lCount < rCount ? lCount : rCount; 55 | } 56 | 57 | bool Intersection::contains(int elem) const 58 | { 59 | return left.contains(elem) && right.contains(elem); 60 | } 61 | -------------------------------------------------------------------------------- /Seminars/Sem.15/Solutions/Design-Patterns/Structural Patterns/README.md: -------------------------------------------------------------------------------- 1 | ## Structural 2 | 3 | Отнасят се към това как класове и обекти са композирани, за да образуват по-голяма структура. Улесняват структурата като задават връзка между самите класове 4 | 5 | - **Adapter** – позволя несъвместими интерфейси да работят заедно. Parse-ва данните от едно състояние в друго, което ни е нужно (irl пример – адаптер, че от usb към нещо друго, програма връща json, но друга иска xml => json to xml parser) 6 | - Плюсове 7 | - Single responsibity – отделяш парсването между двата интерфейса от бизнес логиката и адаптерът се грижи само за нея; 8 | - Open/Closed – можеш лесно да добавяш нови адаптери; 9 | - Минуси 10 | - Увеличава се сложността на кода – нови интерфейси и класове; 11 | - **Facade** – предоставя опростен интерфейс към библиотекта или комплексен набор от класове 12 | - Плюсове 13 | - Изолира комплексен код; 14 | - Минуси 15 | - Може да се превърне в [God Object](https://en.wikipedia.org/wiki/God_object); 16 | 17 | In general е добре да се знае и за: 18 | - **Decorator** - добавя някакво поведение към вече съществуващ обект. Постига се като обектът се поставя в друг "wrapper object", който държи добавеното поведение. 19 | - **Strategy** 20 | - **Flyweight** 21 | - **Proxy** -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/Source.cpp: -------------------------------------------------------------------------------- 1 | #include"SortedCollection.h" 2 | #include 3 | #include"IntervalCollection.h" 4 | #include"NormalCollection.h" 5 | #include"Union.h" 6 | #include"Intersection.h" 7 | 8 | 9 | // c1 = [1, 4, 10, 3, 2, 0] - normal 10 | // c2 = [1, 11, 14] - interval[0, 16] 11 | // c3 = [3, 4, 4, 5, 14, 0] - sorted 12 | // 13 | // c = (c1 u c2) ^ c3 = [0, 3, 4, 14] 14 | int main() 15 | { 16 | Collection* c1 = new NormalCollection(); 17 | c1->add(1); 18 | c1->add(4); 19 | c1->add(10); 20 | c1->add(3); 21 | c1->add(2); 22 | c1->add(0); 23 | 24 | 25 | Collection* c2 = new IntervalCollection(0, 16); 26 | c2->add(1); 27 | c2->add(11); 28 | c2->add(14); 29 | c2->add(0); 30 | 31 | Collection* c3 = new SortedCollection(); 32 | c3->add(5); 33 | c3->add(4); 34 | c3->add(4); 35 | c3->add(14); 36 | c3->add(0); 37 | c3->add(3); 38 | 39 | Collection* leftUnion = new Union(*c1, *c2); 40 | Collection* intersect = new Intersection(*leftUnion, *c3); 41 | 42 | for (size_t i = 0; i < 16; i++) 43 | { 44 | size_t count = intersect->count(i); 45 | 46 | for (size_t j = 0; j < count; j++) 47 | { 48 | std::cout << i << " "; 49 | } 50 | } 51 | 52 | delete c1; 53 | delete c2; 54 | delete c3; 55 | delete leftUnion; 56 | delete intersect; 57 | } 58 | -------------------------------------------------------------------------------- /Seminars/Sem.15/Solutions/Design-Patterns/Behavioral Patterns/README.md: -------------------------------------------------------------------------------- 1 | ## Behavioral 2 | Улесняват комункацията между обекти 3 | 4 | - **Observer** – предоставя механизъм за закачане на обекти към обект, така че да получава информация за event-и, които се случват на обекта (notify за промяна, изтриване и т.н.) 5 | Терминология: 6 | Observable - обектът, който се наблюдава; 7 | Observer - обект, който наблюдава Observable; 8 | - Плюсове 9 | - Лесно могат да се добавят нов тип Observer-и 10 | - Runtime връзка между обекти; 11 | - Минуси 12 | - Memory leak, ако не се използва правилно (High level languages); 13 | 14 | - **Command** – използва обект за да капсулира цялата логика за изпълнение на дадено действие 15 | - Плюсове 16 | - Single Responsibility 17 | - Open/Closed 18 | - Минуси 19 | - Нов layer в приложението 20 | 21 | In general е добре да се знае и за 22 | - **Iterator** - позволява да се обхожда колекция без да се знае от какъв тип е тя 23 | - **Chain of Responsibility** - при дадена заявка трабвя да минеш по верига от n на брой handler-и, които си комуникират само със следващият, като се грижат да подадат данните към следващия в правилен вид. При грешка не се продължава напред по веригата. 24 | - **Mediator** 25 | - **Strategy** 26 | - **State** 27 | - **Visitor** 28 | -------------------------------------------------------------------------------- /Seminars/Sem.06/Solutions/Person/Person.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Person.h" 3 | #include 4 | #include 5 | 6 | Person::Person(const char* name, int age) { 7 | setName(name); 8 | setAge(age); 9 | } 10 | 11 | Person::Person(const Person& other) { 12 | CopyFrom(other); 13 | } 14 | 15 | Person& Person::operator=(const Person& other) { 16 | if (this != &other) { 17 | Free(); 18 | CopyFrom(other); 19 | } 20 | return *this; 21 | } 22 | 23 | Person::~Person() { 24 | Free(); 25 | } 26 | 27 | const char* Person::getName() const { 28 | return name; 29 | } 30 | 31 | int Person::getAge() const { 32 | return age; 33 | } 34 | 35 | void Person::setName(const char* name) { 36 | if (name == nullptr || this->name == name) { 37 | return; 38 | } 39 | 40 | delete[] this->name; 41 | size_t nameLen = strlen(name); 42 | this->name = new char[nameLen + 1]; 43 | strcpy(this->name, name); 44 | } 45 | 46 | void Person::setAge(int age) { 47 | this->age = age; 48 | } 49 | 50 | void Person::print() const { 51 | std::cout << name << " " << age << std::endl; 52 | } 53 | 54 | void Person::CopyFrom(const Person& other) { 55 | name = new char[strlen(other.name) + 1]; 56 | strcpy(name, other.name); 57 | age = other.age; 58 | } 59 | 60 | void Person::Free() { 61 | delete[] name; 62 | } 63 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_polymorphism/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | #include "Rectangle.h" 5 | #include "Circle.h" 6 | #include "Triangle.h" 7 | 8 | 9 | void printAreas(const Shape* const * shapes, size_t shapesCount) 10 | { 11 | for (int i = 0; i < shapesCount; i++) 12 | cout << shapes[i]->getArea() <getPer() << endl; 18 | } 19 | 20 | void checkPointIn(const Shape* const* shapes, size_t shapesCount, int x, int y) 21 | { 22 | for (int i = 0; i < shapesCount; i++) 23 | cout << shapes[i]->isPointIn(x,y) << endl; 24 | } 25 | 26 | void freeCollection(Shape** shapes, size_t shapesCount) 27 | { 28 | for (int i = 0; i < shapesCount; i++) 29 | delete shapes[i]; 30 | delete[] shapes; 31 | } 32 | 33 | int main() 34 | { 35 | Shape** arr = new Shape*[4]; 36 | 37 | arr[0] = new Rectangle(3, 4, 6, 8); 38 | arr[1] = new Circle(3, 3, 4); 39 | arr[2] = new Circle(1, 4, 5); 40 | arr[3] = new Triangle(1, 1, 2, 2, 3, 3); 41 | 42 | printAreas(arr, 4); 43 | std::cout << endl; 44 | printPers(arr, 4); 45 | std::cout << endl; 46 | 47 | checkPointIn(arr, 4, 3, 3); 48 | 49 | 50 | freeCollection(arr, 4); 51 | 52 | } 53 | -------------------------------------------------------------------------------- /Seminars/Sem.14/Pract. 14/Bar/Bar/Bar.cpp: -------------------------------------------------------------------------------- 1 | #include "Bar.h" 2 | 3 | void Bar::addAlcoholDrink(const AlcoholDrink& dr, size_t count) 4 | { 5 | if (count > 0) 6 | alcoholDrinks.push(Pair(dr, count)); 7 | } 8 | void Bar::addDrink(const Drink& dr, size_t count) 9 | { 10 | if (count > 0) 11 | drinks.push(Pair(dr, count)); 12 | } 13 | 14 | Drink Bar::getDrink() 15 | { 16 | 17 | if (drinks.isEmpty()) 18 | throw std::logic_error("Empty drinks collection"); 19 | 20 | Drink toReturn = drinks.peek().getFirst(); 21 | 22 | stats.mlSold += toReturn.getMl(); 23 | stats.soldDrinks++; 24 | 25 | drinks.peek().setSecond(drinks.peek().getSecond() - 1); 26 | if (drinks.peek().getSecond() == 0) 27 | drinks.pop(); 28 | 29 | return toReturn; 30 | } 31 | 32 | AlcoholDrink Bar::getAlcDrink() 33 | { 34 | if (alcoholDrinks.isEmpty()) 35 | throw std::logic_error("Empty alc. drinks collection"); 36 | 37 | AlcoholDrink toReturn = alcoholDrinks.peek().getFirst(); 38 | 39 | stats.mlSold += toReturn.getMl(); 40 | stats.soldAlcoholDrinks++; 41 | 42 | alcoholDrinks.peek().setSecond(alcoholDrinks.peek().getSecond() - 1); 43 | if (alcoholDrinks.peek().getSecond() == 0) 44 | alcoholDrinks.pop(); 45 | 46 | return toReturn; 47 | 48 | } 49 | 50 | const Bar::Statistics& Bar::getStats() const 51 | { 52 | return stats; 53 | } -------------------------------------------------------------------------------- /Seminars/Sem.05/Solutions/Event/Event.cpp: -------------------------------------------------------------------------------- 1 | #include "Event.h" 2 | #pragma warning(disable : 4996) 3 | 4 | Event::Event() : Event("", 1, 1, 1, 0, 0, 0, 0, 0, 0) {} 5 | 6 | Event::Event(const char* name, const Date& date, const Time& startTime, const Time& endTime) : date(date), startTime(startTime), endTime(endTime) { 7 | setName(name); 8 | validateTimes(); 9 | } 10 | 11 | Event::Event(const char* name, unsigned day, unsigned month, unsigned year, 12 | unsigned startTimeHours, unsigned startTimeMins, unsigned startTimeSecs, 13 | unsigned endTimeHours, unsigned endTimeMins, unsigned endTimeSecs) 14 | : date(day, month, year), 15 | startTime(startTimeHours, startTimeMins, startTimeSecs), 16 | endTime(endTimeHours, endTimeMins, endTimeSecs) { 17 | setName(name); 18 | validateTimes(); 19 | } 20 | 21 | const char* Event::getName() const { 22 | return name; 23 | } 24 | 25 | const Date& Event::getDate() const { 26 | return date; 27 | } 28 | 29 | const Time& Event::getStartTime() const { 30 | return startTime; 31 | } 32 | 33 | const Time& Event::getEndTime() const { 34 | return endTime; 35 | } 36 | 37 | void Event::setName(const char* str) { 38 | if (strlen(str) > 20) return; 39 | else strcpy(name, str); 40 | } 41 | 42 | void Event::validateTimes() { 43 | if (_startTime.compare(_endTime) >= 1) 44 | std::swap(_startTime, _endTime); 45 | } -------------------------------------------------------------------------------- /Seminars/Utils/TheoryExamples/Sorting.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void swap(int& a, int& b) { 4 | int temp = a; 5 | a = b; 6 | b = temp; 7 | } 8 | 9 | void print(const int* arr, size_t length) { 10 | for (size_t i = 0; i < length; i++) { 11 | std::cout << arr[i] << " "; 12 | } 13 | } 14 | 15 | void bubbleSort(int* arr, size_t length) { 16 | for (size_t i = 0; i < length - 1; i++) { 17 | bool hasSwaps = false; 18 | 19 | // last i numbers are already ordered 20 | for (size_t j = 0; j < length - i - 1; j++) { 21 | if (arr[j] > arr[j + 1]) { 22 | swap(arr[j], arr[j + 1]); 23 | hasSwaps = true; 24 | } 25 | } 26 | 27 | if (!hasSwaps) {// if no swaps were made - array is ordered 28 | break; 29 | } 30 | } 31 | } 32 | 33 | void selectionSort(int* arr, size_t length) { 34 | for (size_t i = 0; i < length - 1; i++) { 35 | size_t minIndex = i; 36 | 37 | // first i numbers are already ordered 38 | for (size_t j = i + 1; j < length; j++) { 39 | if (arr[minIndex] > arr[j]) { 40 | minIndex = j; 41 | } 42 | } 43 | 44 | if (minIndex != i) { // if minIndex changed - swap 45 | swap(arr[i], arr[minIndex]); 46 | } 47 | } 48 | } 49 | 50 | int main1() { 51 | int arr[] = { 9, 5, 6, 3, 4, 7, 2, 1, 8 }; 52 | 53 | selectionSort(arr, 9); // not stable 54 | bubbleSort(arr, 9); // stable 55 | print(arr, 9); 56 | return 0; 57 | } -------------------------------------------------------------------------------- /Seminars/Sem.04/Pract.04/Task03/main.cpp: -------------------------------------------------------------------------------- 1 | // Solution by Venelina & Manoela 2 | 3 | #include "GamePlatform.h" 4 | #include 5 | 6 | int main() 7 | { 8 | Game games[] = { 9 | Game("game1", 14.40, true), 10 | Game("game2", 0, false) 11 | }; 12 | 13 | GamePlatform gamePlatform(games, 2); 14 | 15 | Game game1("game3", 12.45, false); 16 | Game game2("game4", 13.45, true); 17 | 18 | std::cout << "All games are: " << std::endl; 19 | gamePlatform.PrintAllGames(); 20 | gamePlatform.AddGame(game1); 21 | gamePlatform.AddGame(game2); 22 | 23 | std::cout << "Added two more games: " << std::endl; 24 | gamePlatform.PrintAllGames(); 25 | 26 | std::cout << "Most expensive game is: " << std::endl; 27 | gamePlatform.ReturnMostExpensiveGame().Print(); 28 | 29 | std::cout << "All free games are: " << std::endl; 30 | gamePlatform.PrintAllFreeGames(); 31 | 32 | gamePlatform.RemoveGameFromLibrary(game1); 33 | 34 | std::cout << "Removed game3 from library." << std::endl; 35 | gamePlatform.PrintAllGames(); 36 | 37 | std::cout << "The game with index 1 is: " << std::endl; 38 | gamePlatform.GetGameByID(1).Print(); 39 | 40 | gamePlatform.WriteGamePlatformToFile(FILE_PATH); 41 | 42 | GamePlatform gamePlatform2; 43 | gamePlatform2.ReadGamePlatformFromFile(FILE_PATH); 44 | std::cout << "Games read from file: " << std::endl; 45 | gamePlatform2.PrintAllGames(); 46 | } -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/String/String.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class MyString { 6 | private: 7 | char* _data; 8 | size_t _length; 9 | 10 | void copyFrom(const MyString& data); 11 | void free(); 12 | 13 | explicit MyString(size_t capacity); //for memory allocation. How much bytes to allocate 14 | public: 15 | 16 | MyString(); 17 | MyString(const char* data); 18 | MyString(const MyString& other); 19 | MyString& operator=(const MyString& other); 20 | ~MyString(); 21 | 22 | size_t length() const; 23 | MyString& operator+=(const MyString& other); 24 | 25 | MyString substr(size_t begin, size_t howMany) const; 26 | 27 | char& operator[](size_t index); 28 | char operator[](size_t index) const; 29 | 30 | const char* c_str() const; 31 | 32 | friend MyString operator+(const MyString& lhs, const MyString& rhs); 33 | friend std::istream& operator>>(std::istream& is, MyString& str); 34 | }; 35 | 36 | std::ostream& operator<<(std::ostream& os, const MyString& str); 37 | 38 | bool operator<(const MyString& lhs, const MyString& rhs); 39 | bool operator<=(const MyString& lhs, const MyString& rhs); 40 | bool operator>=(const MyString& lhs, const MyString& rhs); 41 | bool operator>(const MyString& lhs, const MyString& rhs); 42 | bool operator==(const MyString& lhs, const MyString& rhs); 43 | bool operator!=(const MyString& lhs, const MyString& rhs); -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Shapes/cpp/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include "Rectangle.h" 4 | #include "Circle.h" 5 | #include "Triangle.h" 6 | 7 | 8 | void PrintAreas(const Shape* const * shapes, size_t shapesCount) { 9 | for (size_t i = 0; i < shapesCount; ++i) { 10 | std::cout << shapes[i]->getArea() << std::endl; 11 | } 12 | } 13 | 14 | void PrintPers(const Shape* const * shapes, size_t shapesCount) { 15 | for (size_t i = 0; i < shapesCount; ++i) { 16 | std::cout << shapes[i]->getPer() << std::endl; 17 | } 18 | } 19 | 20 | void CheckPointIn(const Shape* const* shapes, size_t shapesCount, int x, int y) { 21 | for (size_t i = 0; i < shapesCount; ++i) { 22 | std::cout << shapes[i]->isPointIn(x, y) << std::endl; 23 | } 24 | } 25 | 26 | void FreeCollection(Shape** shapes, size_t shapesCount) { 27 | for (size_t i = 0; i < shapesCount; ++i) { 28 | delete shapes[i]; 29 | } 30 | 31 | delete[] shapes; 32 | } 33 | 34 | int main() { 35 | Shape** arr = new Shape*[4]; 36 | 37 | arr[0] = new Rectangle(3, 4, 6, 8); 38 | arr[1] = new Circle(3, 3, 4); 39 | arr[2] = new Circle(1, 4, 5); 40 | arr[3] = new Triangle(1, 1, 2, 2, 3, 3); 41 | 42 | PrintAreas(arr, 4); 43 | std::cout << "-----SEPARATOR----\n"; 44 | PrintPers(arr, 4); 45 | std::cout << "-----SEPARATOR----\n"; 46 | CheckPointIn(arr, 4, 3, 3); 47 | 48 | FreeCollection(arr, 4); 49 | } -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/Vector/Vector.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | class Test { 4 | 5 | }; 6 | 7 | // NOTE!: most of the functions are not needed in the class 8 | // or do not work as in the original std::vector 9 | // They were created for testing purposes 10 | class Vector { 11 | private: 12 | Test* data = nullptr; 13 | size_t size = 0; 14 | size_t capacity; 15 | // the resize function of the actual std::vector 16 | // just lowers the size, the function that changes capacity is called reserve there 17 | void resize(size_t newCapacity); 18 | 19 | // Not needed functions - created in class to reuse code 20 | void assertIndex(size_t index) const; 21 | void upsizeIfNeeded(); 22 | void downsizeIfNeeded(); 23 | public: 24 | Vector(); 25 | Vector(size_t capacity); 26 | Vector(const Vector& other); 27 | Vector& operator=(const Vector& other); 28 | ~Vector(); 29 | 30 | size_t getSize() const; 31 | size_t getCapacity() const; 32 | 33 | // push/pop at do not exist in actual std::vector 34 | void pushBack(const Test& element); 35 | void pushAt(const Test& element, size_t index); 36 | Test popBack(); 37 | Test popAt(size_t index); 38 | 39 | bool empty() const; 40 | void clear(); 41 | void shrinkToFit(); 42 | 43 | Test& operator[](size_t index); 44 | const Test& operator[](size_t index) const; 45 | 46 | private: 47 | void copyFrom(const Vector& other); 48 | void free(); 49 | }; 50 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Shapes/cpp/Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include "Triangle.h" 2 | #include 3 | 4 | Triangle::Triangle(int x1, int y1, int x2, int y2, int x3, int y3) : Shape(3) { 5 | setPoint(0, x1, y1); 6 | setPoint(1, x2, y2); 7 | setPoint(2, x3, y3); 8 | } 9 | 10 | double Triangle::GetArea() const { 11 | const Shape::point& p1 = getPointAtIndex(0); 12 | const Shape::point& p2 = getPointAtIndex(1); 13 | const Shape::point& p3 = getPointAtIndex(2); 14 | 15 | 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; 16 | } 17 | 18 | double Triangle::GetPer() const { 19 | const Shape::point& p1 = getPointAtIndex(0); 20 | const Shape::point& p2 = getPointAtIndex(1); 21 | const Shape::point& p3 = getPointAtIndex(2); 22 | 23 | return p1.getDist(p2) + p2.getDist(p3) + p3.getDist(p1); 24 | } 25 | 26 | bool Triangle::IsPointIn(int x, int y) const { 27 | Shape::point p(x, y); 28 | Triangle t1(getPointAtIndex(0).x, getPointAtIndex(0).y, getPointAtIndex(1).x, getPointAtIndex(1).y, p.x, p.y); 29 | Triangle t2(getPointAtIndex(2).x, getPointAtIndex(2).y, getPointAtIndex(1).x, getPointAtIndex(1).y, p.x, p.y); 30 | Triangle t3(getPointAtIndex(2).x, getPointAtIndex(2).y, getPointAtIndex(0).x, getPointAtIndex(0).y, p.x, p.y); 31 | 32 | return abs(t1.getArea() + t2.getArea() + t3.getArea() - getArea()) <= std::numeric_limits::epsilon(); 33 | 34 | } -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/StringPool/StringPool.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | namespace StringPoolConstants { 4 | const unsigned char SMALL_STRING_MAX_LENGTH = 64; 5 | const unsigned char INITIAL_CAPACITY = 4; 6 | } 7 | 8 | class StringPool { 9 | private: 10 | class SmallString { 11 | private: 12 | char data[StringPoolConstants::SMALL_STRING_MAX_LENGTH + 1]; 13 | size_t refsCount = 1; 14 | public: 15 | SmallString(const char* str); 16 | const char* c_str() const; 17 | const size_t getRefsCount() const; 18 | 19 | bool operator==(const SmallString& other) const; 20 | bool operator<(const SmallString& other) const; 21 | friend class StringPool; 22 | }; 23 | // should be a friend of the StringPool so that 24 | // we can access the SmallString 25 | friend int compare(const StringPool::SmallString& lhs, const StringPool::SmallString& rhs); 26 | 27 | SmallString** data; 28 | size_t size = 0; 29 | size_t capacity = 0; 30 | 31 | void resize(); 32 | public: 33 | StringPool(); 34 | StringPool(const StringPool& other); 35 | StringPool& operator=(const StringPool& other); 36 | ~StringPool(); 37 | 38 | size_t getSize() const; 39 | void insert(const SmallString& str); 40 | long long find(const SmallString& str) const; 41 | void removeAt(size_t index); 42 | 43 | const SmallString& operator[](size_t) const; 44 | 45 | private: 46 | void copyFrom(const StringPool& other); 47 | void free(); 48 | }; -------------------------------------------------------------------------------- /Seminars/Sem.09/Pract.09/README.md: -------------------------------------------------------------------------------- 1 | ## Задачи 2 | 3 | **Задача 1:** 4 | 5 | Трябва да се създаде система за обработка на поръчки. 6 | 7 | Създайте клас, който описва ресторант. Всеки ресторант има: 8 | - име (с максимална дължина 25 символа); 9 | - брой продукти 10 | - списък от продукти (с произволна дължина, която се подава в конструктора); 11 | - Поддържаме добавяне на продукт 12 | - Поддържаме и метод за получаване на поръчка 13 | 14 | Създайте клас, който описва поръчка. Всяка поръчка има: 15 | - име на ресторанта, за когото е 16 | - брой продукти 17 | - списък с продуктите. 18 | 19 | Ако в поръчката има продукт, който ресторантът не предлага, се хвърля грешка.
20 | В противен случай връща времето за доставка (време в минути, вие избирате каква точно да е логиката)
21 | 22 | Създайте клас Foodpanda, който има списък с ресторанти (отново с произволна дължина, която се задава в конструктора) и който прочита поръчки от конзолата.
23 | Класът намира за кой ресторант е поръчката, ако има такъв, в противен случай изписва, че поръчката е невалидна, понеже такъв ресторант не съществува.
24 | Ако ресторантът съществува му я изпраща.
25 | - Направете метод за добавяне на нови продукт/и в даден ресторант/и. 26 | - Направете метод за добавяне на нови ресторанти във Foodpanda. 27 | 28 | :warning: За всеки от класовете реализирайте нужните конструктори(+ move семантики) и функционалности. 29 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Example_polymorphism/Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include "Triangle.h" 2 | #include 3 | 4 | Triangle::Triangle(int x1, int y1, int x2, int y2, int x3, int y3) : Shape(3) 5 | { 6 | setPoint(0, x1, y1); 7 | setPoint(1, x2, y2); 8 | setPoint(2, x3, y3); 9 | } 10 | double Triangle::getArea() const 11 | { 12 | const Shape::point& p1 = getPointAtIndex(0); 13 | const Shape::point& p2 = getPointAtIndex(1); 14 | const Shape::point& p3 = getPointAtIndex(2); 15 | 16 | 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; //formula with the determinant 17 | } 18 | double Triangle::getPer() const 19 | { 20 | const Shape::point& p1 = getPointAtIndex(0); 21 | const Shape::point& p2 = getPointAtIndex(1); 22 | const Shape::point& p3 = getPointAtIndex(2); 23 | 24 | return p1.getDist(p2) + p2.getDist(p3) + p3.getDist(p1); 25 | } 26 | 27 | bool Triangle::isPointIn(int x, int y) const 28 | { 29 | Shape::point p(x, y); 30 | Triangle t1(getPointAtIndex(0).x, getPointAtIndex(0).y, getPointAtIndex(1).x, getPointAtIndex(1).y, p.x, p.y); 31 | Triangle t2(getPointAtIndex(2).x, getPointAtIndex(2).y, getPointAtIndex(1).x, getPointAtIndex(1).y, p.x, p.y); 32 | Triangle t3(getPointAtIndex(2).x, getPointAtIndex(2).y, getPointAtIndex(0).x, getPointAtIndex(0).y, p.x, p.y); 33 | 34 | return abs(t1.getArea() + t2.getArea() + t3.getArea() - getArea()) <= std::numeric_limits::epsilon(); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /Seminars/Sem.01/memoryAllocation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | // How much memory is allocated in the following expressions and where? 5 | // we assume that the pointer takes 4 bytes 6 | short s = 1; // Stack: 2 Heap: 0 7 | int a = 2; // Stack: 4 Heap: 0 8 | bool b = true; // Stack: 1 Heap: 0 9 | bool* p = new bool; // Stack: 4 Heap: 1 10 | char c = '\0'; // Stack: 1 Heap: 0 11 | double d = 11.1; // Stack: 8 Heap: 0 12 | int arr1[40] = { 0 }; // Stack: 164 Heap: 0 13 | // arr1 is a static array => it allocates one pointer and 40 * 4 int 14 | 15 | int* arr2 = new int(40); // Stack: 4 Heap: 4 16 | int* arr3 = new int[40]; // Stack: 4 Heap: 160 17 | char test[] = "abcd"; // Stack: 9 Heap: 0 18 | int** matrix = new int*[10]; // Stack: 4 Heap: 10 * 4 19 | for (size_t i = 1; i < 10; i++) { 20 | matrix[i] = new int[i]; // new int(i) vs new int[i] 21 | } 22 | // new int(i) 23 | // Stack: 4 Heap: 10 * 4 + 9 * 4 24 | // new int[i] 25 | // Stack: 4 Heap: 10 * 4 + 4(1 + 2 .... + 9) 26 | 27 | //int arr1[40] = { 0 }; // Stack: 164 Heap: 28 | //int* arr2 = new int(40); // Stack: 4 Heap: 4 29 | //int* arr3 = new int[40]; // Stack: 4 Heap: 160 30 | 31 | // Which of the following statements is/are incorrect? 32 | // delete[] arr1; - arr1 is not a dynamic array 33 | // delete[] arr2; - arr2 is a pointer to a int, not to a int[] 34 | // delete[] arr3; - correct 35 | 36 | return 0; 37 | } -------------------------------------------------------------------------------- /Seminars/Sem.08/Pract.08/Task01/OOPcourse.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Student.h" 4 | #include "Teacher.h" 5 | 6 | const int MAX_NUMBER_OF_ASSISTANTS = 3; 7 | const int START_ARRAY_SIZE = 2; 8 | 9 | class OOPcourse { 10 | // A student exists intependently, outside the course 11 | Student** _students = nullptr; 12 | 13 | // One lecturer/assistant can teach multiple OOP courses 14 | Teacher* _lecturer = nullptr; 15 | Teacher* _assistants[MAX_NUMBER_OF_ASSISTANTS]{ nullptr }; 16 | 17 | unsigned _numberOfStudents = 0; 18 | unsigned _arraySize = START_ARRAY_SIZE; 19 | 20 | void copyFrom(const OOPcourse& other); 21 | void free(); 22 | void resize(); 23 | int find(unsigned FN); 24 | 25 | public: 26 | 27 | OOPcourse(); 28 | OOPcourse(Teacher* lecturer, Teacher* a1 = nullptr, Teacher* a2 = nullptr, Teacher* a3 = nullptr); 29 | OOPcourse(const OOPcourse& other); 30 | OOPcourse& operator=(const OOPcourse& other); 31 | ~OOPcourse(); 32 | 33 | void addStudent(Student& st); 34 | void addGrade(unsigned FN, const char* taskName, double gradeValue, const Teacher& teacher); 35 | double getAverageForCourse() const; 36 | bool removeStudent(unsigned FN); 37 | double getAverageGradePerTask(const char* taskName) const; 38 | double getAverageFromTeacher(const Teacher& teacher) const; 39 | 40 | void changeGrade(unsigned FN, const char* taskName, double newGrade); 41 | 42 | friend std::ostream& operator << (std::ostream& os, const OOPcourse& c); 43 | }; -------------------------------------------------------------------------------- /Seminars/Sem.14/Solutions/MyString/MyString.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class MyString 5 | { 6 | char* _data; 7 | size_t _length; 8 | 9 | void copyFrom(const MyString& data); 10 | void free(); 11 | 12 | explicit MyString(size_t capacity); //for memory allocation. How much bytes to allocate 13 | public: 14 | 15 | MyString(); 16 | MyString(const char* data); 17 | MyString(const MyString& other); 18 | MyString& operator=(const MyString& other); 19 | ~MyString(); 20 | 21 | MyString(MyString&& other) noexcept; 22 | MyString& operator=(MyString&& other) noexcept; 23 | 24 | size_t length() const; 25 | MyString& operator+=(const MyString& other); 26 | 27 | MyString substr(size_t begin, size_t howMany) const; 28 | 29 | char& operator[](size_t index); 30 | char operator[](size_t index) const; 31 | 32 | const char* c_str() const; 33 | 34 | friend MyString operator+(const MyString& lhs, const MyString& rhs); 35 | friend std::istream& operator>>(std::istream&, MyString& str); 36 | }; 37 | 38 | std::ostream& operator<<(std::ostream& os, const MyString& str); 39 | 40 | bool operator<(const MyString& lhs, const MyString& rhs); 41 | bool operator<=(const MyString& lhs, const MyString& rhs); 42 | bool operator>=(const MyString& lhs, const MyString& rhs); 43 | bool operator>(const MyString& lhs, const MyString& rhs); 44 | bool operator==(const MyString& lhs, const MyString& rhs); 45 | bool operator!=(const MyString& lhs, const MyString& rhs); -------------------------------------------------------------------------------- /Seminars/Sem.06/Pract. 06/Task02/Item.cpp: -------------------------------------------------------------------------------- 1 | #include "Item.h" 2 | #include 3 | #pragma warning(disable: 4996) 4 | 5 | Item::Item() : Item("Unkown", 0, 0){} 6 | 7 | Item::Item(const char* name, bool isAvailable, double price) { 8 | SetName(name); 9 | SetAvailability(isAvailable); 10 | SetPrice(price); 11 | } 12 | 13 | Item::Item(const Item& other){ 14 | copyFrom(other); 15 | } 16 | 17 | Item& Item::operator=(const Item& other){ 18 | if (this != &other) { 19 | free(); 20 | copyFrom(other); 21 | } 22 | return *this; 23 | } 24 | 25 | Item::~Item(){ 26 | free(); 27 | } 28 | 29 | void Item::SetName(const char* name) { 30 | if (name == nullptr) 31 | return; 32 | this->name = new char[strlen(name) + 1]; 33 | strcpy(this->name, name); 34 | } 35 | 36 | void Item::SetAvailability(bool isAvailable) { 37 | this->isAvailable = isAvailable; 38 | } 39 | 40 | void Item::SetPrice(double price) { 41 | if (price < 0) 42 | price = 0; 43 | this->price = price; 44 | } 45 | 46 | const char* Item::GetName() const{ 47 | return name; 48 | } 49 | 50 | bool Item::GetAvailability() const{ 51 | return isAvailable; 52 | } 53 | 54 | double Item::GetPrice() const{ 55 | return price; 56 | } 57 | 58 | void Item::copyFrom(const Item& other){ 59 | SetName(other.name); 60 | SetAvailability(other.isAvailable); 61 | SetPrice(other.price); 62 | } 63 | 64 | void Item::free(){ 65 | delete[] name; 66 | name = nullptr; 67 | isAvailable = false; 68 | price = 0; 69 | } 70 | -------------------------------------------------------------------------------- /Seminars/Sem.14/Solutions/ExpressionCalculator/MyString/MyString.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class MyString 5 | { 6 | char* _data; 7 | size_t _length; 8 | 9 | void copyFrom(const MyString& data); 10 | void free(); 11 | 12 | explicit MyString(size_t capacity); //for memory allocation. How much bytes to allocate 13 | public: 14 | 15 | MyString(); 16 | MyString(const char* data); 17 | MyString(const MyString& other); 18 | MyString& operator=(const MyString& other); 19 | ~MyString(); 20 | 21 | MyString(MyString&& other) noexcept; 22 | MyString& operator=(MyString&& other) noexcept; 23 | 24 | size_t length() const; 25 | MyString& operator+=(const MyString& other); 26 | 27 | MyString substr(size_t begin, size_t howMany) const; 28 | 29 | char& operator[](size_t index); 30 | char operator[](size_t index) const; 31 | 32 | const char* c_str() const; 33 | 34 | friend MyString operator+(const MyString& lhs, const MyString& rhs); 35 | friend std::istream& operator>>(std::istream&, MyString& str); 36 | }; 37 | 38 | std::ostream& operator<<(std::ostream& os, const MyString& str); 39 | 40 | bool operator<(const MyString& lhs, const MyString& rhs); 41 | bool operator<=(const MyString& lhs, const MyString& rhs); 42 | bool operator>=(const MyString& lhs, const MyString& rhs); 43 | bool operator>(const MyString& lhs, const MyString& rhs); 44 | bool operator==(const MyString& lhs, const MyString& rhs); 45 | bool operator!=(const MyString& lhs, const MyString& rhs); -------------------------------------------------------------------------------- /Seminars/Sem.12/Solutions/Shapes/cpp/Triangle.cpp: -------------------------------------------------------------------------------- 1 | #include "Triangle.h" 2 | #include 3 | 4 | Triangle::Triangle(int x1, int y1, int x2, int y2, int x3, int y3) : Shape(3) { 5 | setPoint(0, x1, y1); 6 | setPoint(1, x2, y2); 7 | setPoint(2, x3, y3); 8 | } 9 | 10 | double Triangle::GetArea() const { 11 | const Shape::point& p1 = getPointAtIndex(0); 12 | const Shape::point& p2 = getPointAtIndex(1); 13 | const Shape::point& p3 = getPointAtIndex(2); 14 | 15 | 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; 16 | } 17 | 18 | double Triangle::GetPer() const { 19 | const Shape::point& p1 = getPointAtIndex(0); 20 | const Shape::point& p2 = getPointAtIndex(1); 21 | const Shape::point& p3 = getPointAtIndex(2); 22 | 23 | return p1.getDist(p2) + p2.getDist(p3) + p3.getDist(p1); 24 | } 25 | 26 | bool Triangle::IsPointIn(int x, int y) const { 27 | Shape::point p(x, y); 28 | Triangle t1(getPointAtIndex(0).x, getPointAtIndex(0).y, getPointAtIndex(1).x, getPointAtIndex(1).y, p.x, p.y); 29 | Triangle t2(getPointAtIndex(2).x, getPointAtIndex(2).y, getPointAtIndex(1).x, getPointAtIndex(1).y, p.x, p.y); 30 | Triangle t3(getPointAtIndex(2).x, getPointAtIndex(2).y, getPointAtIndex(0).x, getPointAtIndex(0).y, p.x, p.y); 31 | 32 | return abs(t1.getArea() + t2.getArea() + t3.getArea() - getArea()) <= std::numeric_limits::epsilon(); 33 | } 34 | 35 | Shape* Triangle::clone() const override { 36 | return new Triangle(*this); 37 | } 38 | -------------------------------------------------------------------------------- /Seminars/Sem.09/Solutions/CompositionMoveSemantics.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class A { 4 | public: 5 | A() { 6 | std::cout << "A()" << std::endl; 7 | } 8 | 9 | A(const A& other) { 10 | std::cout << "A(const A& other)" << std::endl; 11 | } 12 | 13 | A(A&& other) noexcept { 14 | std::cout << "A(A&& other)" << std::endl; 15 | } 16 | 17 | A& operator=(const A& other) { 18 | std::cout << "operator=(const A& other)" << std::endl; 19 | return *this; 20 | } 21 | 22 | A& operator=(A&& other) noexcept { 23 | std::cout << "operator=(A&& other)" << std::endl; 24 | return *this; 25 | } 26 | 27 | ~A() { 28 | std::cout << "~A()" << std::endl; 29 | } 30 | }; 31 | 32 | class Test { 33 | A a; 34 | 35 | public: 36 | Test() { 37 | std::cout << "Test()" << std::endl; 38 | } 39 | 40 | Test(const Test& other) { 41 | std::cout << "Test(const Test& other)" << std::endl; 42 | } 43 | 44 | Test(Test&& other) noexcept : a(std::move(other.a)) { 45 | std::cout << "Test(Test&& other)" << std::endl; 46 | } 47 | 48 | Test& operator=(const Test& other) { 49 | std::cout << "operator=(const Test& other)" << std::endl; 50 | 51 | return *this; 52 | } 53 | 54 | Test& operator=(Test&& other) noexcept { 55 | std::cout << "operator=(Test&& other)" << std::endl; 56 | // if.... 57 | a = std::move(other.a); 58 | return *this; 59 | } 60 | 61 | ~Test() { 62 | std::cout << "~Test()" << std::endl; 63 | } 64 | }; 65 | 66 | int main() { 67 | Test t; 68 | Test t2(std::move(t)); 69 | t = std::move(t2); 70 | } -------------------------------------------------------------------------------- /Seminars/Sem.09/Pract.09/Task01/MyString/MyString.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | class MyString 5 | { 6 | char* _data; 7 | size_t _length; 8 | 9 | void copyFrom(const MyString& data); 10 | void free(); 11 | 12 | explicit MyString(size_t capacity); //for memory allocation. How much bytes to allocate 13 | public: 14 | 15 | MyString(); 16 | MyString(const char* data); 17 | MyString(const MyString& other); 18 | MyString& operator=(const MyString& other); 19 | ~MyString(); 20 | 21 | //move semantics on the next lecture 22 | //MyString(MyString&& other) = delete; 23 | //MyString& operator=(MyString&& other) = delete; 24 | /// 25 | 26 | size_t length() const; 27 | MyString& operator+=(const MyString& other); 28 | 29 | MyString substr(size_t begin, size_t howMany) const; 30 | 31 | char& operator[](size_t index); 32 | char operator[](size_t index) const; 33 | 34 | const char* c_str() const; 35 | 36 | friend MyString operator+(const MyString& lhs, const MyString& rhs); 37 | friend std::istream& operator>>(std::istream& is, MyString& str); 38 | }; 39 | 40 | std::ostream& operator<<(std::ostream& os, const MyString& str); 41 | 42 | bool operator<(const MyString& lhs, const MyString& rhs); 43 | bool operator<=(const MyString& lhs, const MyString& rhs); 44 | bool operator>=(const MyString& lhs, const MyString& rhs); 45 | bool operator>(const MyString& lhs, const MyString& rhs); 46 | bool operator==(const MyString& lhs, const MyString& rhs); 47 | bool operator!=(const MyString& lhs, const MyString& rhs); -------------------------------------------------------------------------------- /Seminars/Sem.14/Pract. 14/README.md: -------------------------------------------------------------------------------- 1 | ### Задача: 2 | Реализирайте класов бар, в който се продават нормални напитки и алкохолни напитки. Трябва да имате функции за зареждане на напитки от бара и взимане на напитка от бара. 3 | При зареждането се посочва и броят на артикулите, които се зареждат. Ако не се каже брой - зарежда се 1 артикул. 4 | 5 | При взимането на напитка от бара: Избира се тип (нормална или алкохолна) и се връща най-отдавна заредената в бара. 6 | Във всеки момент трябва да могат да се взимат статистика за бара - брой продадени артикула oт всеки тип и сумарно продадени мл. 7 | 8 | **Напитката** има име (низ с произволна дължина, само от латински символи, в който първият символ е главен), количество (в мл [200, 1000]), а **алкохолната напитка** има *име (низ с произволна дължина, само от латински символи, в който първият символ е главен), количество (в мл [200, 1000]) и процент алкохол [5, 98]*. 9 | 10 | Примерен интерфейс: 11 | ```c++ 12 | 13 | int main() 14 | { 15 | Bar b; 16 | 17 | b.addDrink("Coke", 330, 2); //2x Coca cola 330 ml 18 | 19 | b.addDrink("Fanta", 500); //1x Fanta 500 ml 20 | 21 | b.addAlocoholDrink("Zagorka", 500, 5); //1x Zagorka, 5% alc, 500 ml 22 | 23 | b.getAcloholDrink(); // Zagorka 24 | 25 | b.getDrink() // Coke 26 | b.getDrink() // Coke 27 | b.getDrink() // Fanta 28 | 29 | b.getAlocholDrinksSold(); // 1 30 | b.getDrinksMlSold(); // 830 31 | 32 | } 33 | ``` 34 | ![image](https://github.com/Justsvetoslavov/Object-oriented_programming_FMI/assets/49128895/8d393978-fb4c-4f67-b534-f0ef92fd1ae8) 35 | -------------------------------------------------------------------------------- /Seminars/Utils/TheoryExamples/RuleOf4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct A { 4 | A() { 5 | std::cout << "A constructor" << std::endl; 6 | } 7 | 8 | A(const A& other) { 9 | std::cout << "A copy-constructor" << std::endl; 10 | } 11 | 12 | A& operator=(const A& other) { 13 | std::cout << "A operator=" << std::endl; 14 | return *this; 15 | } 16 | 17 | ~A() { 18 | std::cout << "A destructor" << std::endl; 19 | } 20 | }; 21 | 22 | struct B { 23 | B() { 24 | std::cout << "B constructor" << std::endl; 25 | } 26 | 27 | B(const B& other) { 28 | std::cout << "B copy-constructor" << std::endl; 29 | } 30 | 31 | B& operator=(const B& other) { 32 | std::cout << "B operator=" << std::endl; 33 | return *this; 34 | } 35 | 36 | ~B() { 37 | std::cout << "B destructor" << std::endl; 38 | } 39 | }; 40 | 41 | struct C { 42 | A a; 43 | B b; 44 | 45 | C() { 46 | std::cout << "C constructor" << std::endl; 47 | } 48 | 49 | // you have to explicitly call a and b copy constr 50 | // otherwise the default constructors will be called 51 | C(const C& other) : a(other.a), b(other.b) { 52 | std::cout << "C copy-constructor" << std::endl; 53 | } 54 | 55 | // you have to explicitly call a and b operator= 56 | // otherwise nothing will be called 57 | C& operator=(const C& other) { 58 | a = other.a; 59 | b = other.b; 60 | std::cout << "C operator=" << std::endl; 61 | return *this; 62 | } 63 | 64 | ~C() { 65 | std::cout << "C destructor" << std::endl; 66 | } 67 | }; 68 | 69 | int main() { 70 | C c2, c3; 71 | C c1 = c2; 72 | c2 = c3; 73 | } -------------------------------------------------------------------------------- /Seminars/Utils/Exam/Task02/ModifiableNaturalNumbersFunction.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "NaturalNumbersFunction.hpp" 4 | 5 | class ModifiableNaturalNumbersFunction : protected NaturalNumbersFunction { 6 | private: 7 | static const int InvalidPoint = -1; 8 | static const int InvalidIndex = -1; 9 | 10 | public: 11 | ModifiableNaturalNumbersFunction(); 12 | ModifiableNaturalNumbersFunction(UnaryUnsignedFunction pFunc, unsigned pointsToChange); 13 | ModifiableNaturalNumbersFunction(const ModifiableNaturalNumbersFunction& other); 14 | ModifiableNaturalNumbersFunction(ModifiableNaturalNumbersFunction&& other) noexcept; 15 | ModifiableNaturalNumbersFunction& operator=(const ModifiableNaturalNumbersFunction& other); 16 | ModifiableNaturalNumbersFunction& operator=(ModifiableNaturalNumbersFunction&& other) noexcept; 17 | ~ModifiableNaturalNumbersFunction(); 18 | 19 | public: 20 | bool Modify(unsigned point, unsigned value); 21 | bool RemoveModification(unsigned point); 22 | 23 | using NaturalNumbersFunction::CountFixedPoints; 24 | 25 | unsigned Eval(unsigned value) const final; 26 | void SetFunction(UnaryUnsignedFunction pFunc) final; 27 | 28 | private: 29 | void CopyFrom(const ModifiableNaturalNumbersFunction& other); 30 | void MoveFrom(ModifiableNaturalNumbersFunction&& other); 31 | void Free(); 32 | 33 | int FindPointIndex(unsigned point) const; 34 | void RemoveAllModifications(); 35 | 36 | private: 37 | struct Pair { 38 | int m_point = -1; 39 | int m_value = -1; 40 | }; 41 | 42 | Pair* m_pModifiedPoints = nullptr; 43 | unsigned m_capacity = 0; 44 | unsigned m_currentSize = 0; 45 | }; 46 | -------------------------------------------------------------------------------- /Seminars/Sem.10/Solutions/Small String Optimization (SSO)/MyStringSSO.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class MyString { 6 | private: 7 | static const short SSO_MAX_SIZE = sizeof(char*) + sizeof(size_t) - 1; 8 | 9 | union 10 | { 11 | struct 12 | { 13 | char* _data; 14 | size_t _size; 15 | }; 16 | char ssoData[MyString::SSO_MAX_SIZE + 1] = "\0"; 17 | }; 18 | 19 | bool isSso() const; 20 | void move(MyString&& other); 21 | void copyFrom(const MyString& other); 22 | void free(); 23 | 24 | explicit MyString(size_t size); 25 | 26 | void notUsingSso(); 27 | public: 28 | 29 | MyString(); 30 | MyString(const char* data); 31 | 32 | MyString(const MyString& other); 33 | MyString& operator=(const MyString& other); 34 | 35 | MyString(MyString&& other) noexcept; 36 | MyString& operator=(MyString&& other) noexcept; 37 | 38 | MyString& operator+=(const MyString& other); 39 | 40 | const char* c_str() const; 41 | size_t length() const; 42 | 43 | char& operator[](size_t index); 44 | char operator[](size_t index) const; 45 | 46 | ~MyString(); 47 | 48 | friend MyString operator+(const MyString& lhs, const MyString& rhs); 49 | }; 50 | 51 | std::ostream& operator<<(std::ostream& os, const MyString& obj); 52 | 53 | bool operator<(const MyString& lhs, const MyString& rhs); 54 | bool operator<=(const MyString& lhs, const MyString& rhs); 55 | bool operator>=(const MyString& lhs, const MyString& rhs); 56 | bool operator>(const MyString& lhs, const MyString& rhs); 57 | bool operator==(const MyString& lhs, const MyString& rhs); 58 | bool operator!=(const MyString& lhs, const MyString& rhs); -------------------------------------------------------------------------------- /Seminars/Sem.01/Pract.01/Task03.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int** InitializeMatrix(const int rows, const int cols) 4 | { 5 | int** matrix = new int*[rows]; 6 | for (size_t i = 0; i < rows; i++) { 7 | matrix[i] = new int[cols]; 8 | } 9 | 10 | return matrix; 11 | } 12 | 13 | void FillMatrix(int** matrix, const int rows, const int cols) 14 | { 15 | for (size_t i = 0; i < rows; i++) { 16 | for (size_t j = 0; j < cols; j++) { 17 | std::cin >> matrix[i][j]; 18 | } 19 | } 20 | } 21 | 22 | int** TransposeMatrix(const int** matrix, const int rows, const int cols) 23 | { 24 | int** transposedMatrix = InitializeMatrix(cols, rows); 25 | for (size_t i = 0; i < rows; i++) { 26 | for (size_t j = 0; j < cols; j++) { 27 | transposedMatrix[j][i] = matrix[i][j]; 28 | } 29 | } 30 | 31 | return transposedMatrix; 32 | } 33 | 34 | void PrintMatrix(const int** matrix, const int rows, const int cols) 35 | { 36 | for (size_t i = 0; i < rows; i++) { 37 | for (size_t j = 0; j < cols; j++) { 38 | std::cout << matrix[i][j] << " "; 39 | } 40 | std::cout << std::endl; 41 | } 42 | } 43 | 44 | void DeleteMatrix(int** matrix, const int rows) 45 | { 46 | for (size_t i = 0; i < rows; i++) { 47 | delete[] matrix[i]; 48 | } 49 | 50 | delete[] matrix; 51 | } 52 | 53 | int main() 54 | { 55 | int rows, cols; 56 | std::cin >> rows >> cols; 57 | 58 | int** matrix = InitializeMatrix(rows, cols); 59 | FillMatrix(matrix, rows, cols); 60 | PrintMatrix(matrix, rows, cols); 61 | 62 | int** transposedMatrix = TransposeMatrix(matrix, rows, cols); 63 | PrintMatrix(transposedMatrix, cols, rows); 64 | 65 | DeleteMatrix(matrix, rows); 66 | DeleteMatrix(transposedMatrix, cols); 67 | } -------------------------------------------------------------------------------- /Seminars/Sem.04/Pract.04/Task01/Teacher.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #pragma warning(disable : 4996) 4 | 5 | const short MIN_AGE = 18; 6 | const short MAX_AGE = 100; 7 | const short MAX_EXPERIENCE = 100; 8 | 9 | bool isNameValid(const char *name) { 10 | if(name == nullptr) { 11 | return false; 12 | } 13 | size_t nameLength = strlen(name); 14 | return nameLength > 0 && nameLength <= MAX_NAME_LENGTH; 15 | } 16 | 17 | Teacher::Teacher(const char *name, size_t age, size_t experience) { 18 | this->name[0] = '\0'; 19 | if (isNameValid(name)) { 20 | strcpy(this->name, name); 21 | } 22 | 23 | if(age < MIN_AGE || age > MAX_AGE) { 24 | age = MIN_AGE; 25 | } 26 | if(experience > MAX_EXPERIENCE) { 27 | experience = 0; 28 | } 29 | 30 | this->age = age; 31 | this->experience = experience; 32 | } 33 | 34 | const char *Teacher::getName() const { 35 | return name; 36 | } 37 | 38 | size_t Teacher::getAge() const { 39 | return age; 40 | } 41 | 42 | size_t Teacher::getExperience() const { 43 | return experience; 44 | } 45 | 46 | bool Teacher::setName(const char *name) { 47 | if (!isNameValid(name)) { 48 | return false; 49 | } 50 | 51 | strcpy(this->name, name); 52 | return true; 53 | } 54 | 55 | bool Teacher::setAge(size_t age) { 56 | if(age < MIN_AGE || age > MAX_AGE) { 57 | return false; 58 | } 59 | 60 | this->age = age; 61 | return true; 62 | } 63 | 64 | bool Teacher::setExperience(size_t experience) { 65 | if(experience > MAX_EXPERIENCE) { 66 | return false; 67 | } 68 | 69 | this->experience = experience; 70 | return true; 71 | } 72 | -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/readme.md: -------------------------------------------------------------------------------- 1 | # Семинар 12.05.23 2 | 3 | ## Задача първа 4 | Да се реализира полиморфна йерархия за работа колекции от цели числа. Всяка от колекциите трябва да съдържа: 5 | * `add` - Добавя елемент към колекцията. 6 | * `remove` - Премахва елемент от колекцията. 7 | * `count` - Връжа колко елемента от този тип имаме. 8 | * `contains` - Връща дали елемента се съдържа в колекцията. 9 | 10 | Ща раелизираме следните колекции: 11 | * NormalCollection - Това е стандартната динамична колекция. 12 | * add - O(1) 13 | * remove - O(n) (remove e O(1) ако премахваме по индекс) 14 | * count - O(n) 15 | * contains - O(n) 16 | * SortedCollection - Колекция в която елементите са сортирани 17 | * add - O(n) 18 | * remove - O(n) 19 | * count - O(log(n)) 20 | * contains - O(log(n)) - двоично търсене. 21 | * IntervalCollection - Колекция, която допуска числа само от определен интервал (примерно [5, 49]) 22 | * add - O(1) 23 | * remove - O(1) 24 | * count - O(1) 25 | * contains - O(1) 26 | * Union - Oбединение на две колекции. 27 | * add - Добавя елемент и в двете колекции. 28 | * remove - премахва елемент и от двете колекции 29 | * count - връща броя в лявата и в дясната колекция 30 | * contains - връща дали се съдържа в лявата или дясната колекция 31 | * Intersection - Сечение на две колекции. 32 | * add - добавя в колекцията с по - малко елементи. Когато са равни се добавя и в двете колекции. 33 | * remove - премахва от колекцията с по - малък брой. Когато са равни се премахва и от двете. 34 | * count - връща броя в колекцията с по - малко елементи. 35 | * contains - връща дали елемента се среща и в двете колекции. -------------------------------------------------------------------------------- /Seminars/Sem.15/Solutions/Design-Patterns/Creational Patterns/README.md: -------------------------------------------------------------------------------- 1 | ## Creational 2 | Предоставят различни начини за създаване на обект 3 | 4 | - **Singleton** – има най-много една жива инстанция на класа за целия lifetime на програмата, която е достъпна от цялата програма (irl пример – Една държава, едно правителство) 5 | - Плюсове 6 | - Достъпва се от всякъде 7 | - Има точно една инстанция, която се създава при първо извикване 8 | - Минуси 9 | - Нарушава S от Solid (хем дава инстанция, хем създава, хем се грижи за lifycycle му) 10 | - При многонишкова програма, обектът може да бъде създаден няколко пъти (първата влязла нишка трябва да lock-не scope-a на създаване, другите нишки ще изчакват, първата ще създаде обекта и ще release-не lock-а, след като влязат другите те вече ще видят, че има създаден обект и няма да тръгнат да правят нов) 11 | - проблеми при unit test-ове, понеже не може да се моква static и конструктора на сингълтъна class-a е private 12 | 13 | - **Factory** – създава интерфейс, през който да се създава обект от даден клас, като позволява на наследниците да изберат кой клас да инстанцират. 14 | Решението, което предоставя, е вместо да се извиква new operator - да се вика даден метод на някакво factory(където обекта все пак се създава с new operator). Резултатът от създавене се нарича продукт. 15 | - Плюсове 16 | - Скрива създаването; 17 | - Лесно за mock-ванe; 18 | - Single Responsibility; 19 | - Open/Closed - може да добавяме нови типове продукти; 20 | - Минуси 21 | - Много нов код - интерфейси и класове 22 | 23 | In general е добре да се знае и за: 24 | - **Abstract Factory** 25 | - **Builder** 26 | - **Prototype** (цял семестър го ползваме 😅) 27 | -------------------------------------------------------------------------------- /Seminars/Sem.01/Pract.01/Task04.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const short MAX_NAME_SIZE = 30; 4 | 5 | struct Student 6 | { 7 | char name[MAX_NAME_SIZE + 1]; 8 | unsigned int fn; 9 | }; 10 | 11 | void InitStudent(Student& student, const char* name, unsigned int fn) 12 | { 13 | strcpy_s(student.name, MAX_NAME_SIZE, name); 14 | student.fn = fn; 15 | } 16 | 17 | void PrintStudent(const Student& student) 18 | { 19 | std::cout << student.name << " " << student.fn << "\n"; 20 | } 21 | 22 | int main() 23 | { 24 | Student st = { "Joro", 10 }; 25 | PrintStudent(st); 26 | st = {"Ivan", 20 }; 27 | PrintStudent(st); 28 | InitStudent(st, "New Name", 82); 29 | PrintStudent(st); 30 | std::cout << "\n\n"; 31 | 32 | Student* pSt = &st; 33 | *pSt = { "Valeri", 30 }; 34 | PrintStudent(*pSt); 35 | InitStudent(*pSt, "PST New Name", 100); 36 | PrintStudent(*pSt); 37 | std::cout << "\n\n"; 38 | 39 | const Student* pCSt = &st; 40 | //*pCSt = { "Valeri", 30 }; 41 | //initStudent(*pCSt, "PST New Name", 100); 42 | 43 | Student* const cPSt = &st; 44 | *cPSt = { "Ivaylo", 1000 }; 45 | PrintStudent(*cPSt); 46 | InitStudent(*cPSt, "CPST New Name", 100); 47 | PrintStudent(*cPSt); 48 | std::cout << "\n\n"; 49 | 50 | const Student* const cpCSt = &st; 51 | //*cpCSt = { "Valeri", 30 }; 52 | //initStudent(*cpCSt, "PST New Name", 100); 53 | 54 | Student& refSt = st; 55 | refSt = {"Valentin", 82}; 56 | PrintStudent(refSt); 57 | InitStudent(refSt, "REFST New Name", 100); 58 | PrintStudent(refSt); 59 | 60 | const Student& refCSt = st; 61 | //refCSt = { "Valentin", 82 }; 62 | //initStudent(refCSt, "PST New Name", 100); 63 | } -------------------------------------------------------------------------------- /Seminars/Sem.13/Solutions/FixedLengthStack/FixedLengthStack.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | template 5 | class FixedLengthStack { 6 | private: 7 | T data[capacity]; 8 | size_t size = 0; 9 | public: 10 | void push(const T& obj); 11 | void push(T&& obj); 12 | 13 | void pop(); 14 | const T& peek() const; 15 | bool isEmpty() const; 16 | size_t getSize() const; 17 | void clear(); 18 | }; 19 | 20 | template 21 | void FixedLengthStack::push(const T& obj) { 22 | if (size == capacity) { 23 | throw std::exception("Stack is full"); 24 | } 25 | 26 | data[size++] = obj; 27 | } 28 | 29 | template 30 | void FixedLengthStack::push(T&& obj) { 31 | if (size == capacity) { 32 | throw std::exception("Stack is full"); 33 | } 34 | 35 | data[size++] = std::move(obj); 36 | } 37 | 38 | template 39 | void FixedLengthStack::pop() { 40 | if (isEmpty()) { 41 | throw std::exception("Already empty"); 42 | } 43 | 44 | --size; 45 | } 46 | 47 | template 48 | const T& FixedLengthStack::peek() const { 49 | if (isEmpty()) { 50 | throw std::exception("Stack is empty"); 51 | } 52 | 53 | return data[size - 1]; 54 | } 55 | 56 | template 57 | bool FixedLengthStack::isEmpty() const { 58 | return size == 0; 59 | } 60 | 61 | template 62 | size_t FixedLengthStack::getSize() const { 63 | return size; 64 | } 65 | 66 | template 67 | void FixedLengthStack::clear() { 68 | size = 0; 69 | } -------------------------------------------------------------------------------- /Seminars/Sem.11/Solutions/Lectures/Collection/DynamicCollection.cpp: -------------------------------------------------------------------------------- 1 | #include "DynamicCollection.h" 2 | #include // std::move 3 | 4 | void DynamicCollection::free() 5 | { 6 | delete[] data; 7 | } 8 | 9 | void DynamicCollection::copyFrom(const DynamicCollection& other) 10 | { 11 | size = other.size; 12 | capacity = other.capacity; 13 | data = new int[capacity]; 14 | 15 | for (size_t i = 0; i < size; i++) 16 | { 17 | data[i] = other.data[i]; 18 | } 19 | } 20 | 21 | void DynamicCollection::moveFrom(DynamicCollection&& other) 22 | { 23 | data = other.data; 24 | other.data = nullptr; 25 | 26 | other.size = other.capacity = 0; 27 | } 28 | 29 | DynamicCollection::DynamicCollection(DynamicCollection&& other) 30 | { 31 | moveFrom(std::move(other)); 32 | } 33 | 34 | DynamicCollection& DynamicCollection::operator=(DynamicCollection&& other) 35 | { 36 | if(this != &other) 37 | { 38 | free(); 39 | moveFrom(std::move(other)); 40 | } 41 | return *this; 42 | } 43 | 44 | void DynamicCollection::resize(size_t nCap) 45 | { 46 | int* newData = new int[nCap]; 47 | 48 | for (size_t i = 0; i < size; i++) 49 | { 50 | newData[i] = data[i]; 51 | } 52 | 53 | delete[] data; 54 | data = newData; 55 | capacity = nCap; 56 | } 57 | 58 | DynamicCollection::DynamicCollection() 59 | { 60 | size = 0; 61 | capacity = 8; 62 | 63 | data = new int[capacity]; 64 | } 65 | 66 | DynamicCollection::DynamicCollection(const DynamicCollection& other) 67 | { 68 | copyFrom(other); 69 | } 70 | 71 | DynamicCollection& DynamicCollection::operator=(const DynamicCollection& other) 72 | { 73 | if (this != &other) 74 | { 75 | free(); 76 | copyFrom(other); 77 | } 78 | 79 | return *this; 80 | } 81 | 82 | DynamicCollection::~DynamicCollection() 83 | { 84 | free(); 85 | } 86 | -------------------------------------------------------------------------------- /Seminars/Sem.03/Solutions/DynamicNameStudent.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | struct DynamicNameStudent 7 | { 8 | char* name; 9 | int age; 10 | int fn; 11 | }; 12 | 13 | DynamicNameStudent init(const char* name, int age, int fn) 14 | { 15 | DynamicNameStudent st; 16 | 17 | st.name = new char[strlen(name) + 1]; 18 | strcpy(st.name, name); 19 | 20 | st.age = age; 21 | st.fn = fn; 22 | 23 | return st; 24 | } 25 | 26 | void freeStudent(DynamicNameStudent& st) 27 | { 28 | delete[] st.name; 29 | st.age = st.fn = 0; 30 | } 31 | 32 | void saveToBinaryFile(std::ofstream& ofs, const DynamicNameStudent& st) 33 | { 34 | int nameLen = strlen(st.name); 35 | ofs.write((const char*)&nameLen, sizeof(int)); 36 | ofs.write(st.name, nameLen + 1); 37 | 38 | ofs.write((const char*)&st.age, sizeof(st.age)); 39 | ofs.write((const char*)&st.fn, sizeof(st.fn)); 40 | 41 | } 42 | DynamicNameStudent readFromBinaryFile(std::ifstream& ifs) 43 | { 44 | DynamicNameStudent st2; 45 | 46 | int nameLen; 47 | ifs.read((char*)&nameLen, sizeof(nameLen)); 48 | 49 | st2.name = new char[nameLen + 1]; 50 | 51 | ifs.read(st2.name, nameLen + 1); 52 | 53 | ifs.read((char*)&st2.age, sizeof(st2.age)); 54 | ifs.read((char*)&st2.fn, sizeof(st2.fn)); 55 | 56 | return st2; 57 | } 58 | 59 | 60 | 61 | int main() 62 | { 63 | { 64 | DynamicNameStudent myStudent = init("Ivan", 10, 30); 65 | 66 | std::ofstream ofs("student.dat", std::ios::out | std::ios::binary); 67 | 68 | saveToBinaryFile(ofs, myStudent); 69 | 70 | freeStudent(myStudent); 71 | } 72 | 73 | { 74 | std::ifstream ifs("student.dat", std::ios::in | std::ios::binary); 75 | DynamicNameStudent st = readFromBinaryFile(ifs); 76 | 77 | std::cout << st.name << " " << st.age << " " << st.fn; 78 | } 79 | } -------------------------------------------------------------------------------- /Seminars/Sem.08/Solutions/CarDealership/CarDealership/CarDealership.cpp: -------------------------------------------------------------------------------- 1 | #include "CarDealership.h" 2 | 3 | const short INITIAL_CAPACITY = 4; 4 | 5 | CarDealership::CarDealership() { 6 | count = 0; 7 | capacity = INITIAL_CAPACITY; 8 | cars = new Car* [capacity]; 9 | } 10 | 11 | CarDealership::CarDealership(const CarDealership& other) { 12 | copyFrom(other); 13 | } 14 | 15 | CarDealership& CarDealership::operator=(const CarDealership& other) { 16 | if (this != &other) { 17 | free(); 18 | copyFrom(other); 19 | } 20 | 21 | return *this; 22 | } 23 | 24 | CarDealership::~CarDealership() { 25 | free(); 26 | } 27 | 28 | void CarDealership::resize() { 29 | capacity *= 2; 30 | Car** temp = new Car* [capacity]; 31 | for (size_t i = 0; i < count; i++) { 32 | temp[i] = cars[i]; 33 | } 34 | 35 | delete[] cars; 36 | cars = temp; 37 | } 38 | 39 | void CarDealership::addCar(const Car& newCar) { 40 | if (count >= capacity) { 41 | resize(); 42 | } 43 | 44 | cars[count++] = new Car(newCar); 45 | } 46 | 47 | void CarDealership::deleteAtIndex(size_t index) { 48 | if (index >= count) { 49 | throw "Invalid index"; 50 | } 51 | 52 | delete cars[index]; 53 | cars[index] = cars[count - 1]; 54 | cars[--count] = nullptr; 55 | } 56 | 57 | const Car& CarDealership::getCar(size_t index) const { 58 | if (index >= count) { 59 | throw "Invalid index"; 60 | } 61 | 62 | return *(cars[index]); 63 | } 64 | 65 | void CarDealership::free() { 66 | for (size_t i = 0; i < count; i++) { 67 | delete cars[i]; 68 | } 69 | 70 | delete[] cars; 71 | capacity = count = 0; 72 | } 73 | 74 | void CarDealership::copyFrom(const CarDealership& other) { 75 | capacity = other.capacity; 76 | count = other.count; 77 | cars = new Car* [capacity]; 78 | 79 | for (size_t i = 0; i < count; i++) { 80 | cars[i] = new Car(*(other.cars[i])); 81 | } 82 | } -------------------------------------------------------------------------------- /Seminars/Sem.15/Solutions/Design-Patterns/Structural Patterns/Adapter/Adapter.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * The Target defines the domain-specific interface used by the client code. 3 | */ 4 | class Target { 5 | public request(): string { 6 | return 'Target: The default target\'s behavior.'; 7 | } 8 | } 9 | 10 | /** 11 | * The Adaptee contains some useful behavior, but its interface is incompatible 12 | * with the existing client code. The Adaptee needs some adaptation before the 13 | * client code can use it. 14 | */ 15 | class Adaptee { 16 | public specificRequest(): string { 17 | return '.eetpadA eht fo roivaheb laicepS'; 18 | } 19 | } 20 | 21 | /** 22 | * The Adapter makes the Adaptee's interface compatible with the Target's 23 | * interface. 24 | */ 25 | class Adapter extends Target { 26 | private adaptee: Adaptee; 27 | 28 | constructor(adaptee: Adaptee) { 29 | super(); 30 | this.adaptee = adaptee; 31 | } 32 | 33 | public request(): string { 34 | const result = this.adaptee.specificRequest().split('').reverse().join(''); 35 | return `Adapter: (TRANSLATED) ${result}`; 36 | } 37 | } 38 | 39 | /** 40 | * The client code supports all classes that follow the Target interface. 41 | */ 42 | function clientCode(target: Target) { 43 | console.log(target.request()); 44 | } 45 | 46 | console.log('Client: I can work just fine with the Target objects:'); 47 | const target = new Target(); 48 | clientCode(target); 49 | 50 | console.log(''); 51 | 52 | const adaptee = new Adaptee(); 53 | console.log('Client: The Adaptee class has a weird interface. See, I don\'t understand it:'); 54 | console.log(`Adaptee: ${adaptee.specificRequest()}`); 55 | 56 | console.log(''); 57 | 58 | console.log('Client: But I can work with it via the Adapter:'); 59 | const adapter = new Adapter(adaptee); 60 | clientCode(adapter); -------------------------------------------------------------------------------- /Seminars/Sem.10/Solutions/Person-Student-Teacher/Person/Person.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include "Person.h" 3 | #include 4 | #pragma warning (disable:4996) 5 | 6 | 7 | 8 | void Person::copyFrom(const Person& other) 9 | { 10 | name = new char[strlen(other.name) + 1]; 11 | strcpy(name, other.name); 12 | age = other.age; 13 | } 14 | 15 | void Person::free() 16 | { 17 | delete[] name; 18 | } 19 | 20 | Person::Person(const char* name, int age) 21 | { 22 | setName(name); 23 | setAge(age); 24 | } 25 | 26 | Person::Person(const Person& other) 27 | { 28 | copyFrom(other); 29 | } 30 | 31 | Person& Person::operator=(const Person& other) 32 | { 33 | if (this != &other) 34 | { 35 | free(); 36 | copyFrom(other); 37 | } 38 | return *this; 39 | } 40 | 41 | void Person::moveFrom(Person&& other) 42 | { 43 | name = other.name; 44 | other.name = nullptr; 45 | age = other.age; 46 | } 47 | 48 | 49 | Person::Person(Person&& other) 50 | { 51 | moveFrom(std::move(other)); 52 | } 53 | 54 | Person& Person::operator=(Person&& other) 55 | { 56 | if (this != &other) 57 | { 58 | free(); 59 | moveFrom(std::move(other)); 60 | } 61 | return *this; 62 | } 63 | const char* Person::getName() const 64 | { 65 | return name; 66 | } 67 | 68 | int Person::getAge() const 69 | { 70 | return age; 71 | } 72 | 73 | void Person::setName(const char* name) 74 | { 75 | if (name == nullptr || this->name == name) 76 | return; 77 | 78 | delete[] this->name; 79 | size_t nameLen = strlen(name); 80 | this->name = new char[nameLen + 1]; 81 | strcpy(this->name, name); 82 | } 83 | 84 | void Person::setAge(int age) 85 | { 86 | this->age = age; 87 | } 88 | 89 | 90 | Person::~Person() 91 | { 92 | free(); 93 | } 94 | 95 | void Person::print() const 96 | { 97 | std::cout << name << " " << age << std::endl; 98 | } 99 | 100 | --------------------------------------------------------------------------------