-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrectangle.cpp
54 lines (45 loc) · 993 Bytes
/
rectangle.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
#include "rectangle.h"
/*-----------------------------*/
/* rectangle */
/*-----------------------------*/
rectangle::rectangle(float width, float height)
:m_width(width), m_height(height)
{
}
float rectangle::width() const
{
return m_width;
}
float rectangle::height() const
{
return m_height;
}
float rectangle::area() const
{
return m_height * m_width;
}
float rectangle::perimeter() const
{
return 2 * (m_width + m_height);
}
float rectangle::circumference() const
{
return perimeter();
}
std::ostream& rectangle::shape_info(std::ostream& out) const
{
return out << "rectangle"
<< "(w: " << width() << ", "
<< "h: " << height() << ", "
<< "area: " << area() << ", "
<< "perimeter: " << perimeter()
<< ")";
}
std::string rectangle::shape_details() const
{
return "rectangle(w: " + std::to_string(width())
+ ", h: " + std::to_string(height())
+ ", area: " + std::to_string(area())
+ ", perimeter: " + std::to_string(perimeter())
+ ")";
}