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

Function main

Examples/Modules/Chapter 13/Ex13_10/Ex13_10.cpp:17–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15}
16
17int main()
18{
19 const double limit {99.0}; // Upper limit on Box dimensions
20 auto random = createUniformPseudoRandomNumberGenerator(limit);
21
22 Truckload load;
23 const size_t boxCount {16}; // Number of Box object to be created
24
25 // Create boxCount Box objects
26 for (size_t i {}; i < boxCount; ++i)
27 load.addBox(std::make_shared<Box>(random(), random(), random()));
28
29 std::cout << "The boxes in the Truckload are:\n";
30 std::cout << load;
31
32 // Find the largest Box in the Truckload
33 double maxVolume {};
34 size_t maxIndex {};
35 size_t i {};
36 while (load[i])
37 {
38 if (load[i]->volume() > maxVolume)
39 {
40 maxIndex = i;
41 maxVolume = load[i]->volume();
42 }
43 ++i;
44 }
45
46 std::cout << "\nThe largest box is: ";
47 std::cout << *load[maxIndex] << std::endl;
48
49 load.removeBox(load[maxIndex]);
50 std::cout << "\nAfter deleting the largest box, the Truckload contains:\n";
51 std::cout << load;
52}

Callers

nothing calls this directly

Calls 4

addBoxMethod · 0.45
volumeMethod · 0.45
removeBoxMethod · 0.45

Tested by

no test coverage detected