-
Notifications
You must be signed in to change notification settings - Fork 0
/
member_single_argument_minus_operator.cpp
80 lines (58 loc) · 1.45 KB
/
member_single_argument_minus_operator.cpp
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
#include <iostream>
class Folder {
public:
Folder(int folder_capacity = 3): capacity(folder_capacity) {
files = new std::string[capacity];
}
Folder(const Folder &folder_pattern): capacity(folder_pattern.capacity) {
files = new std::string[folder_pattern.capacity];
for (int i = 0; i < folder_pattern.capacity; i++) {
files[i] = folder_pattern.files[i];
}
}
~Folder() {
delete [] files;
}
int getCapacity() const {
return capacity;
}
std::string getFile(int index) const {
std::string result_file = "";
if (index < capacity)
result_file = files[index];
return result_file;
}
void show() {
for (int i = 0; i < capacity; i++) {
std::cout << files[i] << std::endl;
}
}
void putFile(int index, std::string file) {
if (index >= capacity)
return;
files[index] = file;
}
Folder operator-() const;
private:
const int capacity;
std::string *files;
};
Folder Folder::operator-() const {
Folder result_folder(getCapacity());
for(int i = 0; i < getCapacity(); i++) {
std::string file = getFile(getCapacity() - 1 - i);
result_folder.putFile(i, file);
}
return result_folder;
}
int main() {
Folder briefcase;
briefcase.putFile(0, "document");
briefcase.putFile(1, "blueprint");
briefcase.putFile(2, "photo");
briefcase.show();
std::cout << std::endl;
Folder second_case = -briefcase;
second_case.show();
std::cout << std::endl;
}