aboutsummaryrefslogtreecommitdiff
path: root/week12/Exercise4/Manager.cpp
diff options
context:
space:
mode:
authorSyndamia <kamen@syndamia.com>2024-05-10 12:27:14 +0300
committerSyndamia <kamen@syndamia.com>2024-05-10 12:27:14 +0300
commiteb6305c8b0a71a613a34edbcabdaf1fde259451d (patch)
tree2ba4402c82569810ab4287175670193597cc52d4 /week12/Exercise4/Manager.cpp
parent8dd9b39fa54a91030cdd5fe71973f78f7e8089e0 (diff)
downloadoop-2023-solutions-eb6305c8b0a71a613a34edbcabdaf1fde259451d.tar
oop-2023-solutions-eb6305c8b0a71a613a34edbcabdaf1fde259451d.tar.gz
oop-2023-solutions-eb6305c8b0a71a613a34edbcabdaf1fde259451d.zip
[w12] Finished ex 4
Diffstat (limited to 'week12/Exercise4/Manager.cpp')
-rw-r--r--week12/Exercise4/Manager.cpp98
1 files changed, 98 insertions, 0 deletions
diff --git a/week12/Exercise4/Manager.cpp b/week12/Exercise4/Manager.cpp
new file mode 100644
index 0000000..d78ee6d
--- /dev/null
+++ b/week12/Exercise4/Manager.cpp
@@ -0,0 +1,98 @@
+#include "Manager.h"
+
+void Manager::resize() {
+ allocated *= 2;
+ Person* moreManages = new Person[allocated];
+ for (int i = 0; i < size; i++) {
+ moreManages[i] = manages[i];
+ }
+ delete[] manages;
+ manages = moreManages;
+}
+
+void Manager::free() {
+ delete[] manages;
+}
+
+void Manager::copyFrom(const Manager& other) {
+ this->size = other.size;
+ this->allocated = other.allocated;
+ this->manages = new Person[allocated + 1];
+ for (int i = 0; i < size; i++) {
+ manages[i] = other.manages[i];
+ }
+}
+
+Manager::Manager() {
+ manages = nullptr;
+ size = allocated = 0;
+}
+
+Manager::~Manager() {
+ free();
+}
+
+Manager::Manager(const Manager& other) {
+ copyFrom(other);
+}
+
+Manager& Manager::operator=(const Manager& other) {
+ if (this != &other) {
+ free();
+ copyFrom(other);
+ }
+ return *this;
+}
+
+Manager::Manager(Manager&& other) {
+ this->allocated = other.allocated;
+ this->size = other.size;
+ this->manages = other.manages;
+ other.manages = nullptr;
+}
+
+Manager& Manager::operator=(Manager&& other) {
+ if (this != &other) {
+ free();
+
+ this->allocated = other.allocated;
+ this->size = other.size;
+ this->manages = other.manages;
+ other.manages = nullptr;
+ }
+ return *this;
+}
+
+void Manager::StartManaging(Person& newEmp) {
+ for (int i = 0; i < size; i++) {
+ if (manages[i] == newEmp) {
+ throw "Person already managed!";
+ }
+ }
+
+ if (size >= allocated) {
+ resize();
+ }
+ manages[size++] = newEmp;
+}
+
+void Manager::StopManaging(const Person& oldEmp) {
+ int i;
+ for (i = 0; i < size; i++) {
+ if (manages[i] == oldEmp) {
+ break;
+ }
+ }
+ if (i == size) {
+ throw "Not managing employee!";
+ }
+
+ for (; i < size - 1; i++) {
+ manages[i] = manages[i+1];
+ }
+ size--;
+}
+
+float Manager::Workload() {
+ return 0.6 * size;
+}