Source of findBox.cpp


  1: //  Created by Frank M. Carrano and Tim Henry.
  2: //  Copyright (c) 2013 __Pearson Education__. All rights reserved.

  4: // Listing C3-3
  5: PlainBox<string> findBox(PlainBox<string> boxes[], int size,
  6:                          string target) throw(logic_error)
  7: {
  8:    int index = 0;
  9:    bool found = false;
 10:    while (!found && (index < size))
 11:    {
 12:       if (target == boxes[index].getItem())
 13:          found = true;
 14:       else
 15:          index++;
 16:    } // end while
 17:    
 18:    if (!found)
 19:       throw logic_error("Target not found in a box!");
 20:    
 21:    return boxes[index];
 22: } // end findBox