Dana Vrajitoru
C201/I211 Computer Programming II

Homework 4

Due Date: Wednesday, September 27, 2006.

Ex. 1 Download the following files:
array_oper.h
array_oper.cpp
main.cpp

Create a project and include these three files. The project will need to be on the hard drive to run correctly. The source files can be on your O: drive, only the project needs to be on a local drive. Make sure you save the source/header files to your O: drive before leaving, if you stored them somewhere else. Compile the project with the command build and execute it like any other project. If you need help compiling it on Linux let me know.

Ex. 1 Add the following functions to the project. Make sure you place the prototypes of functions and the implementation of the functions in the appropriate files.

a. Selection sort using the max. This function should perform a selection sort by finding the maximum element in the array and moving it to the end of the array, then finding the next largest element and moving it to the previous to last position, and so on. Here is the propotype for this function:

void Selection_sort_max(int *a, int size);

b. Verify that an array is sorted. The function should not output the result but only return true or false. Here's a prototype for this function:

bool Is_sorted(int *a, int size);

c. Reverse the elements of the array. For this you'll have to swap a[0] with a[size-1], a[1] with a[size-2], and so on. Here's a prototype for this function:

void Reverse(int *a, int size);

Ex. 2 Modify the main function to do the following things:

Ex. 3 Add an output statement in the function Binary_search to display information about the first and last at every iteration. Run a few tests with an array of 20 elements where the value is/is not in the array and report on the number of iterations done by the function (in your submission email). Comment out the output statements in this function before you turn in the program but leave them there.

Show an example of the execution by embedding it in the program as a comment, as usual. Send the three files you modified by email. Do not change the file names for this homework.