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

Function main

Exercises/NoModules/Chapter 12/Soln12_08/Soln12_08.cpp:32–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected