CS 117
Midterm 2
Ondich
Due ON PAPER 11:11 AM Wednesday, March 7, 2001

This is an open book, open notes, and open computer test. If you get stuck, you may talk to me (Jeff Ondich) or Jenny Cooper, but please don't talk to anyone else (including the lab assistants) about the exam.

  1. (15 points) Write two versions of the following function, one recursive and one iterative.

    
    	// Returns true if the given character is equal to
    	// a[0] or a[1] or...or a[N-1], and false otherwise.
    
    	bool IsCharInArray( char ch, char a[], int N )
    	{
    		//...
    	}
    


  2. (9 points) Modify the main program in emailClassTester.cpp to sort the array of e-mail messages by subject line before printing them out. Hand in your new main program, and any other code you added or changed in emailClassTester.cpp, emailClass.cpp, or emailClass.h.

  3. (9 points) Searching in computer science is the process of looking through a collection of items to find a particular item. For example, the function IsCharInArray in problem 1 is a search function.



  4. (12 points) I have N numbers stored in an array a[], and I want to know the distance between the pair of these numbers that are furthest apart. Elmo suggests the following code, which does the job:
    
    	int max = 0;
    	for( int i=0; i < N; i++ )
    	{
    		for( int j=0; j < N; j++ )
    		{
    			if( a[i] - a[j] > max )
    				max = a[i] - a[j];
    		}
    	}
    


  5. (2 points) Tell me a joke, please.

  6. (7 points) A little binary arithmetic.