MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / Box

Class Box

Examples/NoModules/Chapter 20/Ex20_08/Box.h:5–28  ·  view source on GitHub ↗

Class to represent a box

Source from the content-addressed store, hash-verified

3
4// Class to represent a box
5class Box
6{
7public:
8 Box() = default;
9 Box(double length, double width, double height)
10 : m_length{ length }, m_width{ width }, m_height{ height }
11 {}
12
13 double getLength() const { return m_length; }
14 double getWidth() const { return m_width; }
15 double getHeight() const { return m_height; }
16
17 void setLength(double length) { if (length > 0) m_length = length; }
18 void setWidth(double width) { if (width > 0) m_width = width; }
19 void setHeight(double height) { if (height > 0) m_height = height; }
20
21 // Function to calculate the volume of a box
22 double volume() const { return m_length * m_width * m_height; }
23
24private:
25 double m_length{ 1.0 };
26 double m_width{ 1.0 };
27 double m_height{ 1.0 };
28};
29
30#endif

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected