Website Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commit42f59920cf5d300a54f3dae03911dccbd1a86eea (patch)
Author
 angeld55 <angel_dimitriev@abv.bg>
2021-05-12 19:47:03 +0300
Committer
 angeld55 <angel_dimitriev@abv.bg>
2021-05-12 19:47:03 +0300
Files35e54cfd62d1f71b8c6b69d5cabcef3c2a752531
Object-oriented_programming_FMI-42f59920cf5d300a54f3dae03911dccbd1a86eea.tar
Object-oriented_programming_FMI-42f59920cf5d300a54f3dae03911dccbd1a86eea.tar.gz
Object-oriented_programming_FMI-42f59920cf5d300a54f3dae03911dccbd1a86eea.zip
Parent75256f8ad62bf73362566fb1484ddd5218774f30 (diff)
sem 11 + split sem 10
7 files changed, 151 insertions, 0 deletions
-rw-r--r--Sem. 10/README.md0
-rw-r--r--Sem. 10/task1/Queue.hpp (renamed from Sem. 09/task2/Queue.hpp)0
-rw-r--r--Sem. 10/task1/main.cpp (renamed from Sem. 09/task2/main.cpp)0
-rw-r--r--Sem. 11/README.md0
-rw-r--r--Sem. 11/example/Person.cpp99
-rw-r--r--Sem. 11/example/Person.h35
-rw-r--r--Sem. 11/example/main.cpp17
diff --git a/Sem. 10/README.md b/Sem. 10/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Sem. 10/README.md
diff --git a/Sem. 09/task2/Queue.hpp b/Sem. 10/task1/Queue.hpp
index 1f7f854..1f7f854 100644
--- a/Sem. 09/task2/Queue.hpp
+++ b/Sem. 10/task1/Queue.hpp
diff --git a/Sem. 09/task2/main.cpp b/Sem. 10/task1/main.cpp
index e52579a..e52579a 100644
--- a/Sem. 09/task2/main.cpp
+++ b/Sem. 10/task1/main.cpp
diff --git a/Sem. 11/README.md b/Sem. 11/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Sem. 11/README.md
diff --git a/Sem. 11/example/Person.cpp b/Sem. 11/example/Person.cpp
new file mode 100644
index 0000000..ae78280
--- /dev/null
+++ b/Sem. 11/example/Person.cpp
@@ -0,0 +1,99 @@
+#include "Person.h"
+#include <iostream>
+
+using namespace std;
+
+Person::Person() : Person("Unknown", 0)
+{
+
+}
+Person::Person(const char* name, int age) : name(nullptr), age(age)
+{
+ cout << "Constr" << endl;
+ setName(name);
+ setAge(age);
+}
+
+Person::Person(const Person& other)
+{
+ cout << "copy constr" << endl;
+ copyFrom(other);
+}
+Person::Person(Person&& other)
+{
+ cout << "Move constr" << endl;
+
+ name = other.name;
+ age = other.age;
+
+ other.name = nullptr;
+}
+
+Person& Person::operator=(Person&& other)
+{
+
+ std::cout << "Move op= " << endl;
+ if (this != &other)
+ {
+ free();
+
+ name = other.name;
+ other.name = nullptr;
+
+ age = other.age;
+
+ }
+ return *this;
+}
+
+Person& Person::operator = (const Person& other)
+{
+ cout << "op =" << endl;
+ if (this != &other)
+ {
+ free();
+ copyFrom(other);
+ }
+ return *this;
+}
+Person::~Person()
+{
+ cout << "Destructor" << endl;
+ free();
+}
+
+const char* Person::getName() const
+{
+ return name;
+}
+
+int Person::getAge() const
+{
+ return age;
+}
+
+void Person::setName(const char* name)
+{
+ delete[] this->name;
+ this->name = new char[strlen(name) + 1];
+ strcpy(this->name, name);
+}
+void Person::setAge(int age)
+{
+ if (age < 0 || age > 120)
+ age = 40;
+ this->age = age;
+}
+
+void Person::copyFrom(const Person& other)
+{
+ name = new char[strlen(other.name) + 1];
+ strcpy(name, other.name);
+
+ age = other.age;
+}
+void Person::free()
+{
+ delete[] name;
+ age = 0;
+} \ No newline at end of file
diff --git a/Sem. 11/example/Person.h b/Sem. 11/example/Person.h
new file mode 100644
index 0000000..9a404c4
--- /dev/null
+++ b/Sem. 11/example/Person.h
@@ -0,0 +1,35 @@
+#pragma once
+
+class Person
+{
+public:
+ Person();
+ Person(const char* name, int age);
+
+ Person(const Person& other);
+
+ Person(Person&& other); //move constr
+
+ Person& operator=(Person&& other); // move op=
+
+ Person& operator=(const Person& other);
+ ~Person();
+
+ void setName(const char* name);
+ void setAge(int age);
+
+ const char* getName() const;
+ int getAge() const;
+
+ void print();
+
+
+private:
+
+ void copyFrom(const Person& other);
+ void free();
+
+
+ char* name;
+ int age;
+}; \ No newline at end of file
diff --git a/Sem. 11/example/main.cpp b/Sem. 11/example/main.cpp
new file mode 100644
index 0000000..a7a00f6
--- /dev/null
+++ b/Sem. 11/example/main.cpp
@@ -0,0 +1,17 @@
+#include<iostream>
+#include<iostream>
+#include "Person.h"
+using namespace std;
+
+Person createPerson(const char* name, int age)
+{
+ Person p(name, age);
+
+ return p;
+}
+
+int main()
+{
+ Person p2("Petur",18);
+ p2 = createPerson("Ivan", 23);
+} \ No newline at end of file