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

Class Box

Examples/NoModules/Chapter 13/Ex13_10/Box.h:7–35  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5#include <format>
6
7class Box
8{
9public:
10 Box() = default;
11 Box(double length, double width, double height)
12 : m_length{length}, m_width{width}, m_height{height} {};
13
14 double volume() const
15 {
16 return m_length * m_width * m_height;
17 }
18
19 int compare(const Box& box) const
20 {
21 if (volume() < box.volume()) return -1;
22 if (volume() == box.volume()) return 0;
23 return +1;
24 }
25
26 friend std::ostream& operator<<(std::ostream& out, const Box& box)
27 {
28 return out << std::format("Box({:.1f},{:.1f},{:.1f})", box.m_length, box.m_width, box.m_height);
29 }
30
31private:
32 double m_length {1.0};
33 double m_width {1.0};
34 double m_height {1.0};
35};
36
37#endif

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected