-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtriangle.cpp
61 lines (52 loc) · 1.19 KB
/
triangle.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
50
51
52
53
54
55
56
57
58
59
60
61
#include "triangle.h"
/*-----------------------------*/
/* triangle */
/*-----------------------------*/
triangle::triangle(float bottom, float left_side, float right_side)
:m_bottom(bottom), m_lside(left_side), m_rside(right_side)
{
}
float triangle::bottom() const
{
return m_bottom;
}
float triangle::lside() const
{
return m_lside;
}
float triangle::rside() const
{
return m_rside;
}
float triangle::area() const
{
float s = perimeter() / 2;
return std::sqrt(s * (s - m_bottom) * (s - m_lside) * (s - m_rside));
}
float triangle::perimeter() const
{
return m_bottom + m_lside + m_rside;
}
float triangle::circumference() const
{
return perimeter();
}
std::ostream& triangle::shape_info(std::ostream& out) const
{
return out << "triangle("
<< "b: " << bottom() << ", "
<< "l: " << lside() << ", "
<< "r: " << rside() << ", "
<< "area: " << area() << ", "
<< "perimeter: " << perimeter()
<< ")";
}
std::string triangle::shape_details() const
{
return "triangle(b: " + std::to_string(bottom())
+ ", l: " + std::to_string(lside())
+ ", r: " + std::to_string(rside())
+ ", area: " + std::to_string(area())
+ ", perimeter: " + std::to_string(perimeter())
+ ")";
}