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

Class Box

Examples/NoModules/Chapter 12/Ex12_11/Box.h:4–29  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#define BOX_H
3
4class Box
5{
6public:
7 // Constructors
8 Box() = default;
9 Box(double length, double width, double height);
10
11 double volume() const; // Function to calculate the volume of a box
12 void printVolume() const; // Function to print out the volume of a box (const!)
13
14 // Functions to provide access to the values of member variables (all const!)
15 double getLength() const { return m_length; }
16 double getWidth() const { return m_width; }
17 double getHeight() const { return m_height; }
18
19 // Functions to set member variable values (not const!)
20 void setLength(double length) { if (length > 0) m_length = length; }
21 void setWidth(double width) { if (width > 0) m_width = width; }
22 void setHeight(double height) { if (height > 0) m_height = height; }
23
24private:
25 double m_length{1.0};
26 double m_width {1.0};
27 double m_height{1.0};
28 mutable unsigned m_count{}; // Counts the amount of time printVolume() is called
29};
30
31#endif

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected