-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathshape_2d.cpp
More file actions
62 lines (48 loc) · 1.33 KB
/
shape_2d.cpp
File metadata and controls
62 lines (48 loc) · 1.33 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "../../include/imeth/geometry/2D.hpp"
#include "../../include/imeth/operation/arithmetic.hpp"
#include <numbers>
namespace imeth {
double Circle::area() const {
return std::numbers::pi * radius_ * radius_;
}
double Circle::perimeter() const {
return 2 * std::numbers::pi * radius_;
}
double Rectangle::area() const {
return width_ * height_;
}
double Rectangle::perimeter() const {
return 2 * (width_ + height_);
}
double Triangle::area() const {
return 0.5 * base_ * height_;
}
double Triangle::perimeter() const {
double side = imeth::Arithmetic::square_root((base_ / 2) * (base_ / 2) + height_ * height_);
return base_ + 2 * side;
}
double Square::area() const {
return side_ * side_;
}
double Square::perimeter() const {
return 4 * side_;
}
double Pentagon::area() const {
return 0.25 * imeth::Arithmetic::square_root(5 * (5 + 2 * imeth::Arithmetic::square_root(5))) * side_ * side_;
}
double Pentagon::perimeter() const {
return 5 * side_;
}
double Hexagon::area() const {
return (3 * imeth::Arithmetic::square_root(3) / 2) * side_ * side_;
}
double Hexagon::perimeter() const {
return 6 * side_;
}
double Octagon::area() const {
return 2 * (1 + imeth::Arithmetic::square_root(2)) * side_ * side_;
}
double Octagon::perimeter() const {
return 8 * side_;
}
} // namespace imeth