Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit5dda3a1f40e4e8f621b20f374c02b6d1e241e7cf (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2022-05-10 20:06:53 +0300
Committer
 angeld55 <angel_dimitriev@abv.bg>
2022-05-10 20:06:53 +0300
Files52f913ec9532fd07c8f679ccf1e68876d1fc9ff2
Object-oriented_programming_FMI-5dda3a1f40e4e8f621b20f374c02b6d1e241e7cf.tar
Object-oriented_programming_FMI-5dda3a1f40e4e8f621b20f374c02b6d1e241e7cf.tar.gz
Object-oriented_programming_FMI-5dda3a1f40e4e8f621b20f374c02b6d1e241e7cf.zip
Parent459d3ac280aafdba703930455f3200b6e7b0f31b (diff)
sem 11
26 files changed, 969 insertions, 460 deletions
-rw-r--r--Sem. 09/MyString (with move)/MyString.cpp143
-rw-r--r--Sem. 09/MyString (with move)/MyString.h44
-rw-r--r--Sem. 10/Examples/Optional/Optional.hpp74
-rw-r--r--Sem. 10/Examples/Optional/Source2.cpp19
-rw-r--r--Sem. 10/Examples/Pair/Pair.hpp43
-rw-r--r--Sem. 10/Examples/Pair/Source2.cpp14
-rw-r--r--Sem. 11/Examples/Person/Person.cpp76
-rw-r--r--Sem. 11/Examples/Person/Person.h27
-rw-r--r--Sem. 11/Examples/Source2.cpp10
-rw-r--r--Sem. 11/Examples/Student/Student.cpp34
-rw-r--r--Sem. 11/Examples/Student/Student.h25
-rw-r--r--Utills/homework_1_SI/Домашна_работа_1.pdf (renamed from homework_1_SI/Домашна_работа_1.pdf)bin811843 -> 811843 bytes
-rw-r--r--Utills/k_1_SI/task1.cpp (renamed from k_1_SI/task1.cpp)0
-rw-r--r--Utills/k_1_SI/task2_read.cpp (renamed from k_1_SI/task2_read.cpp)0
-rw-r--r--Utills/k_1_SI/task2_write.cpp (renamed from k_1_SI/task2_write.cpp)0
-rw-r--r--Utills/допълнително упражнение/Source.cpp (renamed from допълнително упражнение/Source.cpp)22
-rw-r--r--Utills/допълнително упражнение/Task1/LogFile.cpp (renamed from допълнително упражнение/Task1/LogFile.cpp)182
-rw-r--r--Utills/допълнително упражнение/Task1/LogFile.h (renamed from допълнително упражнение/Task1/LogFile.h)46
-rw-r--r--Utills/допълнително упражнение/Task1/Timestamp.cpp (renamed from допълнително упражнение/Task1/Timestamp.cpp)8
-rw-r--r--Utills/допълнително упражнение/Task1/Timestamp.h (renamed from допълнително упражнение/Task1/Timestamp.h)16
-rw-r--r--Utills/допълнително упражнение/User.cpp (renamed from допълнително упражнение/User.cpp)194
-rw-r--r--Utills/допълнително упражнение/User.h (renamed from допълнително упражнение/User.h)52
-rw-r--r--Utills/допълнително упражнение/chatSystem.cpp (renamed from допълнително упражнение/chatSystem.cpp)160
-rw-r--r--Utills/допълнително упражнение/chatSystem.h (renamed from допълнително упражнение/chatSystem.h)62
-rw-r--r--Utills/допълнително упражнение/задачи за допълнително упражнение СИ.pdf (renamed from допълнително упражнение/задачи за допълнително упражнение СИ.pdf)bin69150 -> 69150 bytes
-rw-r--r--Utills/допълнително упражнение/функции от по - висок ред/demo.cpp (renamed from допълнително упражнение/функции от по - висок ред/demo.cpp)178
diff --git a/Sem. 09/MyString (with move)/MyString.cpp b/Sem. 09/MyString (with move)/MyString.cpp
new file mode 100644
index 0000000..a037d3d
--- /dev/null
+++ b/Sem. 09/MyString (with move)/MyString.cpp
@@ -0,0 +1,143 @@
+#include "MyString.h"
+#include <cstring>
+#include <iostream>
+
+void MyString::copyFrom(const MyString& other)
+{
+ str = new char[strlen(other.str) + 1];
+ strcpy(str, other.str);
+ size = other.size;
+}
+void MyString::free()
+{
+ delete[] str;
+}
+
+MyString::MyString()
+{
+ str = new char[1];
+ str[0] = '\0';
+ size = 0;
+}
+
+MyString::MyString(const char* data)
+{
+ if(data == nullptr)
+ {
+ str = new char[1];
+ str[0] = '\0';
+ size = 0;
+ }
+ else
+ {
+ size = strlen(data);
+ str = new char[size + 1];
+ strcpy(str, data);
+ }
+}
+
+MyString::MyString(const MyString& other)
+{
+ copyFrom(other);
+}
+MyString& MyString::operator=(const MyString& other)
+{
+ if (this != &other)
+ {
+ free();
+ copyFrom(other);
+ }
+ return *this;
+}
+MyString::~MyString()
+{
+ free();
+}
+
+
+size_t MyString::getSize() const
+{
+ return size;
+}
+void MyString::concat(const MyString& other)
+{
+ char* temp = new char[getSize() + other.getSize() + 1];
+ strcpy(temp, str);
+ strcat(temp, other.str);
+
+ delete[] str;
+ str = temp;
+ size = size + other.getSize();
+}
+
+const char* MyString::c_str() const
+{
+ return str;
+}
+
+MyString& MyString::operator+=(const MyString& other)
+{
+ concat(other);
+ return *this;
+}
+
+MyString operator+(const MyString& lhs, const MyString& rhs)
+{
+ MyString copyOfLeft(lhs);
+ copyOfLeft += rhs;
+ return copyOfLeft;
+}
+
+std::ostream& operator<<(std::ostream& stream, const MyString& str)
+{
+ stream << str.str;
+ return stream;
+}
+
+std::istream& operator>>(std::istream& stream, MyString& str)
+{
+ delete[] str.str;
+ char buff[1024];
+ stream >> buff;
+
+ str.size = strlen(buff);
+ str.str = new char[str.size + 1];
+ strcpy(str.str, buff);
+
+ return stream;
+}
+
+bool operator==(const MyString& lhs, const MyString& rhs)
+{
+ return strcmp(lhs.c_str(), rhs.c_str()) == 0;
+}
+bool operator<=(const MyString& lhs, const MyString& rhs)
+{
+ return strcmp(lhs.c_str(), rhs.c_str()) <= 0;
+
+}
+bool operator<(const MyString& lhs, const MyString& rhs)
+{
+ return strcmp(lhs.c_str(), rhs.c_str()) < 0;
+
+}
+
+MyString::MyString(MyString&& otherString)
+{
+ str = otherString.str;
+ size = otherString.size;
+ otherString.str = nullptr;
+ std::cout << "move constr" << std::endl;
+}
+
+MyString& MyString::operator=(MyString&& otherString)
+{
+ if (this != &otherString)
+ {
+ free();
+ str = otherString.str;
+ otherString.str = nullptr;
+ size = otherString.size;
+ }
+ return *this;
+}
diff --git a/Sem. 09/MyString (with move)/MyString.h b/Sem. 09/MyString (with move)/MyString.h
new file mode 100644
index 0000000..b37733a
--- /dev/null
+++ b/Sem. 09/MyString (with move)/MyString.h
@@ -0,0 +1,44 @@
+#pragma once
+
+#include <fstream>
+class MyString
+{
+ char* str;
+ size_t size;
+
+ void copyFrom(const MyString& other);
+ void free();
+
+public:
+ MyString();
+ MyString(const char*);
+
+ MyString(const MyString&);
+
+ MyString(MyString&&); //move constructor that accepts rvalue;
+
+ MyString& operator=(const MyString& other);
+ MyString& operator=(MyString&& other); //move op= that accepts rvalue;
+
+ ~MyString();
+
+ size_t getSize() const;
+ void concat(const MyString& other);
+
+ const char* c_str() const;
+
+ MyString& operator+=(const MyString& other);
+
+ friend std::ostream& operator<<(std::ostream& stream, const MyString& str);
+ friend std::istream& operator>>(std::istream& stream, MyString& str);
+
+};
+
+MyString operator+(const MyString& lhs, const MyString& rhs);
+
+bool operator==(const MyString& lhs, const MyString& rhs);
+bool operator<=(const MyString& lhs, const MyString& rhs);
+bool operator<(const MyString& lhs, const MyString& rhs);
+
+
+//MyString name = "sdfsdf" \ No newline at end of file
diff --git a/Sem. 10/Examples/Optional/Optional.hpp b/Sem. 10/Examples/Optional/Optional.hpp
new file mode 100644
index 0000000..9e3ab0f
--- /dev/null
+++ b/Sem. 10/Examples/Optional/Optional.hpp
@@ -0,0 +1,74 @@
+#pragma once
+#include <iostream>
+#include <exception>
+template <typename T>
+class Optional
+{
+ T* data; //DYN MEM
+
+ void copyFrom(const Optional<T>& other);
+ void free();
+public:
+ Optional();
+ Optional(const T& obj);
+
+ bool containsData() const;
+ const T& getData() const;
+ void setData(const T& el);
+ void clear();
+
+
+};
+
+template <typename T>
+Optional<T>::Optional() : data(nullptr)
+{}
+
+template <typename T>
+Optional<T>::Optional(const T& obj) : data(nullptr)
+{
+ setData(obj);
+}
+
+template <typename T>
+bool Optional<T>::containsData() const
+{
+ return data != nullptr;
+}
+
+template <typename T>
+const T& Optional<T>::getData() const
+{
+ if (!containsData())
+ throw std::logic_error("No data in optional");
+ return *data;
+}
+
+template <typename T>
+void Optional<T>::setData(const T& el)
+{
+ delete data;
+ data = new T(el);// copy const;
+}
+
+template <typename T>
+void Optional<T>::copyFrom(const Optional<T>& other)
+{
+ if (other.containsData())
+ data = new T(*other.data);
+ else
+ data = nullptr;
+}
+
+template <typename T>
+void Optional<T>::free()
+{
+ delete data;
+}
+
+template <typename T>
+void Optional<T>::clear()
+{
+ free();
+ data = nullptr;
+}
diff --git a/Sem. 10/Examples/Optional/Source2.cpp b/Sem. 10/Examples/Optional/Source2.cpp
new file mode 100644
index 0000000..7c3e21b
--- /dev/null
+++ b/Sem. 10/Examples/Optional/Source2.cpp
@@ -0,0 +1,19 @@
+#include <iostream>
+#include "Optional.hpp"
+
+
+
+int main()
+{
+ Optional<int> d; //no value
+
+ d.setData(3);
+
+ d.getData();
+
+ d.clear();
+
+
+ std::cout << d.containsData();
+
+}
diff --git a/Sem. 10/Examples/Pair/Pair.hpp b/Sem. 10/Examples/Pair/Pair.hpp
new file mode 100644
index 0000000..adf16b7
--- /dev/null
+++ b/Sem. 10/Examples/Pair/Pair.hpp
@@ -0,0 +1,43 @@
+#pragma once
+
+template<typename T, typename D>
+class Pair
+{
+ T first;
+ D second;
+public:
+ Pair() = default;
+ Pair(const T& first, const D& second);
+ const T& getFirst() const;
+ const D& getSecond() const;
+
+ void setFirst(const T& newValue);
+ void setSecond(const D& newValue);
+};
+
+template<typename T, typename D>
+Pair<T,D>::Pair(const T& first, const D& second) : first(first), second(second)
+{}
+
+template<typename T, typename D>
+const T& Pair<T, D>::getFirst() const
+{
+ return first;
+}
+template<typename T, typename D>
+const D& Pair<T, D>::getSecond() const
+{
+ return second;
+}
+
+template<typename T, typename D>
+void Pair<T, D>::setFirst(const T& newValue)
+{
+ first = newValue;
+}
+
+template<typename T, typename D>
+void Pair<T, D>::setSecond(const D& newValue)
+{
+ second = newValue;
+} \ No newline at end of file
diff --git a/Sem. 10/Examples/Pair/Source2.cpp b/Sem. 10/Examples/Pair/Source2.cpp
new file mode 100644
index 0000000..39229da
--- /dev/null
+++ b/Sem. 10/Examples/Pair/Source2.cpp
@@ -0,0 +1,14 @@
+#include <iostream>
+#include "Pair.hpp"
+
+
+
+int main()
+{
+ Pair<int, char> p(3, 'd');
+
+ std::cout << p.getSecond();
+
+ p.setSecond('a');
+
+}
diff --git a/Sem. 11/Examples/Person/Person.cpp b/Sem. 11/Examples/Person/Person.cpp
new file mode 100644
index 0000000..a0cc714
--- /dev/null
+++ b/Sem. 11/Examples/Person/Person.cpp
@@ -0,0 +1,76 @@
+#pragma once
+#include "Person.h"
+#include <cstring>
+#pragma warning (disable:4996)
+
+
+
+void Person::copyFrom(const Person& other)
+{
+ name = new char[strlen(other.name) + 1];
+ strcpy(name, other.name);
+ age = other.age;
+}
+
+void Person::free()
+{
+ delete[] name;
+}
+
+Person::Person(const char* name, int age)
+{
+ setName(name);
+ setAge(age);
+}
+
+Person::Person(const Person& other)
+{
+ copyFrom(other);
+}
+
+Person& Person::operator=(const Person& other)
+{
+ if (this != &other)
+ {
+ free();
+ copyFrom(other);
+ }
+ return *this;
+}
+const char* Person::getName() const
+{
+ return name;
+}
+
+int Person::getAge() const
+{
+ return age;
+}
+
+void Person::setName(const char* name)
+{
+ if (name == nullptr || this->name == name)
+ return;
+
+ delete[] this->name;
+ size_t nameLen = strlen(name);
+ this->name = new char[nameLen + 1];
+ strcpy(this->name, name);
+}
+
+void Person::setAge(int age)
+{
+ this->age = age;
+}
+
+
+Person::~Person()
+{
+ free();
+}
+
+void Person::print() const
+{
+ std::cout << name << " " << age << std::endl;
+}
+
diff --git a/Sem. 11/Examples/Person/Person.h b/Sem. 11/Examples/Person/Person.h
new file mode 100644
index 0000000..826b671
--- /dev/null
+++ b/Sem. 11/Examples/Person/Person.h
@@ -0,0 +1,27 @@
+#pragma once
+#include <iostream>
+class Person
+{
+ char* name = nullptr;
+ int age = 0;
+
+ void copyFrom(const Person& other);
+ void free();
+
+public:
+ Person() = default;
+ Person(const char* name, int age);
+
+ Person(const Person& other);
+ Person& operator=(const Person& other);
+
+ const char* getName() const;
+ int getAge() const;
+
+ ~Person();
+ void print() const;
+
+protected:
+ void setName(const char* name);
+ void setAge(int age);
+};
diff --git a/Sem. 11/Examples/Source2.cpp b/Sem. 11/Examples/Source2.cpp
new file mode 100644
index 0000000..b6196dd
--- /dev/null
+++ b/Sem. 11/Examples/Source2.cpp
@@ -0,0 +1,10 @@
+#include <iostream>
+#include "Student/Student.h"
+
+
+
+int main()
+{
+ Student s2("Fsdf", 34,4);
+
+}
diff --git a/Sem. 11/Examples/Student/Student.cpp b/Sem. 11/Examples/Student/Student.cpp
new file mode 100644
index 0000000..8b5b04c
--- /dev/null
+++ b/Sem. 11/Examples/Student/Student.cpp
@@ -0,0 +1,34 @@
+#include "Student.h"
+
+Student::Student(const char* name, int age, size_t fn) : Person(name, age)
+{
+ setFn(fn);
+}
+
+size_t Student::getFn() const
+{
+ return fn;
+}
+
+void Student::setFn(size_t fn)
+{
+
+ if (fn < 100)
+ fn = 100;
+ this->fn = fn;
+}
+
+// The compiler will make:
+
+//Student(const Student& other) : Person(other), fn(other.fn), grade(other.grade) OK!!!
+//{}
+
+//Student& operator=(const Student& other) OK!!!!
+//{
+// if (this != &other)
+// {
+// Person::operator=(other); //handles the deletion and copying of the base class
+// fn = other.fn;
+// }
+// return *this;
+//} \ No newline at end of file
diff --git a/Sem. 11/Examples/Student/Student.h b/Sem. 11/Examples/Student/Student.h
new file mode 100644
index 0000000..af99e30
--- /dev/null
+++ b/Sem. 11/Examples/Student/Student.h
@@ -0,0 +1,25 @@
+#include <iostream>
+#include "../Person/Person.h"
+
+class Student : public Person
+{
+ size_t fn = 0;
+ size_t grade = 2;
+public:
+ Student() = default;
+ Student(const char* name, int age, size_t fn);
+
+ size_t getFn() const;
+ void setFn(size_t fn);
+
+
+ // No need for big 4, since there is NO dyn. memory in Student
+ // The compiler will generate valid:
+
+ //Student(const Student& other);
+ //Student& operator=(const Student& other); //no need
+ // ~Student()
+
+ //See on the .cpp file how the compiler creates them
+
+};
diff --git a/homework_1_SI/Домашна_работа_1.pdf b/Utills/homework_1_SI/Домашна_работа_1.pdf
index a7a27ba..a7a27ba 100644
--- a/homework_1_SI/Домашна_работа_1.pdf
+++ b/Utills/homework_1_SI/Домашна_работа_1.pdf
Binary files differ
diff --git a/k_1_SI/task1.cpp b/Utills/k_1_SI/task1.cpp
index 77ad5f5..77ad5f5 100644
--- a/k_1_SI/task1.cpp
+++ b/Utills/k_1_SI/task1.cpp
diff --git a/k_1_SI/task2_read.cpp b/Utills/k_1_SI/task2_read.cpp
index e6a8312..e6a8312 100644
--- a/k_1_SI/task2_read.cpp
+++ b/Utills/k_1_SI/task2_read.cpp
diff --git a/k_1_SI/task2_write.cpp b/Utills/k_1_SI/task2_write.cpp
index f320557..f320557 100644
--- a/k_1_SI/task2_write.cpp
+++ b/Utills/k_1_SI/task2_write.cpp
diff --git a/допълнително упражнение/Source.cpp b/Utills/допълнително упражнение/Source.cpp
index 8845349..17e6f4e 100644
--- a/допълнително упражнение/Source.cpp
+++ b/Utills/допълнително упражнение/Source.cpp
@@ -1,12 +1,12 @@
-#include<iostream>
-#include"chatSystem.h"
-
-int main() {
- chatSystem data;
-
- data.addUser({ "Ivan", "1234", "iv@abv.bg" });
- data.addUser({ "Qvor", "4321", "qv@abv.bg" });
-
- data.sendMessage("last example", "Ivan", "Qvor");
- data.viewMessages("Qvor", "Ivan");
+#include<iostream>
+#include"chatSystem.h"
+
+int main() {
+ chatSystem data;
+
+ data.addUser({ "Ivan", "1234", "iv@abv.bg" });
+ data.addUser({ "Qvor", "4321", "qv@abv.bg" });
+
+ data.sendMessage("last example", "Ivan", "Qvor");
+ data.viewMessages("Qvor", "Ivan");
} \ No newline at end of file
diff --git a/допълнително упражнение/Task1/LogFile.cpp b/Utills/допълнително упражнение/Task1/LogFile.cpp
index 01fa25e..7be397b 100644
--- a/допълнително упражнение/Task1/LogFile.cpp
+++ b/Utills/допълнително упражнение/Task1/LogFile.cpp
@@ -1,92 +1,92 @@
-#include "LogFile.h"
-
-void LogFile::readTime(std::ifstream& inFile, Timestamp& obj) const {
- char isLogin;
-
- inFile >> isLogin;
-
- obj.isLogin = (isLogin == '+');
-
- inFile >> obj.hour >> obj.minutes >> obj.seconds;
-}
-
-
-LogFile::LogFile() {
- size = 0;
-}
-
-LogFile::LogFile(const char* filePath) {
- std::ifstream inFile(filePath);
-
- if (!inFile.is_open()) {
- size = 0;
- return;
- }
-
- inFile >> size;
-
- for (int i = 0; i < size; i++)
- readTime(inFile, data[i]);
-}
-
-
-int LogFile::getLoginsCountAfterHour(short hours, short minutes, short seconds) const {
- int ctr = 0;
- int totalSeconds = hours * 3600 + minutes * 60 + seconds;
- for (int i = 0; i < size; i++) {
- if (data[i].toSeconds() > totalSeconds) {
- ctr = i + 1;
- break;
- }
- }
-
- return size - ctr;
-}
-
-int LogFile::getLoginsCountBetweenHours(short h1, short m1, short s1, short h2, short m2, short s2) const {
- return getLoginsCountAfterHour(h1, m1, s1) - getLoginsCountAfterHour(h2, m2, s2);
-}
-
-int LogFile::getLongestActivePeriod() const {
- int max = 0;
- bool isFirstLogOut = !data[0].isLogin;
- bool isLastLogIn = data[size - 1].isLogin;
-
- if (isFirstLogOut)
- max = data[0].toSeconds();
-
- if (isLastLogIn) {
- int lastTimeInterval = 23 * 3600 + 59 * 60 + 59 - data[size - 1].toSeconds();
-
- if (max < lastTimeInterval)
- max = lastTimeInterval;
- }
-
- for (int i = isFirstLogOut; i < size - isLastLogIn; i += 2) {
- int diff = data[i + 1].toSeconds() - data[i].toSeconds();
- if (diff > max)
- max = diff;
- }
-
- return max;
-}
-
-bool LogFile::loggedInHour(int hour) const {
- int left = 0;
- int right = size-1;
-
- while (left <= right) {
- int mid = left + (right - left) / 2;
- if (hour == data[mid].hour) {
- return true;
- }
-
- if (hour < data[mid].hour) {
- right = mid - 1;
- }
- else {
- left = mid + 1;
- }
- }
- return false;
+#include "LogFile.h"
+
+void LogFile::readTime(std::ifstream& inFile, Timestamp& obj) const {
+ char isLogin;
+
+ inFile >> isLogin;
+
+ obj.isLogin = (isLogin == '+');
+
+ inFile >> obj.hour >> obj.minutes >> obj.seconds;
+}
+
+
+LogFile::LogFile() {
+ size = 0;
+}
+
+LogFile::LogFile(const char* filePath) {
+ std::ifstream inFile(filePath);
+
+ if (!inFile.is_open()) {
+ size = 0;
+ return;
+ }
+
+ inFile >> size;
+
+ for (int i = 0; i < size; i++)
+ readTime(inFile, data[i]);
+}
+
+
+int LogFile::getLoginsCountAfterHour(short hours, short minutes, short seconds) const {
+ int ctr = 0;
+ int totalSeconds = hours * 3600 + minutes * 60 + seconds;
+ for (int i = 0; i < size; i++) {
+ if (data[i].toSeconds() > totalSeconds) {
+ ctr = i + 1;
+ break;
+ }
+ }
+
+ return size - ctr;
+}
+
+int LogFile::getLoginsCountBetweenHours(short h1, short m1, short s1, short h2, short m2, short s2) const {
+ return getLoginsCountAfterHour(h1, m1, s1) - getLoginsCountAfterHour(h2, m2, s2);
+}
+
+int LogFile::getLongestActivePeriod() const {
+ int max = 0;
+ bool isFirstLogOut = !data[0].isLogin;
+ bool isLastLogIn = data[size - 1].isLogin;
+
+ if (isFirstLogOut)
+ max = data[0].toSeconds();
+
+ if (isLastLogIn) {
+ int lastTimeInterval = 23 * 3600 + 59 * 60 + 59 - data[size - 1].toSeconds();
+
+ if (max < lastTimeInterval)
+ max = lastTimeInterval;
+ }
+
+ for (int i = isFirstLogOut; i < size - isLastLogIn; i += 2) {
+ int diff = data[i + 1].toSeconds() - data[i].toSeconds();
+ if (diff > max)
+ max = diff;
+ }
+
+ return max;
+}
+
+bool LogFile::loggedInHour(int hour) const {
+ int left = 0;
+ int right = size-1;
+
+ while (left <= right) {
+ int mid = left + (right - left) / 2;
+ if (hour == data[mid].hour) {
+ return true;
+ }
+
+ if (hour < data[mid].hour) {
+ right = mid - 1;
+ }
+ else {
+ left = mid + 1;
+ }
+ }
+ return false;
} \ No newline at end of file
diff --git a/допълнително упражнение/Task1/LogFile.h b/Utills/допълнително упражнение/Task1/LogFile.h
index 8c021f8..258c7d5 100644
--- a/допълнително упражнение/Task1/LogFile.h
+++ b/Utills/допълнително упражнение/Task1/LogFile.h
@@ -1,24 +1,24 @@
-#pragma once
-#include<fstream>
-#include "Timestamp.h"
-const int MAX_FILE_SIZE = 100;
-class LogFile {
-private:
- size_t size;
- Timestamp data[MAX_FILE_SIZE];
-
- void readTime(std::ifstream& inFile, Timestamp& obj) const;
-
-public:
- LogFile();
-
- LogFile(const char* filePath);
-
- int getLoginsCountAfterHour(short hours, short minutes, short seconds) const;
-
- int getLoginsCountBetweenHours(short h1, short m1, short s1, short h2, short m2, short s2) const;
-
- int getLongestActivePeriod() const;
-
- bool loggedInHour(int hour) const;
+#pragma once
+#include<fstream>
+#include "Timestamp.h"
+const int MAX_FILE_SIZE = 100;
+class LogFile {
+private:
+ size_t size;
+ Timestamp data[MAX_FILE_SIZE];
+
+ void readTime(std::ifstream& inFile, Timestamp& obj) const;
+
+public:
+ LogFile();
+
+ LogFile(const char* filePath);
+
+ int getLoginsCountAfterHour(short hours, short minutes, short seconds) const;
+
+ int getLoginsCountBetweenHours(short h1, short m1, short s1, short h2, short m2, short s2) const;
+
+ int getLongestActivePeriod() const;
+
+ bool loggedInHour(int hour) const;
}; \ No newline at end of file
diff --git a/допълнително упражнение/Task1/Timestamp.cpp b/Utills/допълнително упражнение/Task1/Timestamp.cpp
index a874eb8..28ff933 100644
--- a/допълнително упражнение/Task1/Timestamp.cpp
+++ b/Utills/допълнително упражнение/Task1/Timestamp.cpp
@@ -1,5 +1,5 @@
-#include "Timestamp.h"
-
-int Timestamp::toSeconds() const{
- return hour * 3600 + minutes * 60 + seconds;
+#include "Timestamp.h"
+
+int Timestamp::toSeconds() const{
+ return hour * 3600 + minutes * 60 + seconds;
} \ No newline at end of file
diff --git a/допълнително упражнение/Task1/Timestamp.h b/Utills/допълнително упражнение/Task1/Timestamp.h
index 912d69a..e437187 100644
--- a/допълнително упражнение/Task1/Timestamp.h
+++ b/Utills/допълнително упражнение/Task1/Timestamp.h
@@ -1,9 +1,9 @@
-#pragma once
-struct Timestamp {
- bool isLogin;
- unsigned short hour;
- unsigned short minutes;
- unsigned short seconds;
-
- int toSeconds() const;
+#pragma once
+struct Timestamp {
+ bool isLogin;
+ unsigned short hour;
+ unsigned short minutes;
+ unsigned short seconds;
+
+ int toSeconds() const;
}; \ No newline at end of file
diff --git a/допълнително упражнение/User.cpp b/Utills/допълнително упражнение/User.cpp
index 7f5a53d..998b91f 100644
--- a/допълнително упражнение/User.cpp
+++ b/Utills/допълнително упражнение/User.cpp
@@ -1,97 +1,97 @@
-#include "User.h"
-#include<cstring>
-#include<fstream>
-#include<iostream>
-
-#pragma warning(disable : 4996)
-
-void generatePath(char* path, const char* bigger, const char* smaller) {
- strcpy(path, bigger);
- strcat(path, "-");
- strcat(path, smaller);
- strcat(path, ".bat");
-}
-
-void User::createFileName(char* fileName, const User& other) const {
- if (strcmp(name, other.name) == 1) {
- generatePath(fileName, name, other.name);
- }
- else {
- generatePath(fileName, other.name, name);
- }
-}
-
-User::User() : name(""), password(""), email(""){}
-
-User::User(const char* n, const char* pass, const char* mail) {
- if (strlen(n) > NAME_LEN || strlen(pass) > PASS_LEN || strlen(mail) > MAIL_LEN) {
- strcpy(name, "");
- strcpy(password, "");
- strcpy(email, "");
-
- return;
- }
-
- strcpy(name, n);
- strcpy(password, pass);
- strcpy(email, mail);
-}
-
-void User::sendMessage(const char* message, const User& other) const {
- char filePath[50];
- createFileName(filePath, other);
-
- std::ofstream outFile(filePath, std::ios::binary | std::ios::app);
-
- if (!outFile.is_open())
- return;
-
- outFile.write(name, sizeof(name));
-
- int length = strlen(message);
-
- outFile.write((const char*)&length, sizeof(length));
-
- outFile.write(message, length);
-
- outFile.close();
-}
-
-void User::viewMessage(const User& other) const {
- char filePath[50];
- createFileName(filePath, other);
-
- std::ifstream inFile(filePath, std::ios::binary);
-
- if (!inFile.is_open())
- return;
-
- char buff[NAME_LEN + 1];
-
- while (!inFile.eof()) {
- inFile.read(buff, sizeof(buff));
-
- if (inFile.eof())
- return;
-
- int length = 0;
-
- inFile.read((char*)&length, sizeof(length));
-
- char* msg = new char[length + 1];
-
- inFile.read(msg, length);
-
- msg[length] = '\0';
-
- std::cout << buff << ": " << msg << std::endl;
-
- delete[] msg;
- }
-
- inFile.close();
-}
-
-const char* User::getName() const {
- return name;
-}
+#include "User.h"
+#include<cstring>
+#include<fstream>
+#include<iostream>
+
+#pragma warning(disable : 4996)
+
+void generatePath(char* path, const char* bigger, const char* smaller) {
+ strcpy(path, bigger);
+ strcat(path, "-");
+ strcat(path, smaller);
+ strcat(path, ".bat");
+}
+
+void User::createFileName(char* fileName, const User& other) const {
+ if (strcmp(name, other.name) == 1) {
+ generatePath(fileName, name, other.name);
+ }
+ else {
+ generatePath(fileName, other.name, name);
+ }
+}
+
+User::User() : name(""), password(""), email(""){}
+
+User::User(const char* n, const char* pass, const char* mail) {
+ if (strlen(n) > NAME_LEN || strlen(pass) > PASS_LEN || strlen(mail) > MAIL_LEN) {
+ strcpy(name, "");
+ strcpy(password, "");
+ strcpy(email, "");
+
+ return;
+ }
+
+ strcpy(name, n);
+ strcpy(password, pass);
+ strcpy(email, mail);
+}
+
+void User::sendMessage(const char* message, const User& other) const {
+ char filePath[50];
+ createFileName(filePath, other);
+
+ std::ofstream outFile(filePath, std::ios::binary | std::ios::app);
+
+ if (!outFile.is_open())
+ return;
+
+ outFile.write(name, sizeof(name));
+
+ int length = strlen(message);
+
+ outFile.write((const char*)&length, sizeof(length));
+
+ outFile.write(message, length);
+
+ outFile.close();
+}
+
+void User::viewMessage(const User& other) const {
+ char filePath[50];
+ createFileName(filePath, other);
+
+ std::ifstream inFile(filePath, std::ios::binary);
+
+ if (!inFile.is_open())
+ return;
+
+ char buff[NAME_LEN + 1];
+
+ while (!inFile.eof()) {
+ inFile.read(buff, sizeof(buff));
+
+ if (inFile.eof())
+ return;
+
+ int length = 0;
+
+ inFile.read((char*)&length, sizeof(length));
+
+ char* msg = new char[length + 1];
+
+ inFile.read(msg, length);
+
+ msg[length] = '\0';
+
+ std::cout << buff << ": " << msg << std::endl;
+
+ delete[] msg;
+ }
+
+ inFile.close();
+}
+
+const char* User::getName() const {
+ return name;
+}
diff --git a/допълнително упражнение/User.h b/Utills/допълнително упражнение/User.h
index ab729cd..4f94c7f 100644
--- a/допълнително упражнение/User.h
+++ b/Utills/допълнително упражнение/User.h
@@ -1,26 +1,26 @@
-#pragma once
-
-const int NAME_LEN = 20;
-const int MAIL_LEN = 12;
-const int PASS_LEN = 8;
-
-class User {
-private:
- // N символа за име +1 за терминираща нула!
- char name[NAME_LEN + 1];
- char password[PASS_LEN + 1];
- char email[MAIL_LEN + 1];
-
- void createFileName(char* fileName, const User& other) const;
-public:
- User();
-
- User(const char* n, const char* pass, const char* email);
-
- void sendMessage(const char* message, const User& u) const;
-
- void viewMessage(const User& u) const;
-
- const char* getName() const;
-};
-
+#pragma once
+
+const int NAME_LEN = 20;
+const int MAIL_LEN = 12;
+const int PASS_LEN = 8;
+
+class User {
+private:
+ // N символа за име +1 за терминираща нула!
+ char name[NAME_LEN + 1];
+ char password[PASS_LEN + 1];
+ char email[MAIL_LEN + 1];
+
+ void createFileName(char* fileName, const User& other) const;
+public:
+ User();
+
+ User(const char* n, const char* pass, const char* email);
+
+ void sendMessage(const char* message, const User& u) const;
+
+ void viewMessage(const User& u) const;
+
+ const char* getName() const;
+};
+
diff --git a/допълнително упражнение/chatSystem.cpp b/Utills/допълнително упражнение/chatSystem.cpp
index 416b1f8..c982451 100644
--- a/допълнително упражнение/chatSystem.cpp
+++ b/Utills/допълнително упражнение/chatSystem.cpp
@@ -1,80 +1,80 @@
-#include "chatSystem.h"
-#include<cstring>
-#include<fstream>
-
-void chatSystem::save() const {
- std::ofstream outFile(FILE_PATH, std::ios::binary);
-
- outFile.write((const char*)this, sizeof(chatSystem));
-}
-
-void chatSystem::read() {
- std::ifstream inFile(FILE_PATH, std::ios::binary);
-
- inFile.read((char*)this, sizeof(chatSystem));
-}
-
-void chatSystem::searchIndexes(int& firstIndex, int& secondIndex, const char* fstName, const char* sndName) const {
- for (int i = 0; i < size; i++) {
- if (strcmp(fstName, data[i].getName()) == 0) {
- firstIndex = i;
- }
-
- if (strcmp(sndName, data[i].getName()) == 0) {
- secondIndex = i;
- }
-
- if (firstIndex != -1 && secondIndex != -1)
- break;
- }
-}
-
-chatSystem::chatSystem() {
- size = 0;
- read();
-}
-
-void chatSystem::addUser(const User& arg) {
- if (size > 99)
- return;
-
- for (int i = 0; i < size; i++) {
- if (strcmp(arg.getName(), data[i].getName()) == 0) {
- return;
- }
- }
-
- data[size++] = arg;
-}
-
-void chatSystem::sendMessage(const char* msg, const char* fstName, const char* sndName) const {
- int firstIndex = -1;
- int secondIndex = -1;
-
- searchIndexes(firstIndex, secondIndex, fstName, sndName);
-
- if (firstIndex == -1 || secondIndex == -1)
- return;
-
- data[firstIndex].sendMessage(msg, data[secondIndex]);
-}
-
-void chatSystem::viewMessages(const char* fstName, const char* sndName) const {
- int firstIndex = -1;
- int secondIndex = -1;
-
- searchIndexes(firstIndex, secondIndex, fstName, sndName);
-
- if (firstIndex == -1 || secondIndex == -1)
- return;
-
- data[firstIndex].viewMessage(data[secondIndex]);
-}
-
-int chatSystem::getSize() const {
- return size;
-}
-
-chatSystem::~chatSystem() {
- save();
-}
+#include "chatSystem.h"
+#include<cstring>
+#include<fstream>
+
+void chatSystem::save() const {
+ std::ofstream outFile(FILE_PATH, std::ios::binary);
+
+ outFile.write((const char*)this, sizeof(chatSystem));
+}
+
+void chatSystem::read() {
+ std::ifstream inFile(FILE_PATH, std::ios::binary);
+
+ inFile.read((char*)this, sizeof(chatSystem));
+}
+
+void chatSystem::searchIndexes(int& firstIndex, int& secondIndex, const char* fstName, const char* sndName) const {
+ for (int i = 0; i < size; i++) {
+ if (strcmp(fstName, data[i].getName()) == 0) {
+ firstIndex = i;
+ }
+
+ if (strcmp(sndName, data[i].getName()) == 0) {
+ secondIndex = i;
+ }
+
+ if (firstIndex != -1 && secondIndex != -1)
+ break;
+ }
+}
+
+chatSystem::chatSystem() {
+ size = 0;
+ read();
+}
+
+void chatSystem::addUser(const User& arg) {
+ if (size > 99)
+ return;
+
+ for (int i = 0; i < size; i++) {
+ if (strcmp(arg.getName(), data[i].getName()) == 0) {
+ return;
+ }
+ }
+
+ data[size++] = arg;
+}
+
+void chatSystem::sendMessage(const char* msg, const char* fstName, const char* sndName) const {
+ int firstIndex = -1;
+ int secondIndex = -1;
+
+ searchIndexes(firstIndex, secondIndex, fstName, sndName);
+
+ if (firstIndex == -1 || secondIndex == -1)
+ return;
+
+ data[firstIndex].sendMessage(msg, data[secondIndex]);
+}
+
+void chatSystem::viewMessages(const char* fstName, const char* sndName) const {
+ int firstIndex = -1;
+ int secondIndex = -1;
+
+ searchIndexes(firstIndex, secondIndex, fstName, sndName);
+
+ if (firstIndex == -1 || secondIndex == -1)
+ return;
+
+ data[firstIndex].viewMessage(data[secondIndex]);
+}
+
+int chatSystem::getSize() const {
+ return size;
+}
+
+chatSystem::~chatSystem() {
+ save();
+}
diff --git a/допълнително упражнение/chatSystem.h b/Utills/допълнително упражнение/chatSystem.h
index cf7332a..1f21bf3 100644
--- a/допълнително упражнение/chatSystem.h
+++ b/Utills/допълнително упражнение/chatSystem.h
@@ -1,31 +1,31 @@
-#pragma once
-#include"User.h"
-
-const char FILE_PATH[] = "database.bat";
-
-class chatSystem {
-private:
- User data[100];
- size_t size;
-
- void save() const;
-
- void read();
-
- void searchIndexes(int& firstIndex, int& secondIndex, const char* fstName, const char* sndName) const;
-
-public:
- chatSystem();
-
- void addUser(const User& arg);
-
- void sendMessage(const char* msg, const char* fstName, const char* sndName) const;
-
- void viewMessages(const char* sender, const char* reciever) const;
-
- int getSize() const;
-
- ~chatSystem();
-
-};
-
+#pragma once
+#include"User.h"
+
+const char FILE_PATH[] = "database.bat";
+
+class chatSystem {
+private:
+ User data[100];
+ size_t size;
+
+ void save() const;
+
+ void read();
+
+ void searchIndexes(int& firstIndex, int& secondIndex, const char* fstName, const char* sndName) const;
+
+public:
+ chatSystem();
+
+ void addUser(const User& arg);
+
+ void sendMessage(const char* msg, const char* fstName, const char* sndName) const;
+
+ void viewMessages(const char* sender, const char* reciever) const;
+
+ int getSize() const;
+
+ ~chatSystem();
+
+};
+
diff --git a/допълнително упражнение/задачи за допълнително упражнение СИ.pdf b/Utills/допълнително упражнение/задачи за допълнително упражнение СИ.pdf
index 111878f..111878f 100644
--- a/допълнително упражнение/задачи за допълнително упражнение СИ.pdf
+++ b/Utills/допълнително упражнение/задачи за допълнително упражнение СИ.pdf
Binary files differ
diff --git a/допълнително упражнение/функции от по - висок ред/demo.cpp b/Utills/допълнително упражнение/функции от по - висок ред/demo.cpp
index d5e5e4e..951b7d2 100644
--- a/допълнително упражнение/функции от по - висок ред/demo.cpp
+++ b/Utills/допълнително упражнение/функции от по - висок ред/demo.cpp
@@ -1,89 +1,89 @@
-#include<iostream>
-#include<vector>
-
-template<class T>
-class Entity {
-private:
- int integerData;
- char symbolData;
- T abstractData;
-
-public:
- Entity(int iArg, char cArg, const T& aArg) : integerData(iArg), symbolData(cArg), abstractData(aArg) {}
-
- int getIntegerData() const {
- return integerData;
- }
-
- char getCharData() const {
- return symbolData;
- }
-
- const T& getAbstractData() const {
- return abstractData;
- }
-
- void print() const {
- std::cout << integerData << " " << symbolData << " " << abstractData << std::endl;
- }
-};
-
-template<class T>
-bool compareIntegerValues(const Entity<T>& fst, const Entity<T>& snd) {
- return fst.getIntegerData() < snd.getIntegerData();
-}
-
-template<class T>
-bool compareCharValues(const Entity<T>& fst, const Entity<T>& snd) {
- return fst.getCharData() < snd.getCharData();
-}
-
-template<class T>
-bool compareAbstractValues(const Entity<T>& fst, const Entity<T>& snd) {
- return fst.getAbstractData() < snd.getAbstractData();
-}
-
-template<class T>
-void sort(std::vector<Entity<T>>& collection, bool (*lessThan)(const Entity<T>&, const Entity<T>&)) {
- for (size_t i = 0; i < collection.size(); i++) {
- size_t minElementIndex = i;
-
- for (size_t j = i + 1; j < collection.size(); j++) {
- if (lessThan(collection[j], collection[minElementIndex])) {
- minElementIndex = j;
- }
- }
-
- if (minElementIndex != i)
- std::swap(collection[i], collection[minElementIndex]);
- }
-}
-
-char generateRandomLetter() {
- return (char)(rand() % 26 + 'a');
-}
-
-double generateRandomDouble() {
- return (double)rand() / RAND_MAX + rand() % 256;
-}
-
-int main() {
- std::vector<Entity<double>> collection;
-
- for (size_t i = 0; i < 100; i++)
- collection.push_back({ rand() % 10000, generateRandomLetter(), generateRandomDouble() });
-
-
- // Sort integer values
- // sort(collection, compareIntegerValues);
-
- // Sort char values
- // sort(collection, compareCharValues);
-
- // Sort abstract values
- sort(collection, compareAbstractValues);
-
-
- for (size_t i = 0; i < 100; i++)
- collection[i].print();
-}
+#include<iostream>
+#include<vector>
+
+template<class T>
+class Entity {
+private:
+ int integerData;
+ char symbolData;
+ T abstractData;
+
+public:
+ Entity(int iArg, char cArg, const T& aArg) : integerData(iArg), symbolData(cArg), abstractData(aArg) {}
+
+ int getIntegerData() const {
+ return integerData;
+ }
+
+ char getCharData() const {
+ return symbolData;
+ }
+
+ const T& getAbstractData() const {
+ return abstractData;
+ }
+
+ void print() const {
+ std::cout << integerData << " " << symbolData << " " << abstractData << std::endl;
+ }
+};
+
+template<class T>
+bool compareIntegerValues(const Entity<T>& fst, const Entity<T>& snd) {
+ return fst.getIntegerData() < snd.getIntegerData();
+}
+
+template<class T>
+bool compareCharValues(const Entity<T>& fst, const Entity<T>& snd) {
+ return fst.getCharData() < snd.getCharData();
+}
+
+template<class T>
+bool compareAbstractValues(const Entity<T>& fst, const Entity<T>& snd) {
+ return fst.getAbstractData() < snd.getAbstractData();
+}
+
+template<class T>
+void sort(std::vector<Entity<T>>& collection, bool (*lessThan)(const Entity<T>&, const Entity<T>&)) {
+ for (size_t i = 0; i < collection.size(); i++) {
+ size_t minElementIndex = i;
+
+ for (size_t j = i + 1; j < collection.size(); j++) {
+ if (lessThan(collection[j], collection[minElementIndex])) {
+ minElementIndex = j;
+ }
+ }
+
+ if (minElementIndex != i)
+ std::swap(collection[i], collection[minElementIndex]);
+ }
+}
+
+char generateRandomLetter() {
+ return (char)(rand() % 26 + 'a');
+}
+
+double generateRandomDouble() {
+ return (double)rand() / RAND_MAX + rand() % 256;
+}
+
+int main() {
+ std::vector<Entity<double>> collection;
+
+ for (size_t i = 0; i < 100; i++)
+ collection.push_back({ rand() % 10000, generateRandomLetter(), generateRandomDouble() });
+
+
+ // Sort integer values
+ // sort(collection, compareIntegerValues);
+
+ // Sort char values
+ // sort(collection, compareCharValues);
+
+ // Sort abstract values
+ sort(collection, compareAbstractValues);
+
+
+ for (size_t i = 0; i < 100; i++)
+ collection[i].print();
+}