blob: d78ee6df08b50b145b853cf9750737c98bab1cdd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
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;
}
|