CS 117
Midterm 1
Ondich
Due ON PAPER 12:00 noon Friday, February 4, 2000

This is an open book, open notes, and open computer test. You may not use any books other than your textbook, and you may not use Internet resources from off campus. If you get stuck, talk to Jeff Ondich, but please don't talk to anyone else (not even Shaun Reynolds or the lab assistants) about the exam.

  1. (10 points) Complete the following function.

    
    	////////////////////////////////////////////////////
    	//
    	//	IsCharInArray returns true if the given
    	//	character (ch) is found at least once in
    	//	the array (a) between indices 0 and N-1.
    	//	Otherwise, IsCharInArray returns false.
    	//
    	////////////////////////////////////////////////////
    
    	bool IsCharInArray( char ch, char a[], int N )
    	{
    	}
    


  2. (10 points) Consider the following code.

    
    	for( int i=0; i < N; i++ )
    	{
    		for( int j=N; j > 0; j-- )
    		{
    			cout << i << " " << j << endl;
    		}
    	}
    



  3. (12 points) For each of the following tasks, design an interface for a function that will perform the task, and give an example of how you would call the function. Don't forget that an interface includes both the function's prototype and a comment describing the behavior of the function. DO NOT WRITE THE FUNCTIONS THEMSELVES.



  4. (16 points) Give brief answers for each of the following.



  5. (2 points) What book should I read next?

  6. (10 points) Consider the following InsertionSort function, which you can also find in sorts.cpp.

    
    ////////////////////////////////////////////////////////
    // InsertionSort sorts the first N elements of the
    // given array in increasing order, using an insertion
    // sort algorithm.
    ////////////////////////////////////////////////////////
    
    void InsertionSort( int a[], int N )
    {
    	for( int i=1; i < N; i++ )
    	{
    		int		j;
    		int		temp = a[i];
    
    		for( j=i; j > 0  &&  temp < a[j-1]; j-- )
    		{
    			a[j] = a[j-1];
    		}
    
    		a[j] = temp;
    	}
    }