Name: ____________________________________________________ Alpha: _____________________

Describe help received: _________________________________________________________________

  1. [10pts] Consider the program below, and provide the prototype for the missing function "search".
    #include <iostream>
    #include <fstream>
    using namespace std;
    
    
    
    
    int main()
    {
      ifstream fin("hwdata.txt");
      int n;
      fin >> n;
      double **D = new double*[n];
      for(int i = 0; i < n; i++)
        D[i] = new double[2]; // index 0 is x-coord, index 1 is y-coord
    
      for(int i = 0; i < n; i++)
        fin >> D[i][0] >> D[i][1];
    
      double* w = new double[2];
      cin >> w[0] >> w[1];
    
      int k = search(D,n,w);
      if (k == n)
        cout << "No point found!" << endl;
      else
        cout << "Point: (" << D[k][0] << ',' << D[k][1] << ')' << endl;
    }
  2. [10pts] Consinuing with the previous problem: if "search" was written using the "match" function, as described in the notes, give the prototype and definition for a "match" function that would find a match at index k provided that the point described by array element D[k] was within distance .01 of the point defined by w.
  3. [80pts] Write a program that reads 10 positive ints from the user and prints them into order so that all the odd numbers come first (in increasing size) followed by all the even numbers (in increasing size). For example:
    ~/$ ./hw
    18 2 7 14 29 3 5 8 16 11
    3 5 7 11 29 2 8 14 16 18
    It is expected that you use selection sort (as described in the notes), and there is a "good" way to do this, and an "ugly hack" way to do it. Try to do it the good way!
    Turn In a screen capture of your program running on the above input, and a printout of your source code.