text: //DISPLAY 7.10 Searching an Array
  //Searches a partially filled array of nonnegative integers.
  #include <iostream>
  const int DECLARED_SIZE = 20;
  
  void fillArray(int a[], int size, int& numberUsed);
  //Precondition: size is the declared size of the array a.
  //Postcondition: numberUsed is the number of values stored in a.
  //a[0] through a[numberUsed-1] have been filled with
  //nonnegative integers read from the keyboard.
  
  int search(const int a[], int numberUsed, int target);
  //Precondition: numberUsed is <= the declared size of a.
  //Also, a[0] through a[numberUsed -1] have values.
  //Returns the first index such that a[index] == target,
  //provided there is such an index; otherwise, returns -1.
  
  int main( )
  {
      using namespace std;
      int arr[DECLARED_SIZE], list_size, target;
  
      fillArray(arr, DECLARED_SIZE, list_size);
  
      char ans;
      int result;
      do
      {
          cout << "Enter a number to search for: ";
          cin >> target;
  
          result = search(arr, list_size, target);
          if (result == -1)
              cout << target << " is not on the list.\n";
          else
              cout << target << " is stored in array position "
                   << result << endl
                   << "(Remember: The first position is 0.)\n";
  
          cout << "Search again?(y/n followed by Return): ";
          cin >> ans;
      }while ((ans != 'n') && (ans != 'N'));
  
      cout << "End of program.\n";
      return 0;
  }
  //Uses iostream:
  void fillArray(int a[], int size, int& numberUsed)
  <The rest of the definition of fillArray is given in Display 7.9.>
  
  int search(const int a[], int numberUsed, int target)
  {
  
      int index = 0;
      bool found = false;
      while ((!found) && (index < numberUsed))
          if (target == a[index])
              found = true;
          else
              index++;
  
      if (found)
          return index;
      else
          return -1;
  }
  
  