CS 117
Midterm 1
Ondich
Due ON PAPER 8:30 AM Friday, October 13, 2000

This is an open book, open notes, and open computer test. If you get stuck, talk to Jeff Ondich, but please don't talk to anyone else (not even Justin Thomson or the lab assistants) about the exam.

The first several problems refer to the printwords.cpp program you used as a starting point for your first programming assignment. For each problem, start with the original copy of printwords.cpp.

  1. (4 points) Remove the interface for CleanWord (that is, delete the line of code immediately preceding the main program). What error message do you get when you try to compile the resulting program? Explain why the absence of the interface causes the compiler to be confused.

  2. (4 points) If you remove the ampersand (&) from the CleanWord interface, and then compile and run the program, what happens? (You need to remove the ampersand in both places it appears--above main and down where CleanWord is defined.) Explain why the removal of the ampersand has this effect.

  3. (9 points) Modify CleanWord so a hyphen at the beginning or end of the word is removed, while hyphens appearing in the middle of the word are retained. For example, "pre-eminent" would be unchanged by CleanWord, but "pre-" or "-pre" would be changed to "pre".

  4. (10 points) Modify the main program to print the words in reverse order. Here's an outline of the strategy you should use:

  5. (2 points) What is dangerous about the strategy in the previous problem?

  6. (2 points) Please direct me to an interesting or amusing web site.

  7. (10 points) Consider the following implementation of IsPalindrome.

    
    	bool IsPalindrome( const string& s )
    	{
    		int left = 0;
    		int right = s.length() - 1;
    
    		while( left < right )
    		{
    			if( tolower( s[left] )  !=  tolower( s[right] ) )
    				return( false );
    			else
    				return( true );
    		}
    	}
    



  8. (5 points) Write a one-paragraph biography of one of the following people: Charles Babbage, Grace Hopper, or John Mauchly.