-
Notifications
You must be signed in to change notification settings - Fork 0
/
Fruit.cpp
49 lines (39 loc) · 980 Bytes
/
Fruit.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
#include "Fruit.hpp"
#include <stdexcept>
Fruit::Fruit(const std::string& name, size_t amount, size_t basePrice)
: Cargo(name, amount, basePrice)
{}
size_t Fruit::getPrice() const {
return basePrice_ * (rottenTime_ / DAYS_TO_ROTTEN);
}
Cargo& Fruit::operator+=(const size_t amount) {
if (amount_ + amount > MAX_AMOUNT_OF_CARGO) {
throw std::out_of_range("Maximum amount of fruits reached!");
}
amount_ += amount;
return *this;
}
Cargo& Fruit::operator-=(const size_t amount) {
if (amount <= amount_) {
amount_ -= amount;
}
return *this;
}
bool Fruit::operator==(const Cargo& cargo) const {
if (cargo.getName() == name_ && cargo.getBasePrice() == basePrice_) {
return true;
}
return false;
}
void Fruit::nextDay() {
operator--();
}
Fruit& Fruit::operator--() {
if (rottenTime_ != 0) {
rottenTime_--;
}
return *this;
}
bool Fruit::isExpired() const {
return rottenTime_;
}