1: // Created by Frank M. Carrano and Tim Henry.
2: // Copyright (c) 2013 __Pearson Education__. All rights reserved.
4: int main()
5: {
6: // Listing C3-4
7: // Create and initialize an array of boxes
8: PlainBox<string> myBoxes[5]; // Array of PlainBox objects
9: myBoxes[0] = PlainBox<string>("ring");
10: myBoxes[1] = PlainBox<string>("hat");
11: myBoxes[2] = PlainBox<string>("shirt");
12: myBoxes[3] = PlainBox<string>("sock");
13: myBoxes[4] = PlainBox<string>("shoe");
14: PlainBox<string> foundBox;
16: // Try to find a box containing glasses
17: try
18: {
19: foundBox = findBox(myBoxes, 5, "glasses");
20: }
21: catch(logic_error logErr)
22: {
23: cout << logErr.what() << endl; // Display error message to user
24: foundBox = PlainBox<string>("nothing"); // Fix problem
25: } // end try-catch
26: // Because we catch the exception and fix the problem, the following
27: // statement should work even if the target is not found
28: cout << foundBox.getItem();
30: return 0;
31: }