Midterm Exam, CS130                         Name________________

Grade__________                                Student ID____________

                                                           

Instructions.   The exam is just one programming exercise, similar to the labs you have done except that you will not get step-by-step instructions.  The exam is open book--you may use any books or notes, the course web site, your past work, etc.  Communicating with other people is illegal—so no conversations, instant messaging, chat rooms, or email, even if you have finished the exam already.  You may use the Internet only to reach the course web site.  If technical difficulties should prevent the Internet from working during the exam, you will have to proceed anyway.  Call your project Midterm2345, using your 4-digit student ID number instead of 2345, as you have done before.  If the number does not appear in the title bar of your program you will not get credit. 

 

You will have sixty minutes.  The exam will be graded right in the lab while you are still there.  That’s why you have only sixty minutes instead of sixty-five. 

 

The problem requirements.    

 

1.    Your program should always display a colored (filled) square and sometimes it will display a colored (filled) circle as well, as explained below.   There should be a Square menu offering two colors Green and Yellow, and a Circle  menu offering two colors Red and Blue.   These menu items will enable the user to change the colors of the square and circle.  Colors should change without flicker.

 

2.  When the program first opens, the square is red.   Make it 100 by 100 pixels—the location doesn’t matter.   Initially, no circle is visible.

 

3.  When the user depresses the left mouse button anywhere inside the square, that point becomes the center of a circle (of radius 25 pixels).  The color of the circle is given by the color last selected on the Circle  menu, or yellow if that menu hasn’t yet been used.   Any previous circles disappear—there is always either exactly one circle or no circle at all.   (The circle will stick out of the square if the center is near the edge; the square does not change position.)  

 

4.   When the user depresses the left mouse button outside the square,   then the old square disappears, and a new square is drawn, centered at the point clicked.   (If the point is too near the edge of the window, some of the square may not be shown—that’s OK.)    The old circle, if there was one, does not change position.   Thus it might now be outside the new square (or it might not).  

 

5.  When the window is resized, the image stays visible and in the same position relative to the upper left corner.  

 

Grading Criteria (total 100 points).   Ten points for each of the following:

 

1.   The menu appears correctly.

2.   A red filled square appears when the program opens.

3.  A yellow filled circle appears if you click inside the red square.

4.   The menus correctly change the colors of the square and circles.

5.  If you click somewhere else inside the square, the old circle disappears and

     a new circle appears centered at the point where you clicked.

6 .  If you click outside the square, a new square is drawn, in the same color, and the circle is unchanged.

7.   Steps 5 and 6 work with the new square, and so on with yet new squares.

8.  When the window is resized, the image stays visible and in the same position relative to the upper left corner.  

9.  When you change the color of the square or circle, you do NOT see any flicker of white during the color change.  

 

[ This doesn’t add up to 100 because when the exam was originally given, there was another requirement that we haven’t yet covered.] 

 

For an A+, get all 100 points listed above, and also change the program so that you can’t make the square larger than will fit in the window.  That is, if you click within 50 pixels of any edge of the window, nothing happens.