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

Function main

Examples/Modules/Chapter 12/Ex12_12/Ex12_12.cpp:6–20  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4import box;
5
6int main()
7{
8 Box box1 {2.2, 1.1, 0.5}; // An arbitrary box
9 Box box2; // A default box
10 auto box3{ std::make_unique<Box>(15.0, 20.0, 8.0) }; // Dynamically allocated Box
11
12 std::cout << "Volume of box1 = " << box1.volume() << std::endl;
13 std::cout << "Surface area of box1 = " << surfaceArea(box1) << std::endl;
14
15 std::cout << "Volume of box2 = "<< box2.volume() << std::endl;
16 std::cout << "Surface area of box2 = " << surfaceArea(box2) << std::endl;
17
18 std::cout << "Volume of box3 = " << box3->volume() << std::endl;
19 std::cout << "Surface area of box3 = " << surfaceArea(*box3) << std::endl;
20}
21
22// friend function to calculate the surface area of a Box object
23double surfaceArea(const Box& box)

Callers

nothing calls this directly

Calls 2

surfaceAreaFunction · 0.70
volumeMethod · 0.45

Tested by

no test coverage detected