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

Function main

Examples/NoModules/Chapter 12/Ex12_09/Ex12_09.cpp:5–22  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3#include <iostream>
4
5int main()
6{
7 // v-- this const was added...
8 const Box myBox {3.0, 4.0, 5.0};
9 std::cout << "myBox dimensions are " << myBox.getLength()
10 << " by " << myBox.getWidth()
11 << " by " << myBox.getHeight() << std::endl;
12
13 // Invoking mutators / setters is not possible on a const object:
14 //myBox.setLength(-20.0); // ignored!
15 //myBox.setWidth(40.0);
16 //myBox.setHeight(10.0);
17 //std::cout << "myBox dimensions are now " << myBox.getLength() // 3 (unchanged)
18 // << " by " << myBox.getWidth() // by 40
19 // << " by " << myBox.getHeight() << std::endl; // by 10
20
21 std::cout << "myBox's volume is " << myBox.volume() << std::endl;
22}

Callers

nothing calls this directly

Calls 4

getLengthMethod · 0.45
getWidthMethod · 0.45
getHeightMethod · 0.45
volumeMethod · 0.45

Tested by

no test coverage detected