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