Source of ListingC3-2.cpp


  1: //  Created by Frank M. Carrano and Timothy M. Henry.
  2: //  Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.

  4: // Listing C3-2
  5: PlainBox<std::string> findBox(PlainBox<std::string> boxes[], int size,
  6:                               std::string target)
  7: {
  8:    int index = 0;
  9:    bool found = false;
 10:    while (!found && (index < size))
 11:    {
 12:       found = (target == boxes[index].getItem());
 13:       if (!found)
 14:          index++; // Look at next entry
 15:    } // end while
 16:    
 17:    assert(found); // Verify that there is a box to return
 18:    return boxes[index];
 19: }  // end findBox