blob: 41d4ea305e1af1c49527244748c4e350b69c1fa5 (
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
|
#include <algorithm>
#include <utility>
#include "Zoo.hh"
namespace zoo {
Zoo::~Zoo() {
delete[] this->exhibits;
delete[] this->cages;
}
void Zoo::setExhibit(std::string exhibit) {
auto *newExhibits =
new std::string[static_cast<unsigned long>(this->numExhibits + 1)];
std::copy(this->exhibits,
this->exhibits + static_cast<unsigned long>(this->numExhibits),
newExhibits);
delete[] this->exhibits;
this->exhibits = newExhibits;
this->exhibits[this->numExhibits] = std::move(exhibit);
this->incrementNumExhibits();
}
void Zoo::setCage(int cageNumber) {
int *newCages = new int[static_cast<unsigned long>(this->numCages + 1)];
std::copy(this->cages,
this->cages + static_cast<unsigned long>(this->numCages), newCages);
delete[] this->cages;
this->cages = newCages;
this->cages[this->numCages] = cageNumber;
this->incrementNumCages();
}
std::string *Zoo::getExhibit(std::size_t exhibitIndex) {
return &this->exhibits[exhibitIndex];
}
int *Zoo::getCage(std::size_t cageIndex) { return &this->cages[cageIndex]; }
int Zoo::getNumExhibits() const { return this->numExhibits; }
int Zoo::getNumCages() const { return this->numCages; }
void Zoo::incrementNumExhibits() { this->numExhibits += 1; }
void Zoo::incrementNumCages() { this->numCages += 1; }
} // namespace zoo
|