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

Function main

Exercises/Modules/Chapter 12/Soln12_06/Soln12_06.cpp:26–68  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected