| 4 | import <iostream>; |
| 5 | |
| 6 | int main() |
| 7 | { |
| 8 | Truckload load1; // Create an empty list |
| 9 | |
| 10 | // Add 12 random Box objects to the list |
| 11 | const size_t boxCount {12}; |
| 12 | for (size_t i {} ; i < boxCount ; ++i) |
| 13 | load1.addBox(randomSharedBox()); |
| 14 | |
| 15 | std::cout << "The first list:\n"; |
| 16 | load1.listBoxes(); |
| 17 | |
| 18 | // Copy the truckload |
| 19 | Truckload copy{load1}; |
| 20 | std::cout << "The copied truckload:\n"; |
| 21 | copy.listBoxes(); |
| 22 | |
| 23 | // Find the largest Box in the list |
| 24 | SharedBox largestBox{load1.getFirstBox()}; |
| 25 | |
| 26 | SharedBox nextBox{load1.getNextBox()}; |
| 27 | while (nextBox) |
| 28 | { |
| 29 | if (nextBox->compare(*largestBox) > 0) |
| 30 | largestBox = nextBox; |
| 31 | nextBox = load1.getNextBox(); |
| 32 | } |
| 33 | |
| 34 | std::cout << "\nThe largest box in the first list is "; |
| 35 | largestBox->listBox(); |
| 36 | std::cout << std::endl; |
| 37 | load1.removeBox(largestBox); |
| 38 | std::cout << "\nAfter deleting the largest box, the list contains:\n"; |
| 39 | load1.listBoxes(); |
| 40 | |
| 41 | const size_t nBoxes {20}; // Number of vector elements |
| 42 | std::vector<SharedBox> boxes; // Array of Box objects |
| 43 | |
| 44 | for (size_t i {} ; i < nBoxes ; ++i) |
| 45 | boxes.push_back(randomSharedBox()); |
| 46 | |
| 47 | Truckload load2{boxes}; |
| 48 | std::cout << "\nThe second list:\n"; |
| 49 | load2.listBoxes(); |
| 50 | |
| 51 | auto smallestBox{ load2.getFirstBox() }; |
| 52 | for (auto box{ load2.getNextBox() }; box; box = load2.getNextBox()) |
| 53 | if (box->compare(*smallestBox) < 0) |
| 54 | smallestBox = box; |
| 55 | |
| 56 | std::cout << "\nThe smallest box in the second list is "; |
| 57 | smallestBox->listBox(); |
| 58 | std::cout << std::endl; |
| 59 | } |
nothing calls this directly
no test coverage detected