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

Function main

Exercises/NoModules/Chapter 12/Soln12_06/Soln12_06.cpp:25–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23SharedBox findSmallestBox(const Truckload& truckload);
24
25int main()
26{
27 Truckload load1; // Create an empty list
28
29 // Add 12 random Box objects to the list
30 const size_t boxCount{ 12 };
31 for (size_t i{}; i < boxCount; ++i)
32 load1.addBox(randomSharedBox());
33
34 std::cout << "The first list:\n";
35 load1.listBoxes();
36
37 // Copy the truckload
38 Truckload copy{ load1 };
39 std::cout << "The copied truckload:\n";
40 copy.listBoxes();
41
42 // Find the largest Box in the list
43 const auto largestBox{ findLargestBox(load1) };
44
45 std::cout << "\nThe largest box in the first list is ";
46 largestBox->listBox();
47 std::cout << std::endl;
48 load1.removeBox(largestBox);
49 std::cout << "\nAfter deleting the largest box, the list contains:\n";
50 load1.listBoxes();
51
52 const size_t nBoxes{ 20 }; // Number of vector elements
53 std::vector<SharedBox> boxes; // Array of Box objects
54
55 for (size_t i{}; i < nBoxes; ++i)
56 boxes.push_back(randomSharedBox());
57
58 Truckload load2{ boxes };
59 std::cout << "\nThe second list:\n";
60 load2.listBoxes();
61
62 const auto smallestBox{ findSmallestBox(load2) };
63
64 std::cout << "\nThe smallest box in the second list is ";
65 smallestBox->listBox();
66 std::cout << std::endl;
67}
68
69SharedBox findLargestBox(const Truckload& truckload)
70{

Callers

nothing calls this directly

Calls 8

randomSharedBoxFunction · 0.70
findLargestBoxFunction · 0.70
findSmallestBoxFunction · 0.70
addBoxMethod · 0.45
listBoxesMethod · 0.45
listBoxMethod · 0.45
removeBoxMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected