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

Class Box

Examples/NoModules/Chapter 12/Ex12_01A/Ex12_01A.cpp:5–30  ·  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() {} // Explicitly defined default constructor
9 Box() = default; // Defaulted default constructor
10
11 // Constructor
12 Box(double length, double width, double height)
13 {
14 std::cout << "Box constructor called." << std::endl;
15 m_length = length;
16 m_width = width;
17 m_height = height;
18 }
19
20 // Function to calculate the volume of a box
21 double volume()
22 {
23 return m_length * m_width * m_height;
24 }
25
26private:
27 double m_length {1.0};
28 double m_width {1.0};
29 double m_height {1.0};
30};
31
32int main()
33{

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected