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

Function main

Exercises/Modules/Chapter 12/Soln12_08/Soln12_08.cpp:33–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31Truckload::Iterator findSmallestBox(const Truckload& truckload);
32
33int main()
34{
35 Truckload load; // Create an empty list
36
37 // Add 12 random Box objects to the list
38 const size_t boxCount{ 12 };
39 for (size_t i{}; i < boxCount; ++i)
40 load.addBox(randomSharedBox());
41
42 std::cout << "The random truckload:\n";
43 load.listBoxes();
44 std::cout << std::endl;
45
46 const auto largestIter{ findLargestBox(load) };
47 const auto smallestIter{ findSmallestBox(load) };
48
49 std::cout << "The largest box (found using forward iteration) is ";
50 largestIter.getCurrentBox()->listBox();
51 std::cout << '\n' << std::endl;
52
53 load.removeBox(largestIter);
54
55 std::cout << "The truckload without its largest box:\n";
56 load.listBoxes();
57 std::cout << std::endl;
58
59 std::cout << "The smallest box (found using reverse iteration) is ";
60 smallestIter.getCurrentBox()->listBox();
61 std::cout << '\n' << std::endl;
62
63 load.removeBox(smallestIter);
64
65 std::cout << "The truckload without its smallest box (in reverse order):\n";
66 load.listBoxesReversed();
67}
68
69Truckload::Iterator findLargestBox(const Truckload& truckload)
70{

Callers

nothing calls this directly

Calls 9

findLargestBoxFunction · 0.70
findSmallestBoxFunction · 0.70
randomSharedBoxFunction · 0.50
addBoxMethod · 0.45
listBoxesMethod · 0.45
listBoxMethod · 0.45
getCurrentBoxMethod · 0.45
removeBoxMethod · 0.45
listBoxesReversedMethod · 0.45

Tested by

no test coverage detected