-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclasses.hpp
70 lines (53 loc) · 1.54 KB
/
classes.hpp
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
#include <cmath>
#ifndef LAB4_CLASSES_HPP
#define LAB4_CLASSES_HPP
class Point {
public:
Point(double x = 0, double y = 0) : x(x), y(y) {}
double getDist() const { return sqrt(x * x + y * y); }
bool operator==(const Point& rhs) const {
return getDist() == rhs.getDist();
}
bool operator!=(const Point& rhs) const {
return getDist() != rhs.getDist();
}
bool operator<(const Point& rhs) const {
return getDist() < rhs.getDist();
}
bool operator>(const Point& rhs) const {
return getDist() > rhs.getDist();
}
bool operator<=(const Point& rhs) const {
return getDist() <= rhs.getDist();
}
bool operator>=(const Point& rhs) const {
return getDist() >= rhs.getDist();
}
private:
double x, y;
};
class Human {
public:
explicit Human(unsigned height = 0, unsigned age = 0) : height(height), age(age) {}
bool operator==(const Human& rhs) const {
return height == rhs.height && age == rhs.age;
}
bool operator!=(const Human& rhs) const {
return !((*this) == rhs);
}
bool operator<(const Human& rhs) const {
return height * age < rhs.height * rhs.age;
}
bool operator>(const Human& rhs) const {
return height * age > rhs.height * rhs.age;
}
bool operator<=(const Human& rhs) const {
return height * age <= rhs.height * rhs.age;
}
bool operator>=(const Human& rhs) const {
return height * age >= rhs.height * rhs.age;
}
private:
unsigned height, age;
};
#endif