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

Function main

Examples/Modules/Chapter 13/Ex13_11/Ex13_11.cpp:29–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27}
28
29int main()
30{
31 const double limit {99.0}; // Upper limit on Box dimensions
32 auto random = createUniformPseudoRandomNumberGenerator(limit);
33
34 Truckload load;
35 const size_t boxCount {16}; // Number of Box object to be created
36
37 // Create boxCount Box objects
38 for (size_t i {}; i < boxCount; ++i)
39 load.addBox(std::make_shared<Box>(random(), random(), random()));
40
41 std::cout << "The boxes in the Truckload are:\n";
42 std::cout << load;
43
44 // Find the largest Box in the Truckload
45 double maxVolume {};
46 size_t maxIndex {};
47 size_t i {};
48 while (load[i])
49 {
50 if (load[i]->volume() > maxVolume)
51 {
52 maxIndex = i;
53 maxVolume = load[i]->volume();
54 }
55 ++i;
56 }
57
58 std::cout << "\nThe largest box is: ";
59 std::cout << *load[maxIndex] << std::endl;
60
61 load.removeBox(load[maxIndex]);
62 std::cout << "\nAfter deleting the largest box, the Truckload contains:\n";
63 std::cout << load;
64
65 load[0] = load[1]; // Copy 2nd element to the 1st
66 std::cout << "\nAfter copying the 2nd element to the 1st, the list contains:\n";
67 std::cout << load;
68
69 load[1] = std::make_shared<Box>(*load[2] + *load[3]);
70 std::cout << "\nAfter making the 2nd element a pointer to the 3rd plus 4th,"
71 " the list contains:\n";
72 std::cout << load;
73}

Callers

nothing calls this directly

Calls 4

addBoxMethod · 0.45
volumeMethod · 0.45
removeBoxMethod · 0.45

Tested by

no test coverage detected