forked from coders-school/object-oriented-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise3.cpp
More file actions
44 lines (39 loc) · 1 KB
/
exercise3.cpp
File metadata and controls
44 lines (39 loc) · 1 KB
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
#include <string>
class Ship {
public:
Ship()
: id_(-1)
{}
Ship(int capacity, int maxCrew, int speed, const std::string& name, size_t id)
: capacity_(capacity)
, maxCrew_(maxCrew)
, crew_(0)
, speed_(speed)
, name_(name)
, id_(id)
{}
Ship(int maxCrew, int speed, size_t id)
: Ship(0, maxCrew, speed, "", id)
{}
void setName(const std::string& name) { name_ = name; }
Ship& operator-=(size_t num) {
crew_ -= num;
return *this;
}
Ship& operator+=(size_t num) {
crew_ += num;
return *this;
}
size_t getCapacity() const { return capacity_; }
size_t getMaxCrew() const { return maxCrew_; }
size_t getSpeed() const { return speed_; }
std::string getName() const { return name_; }
size_t getId() const { return id_; }
private:
size_t capacity_;
size_t maxCrew_;
size_t crew_;
size_t speed_;
std::string name_;
const size_t id_;
};