Teach a child about an analog clock

Your goal in this lab is to teach a child to use an analog clock. The idea is to display the time in digital form, and ask the child to click on where the hour hand should point to, and then to where the minute hand should point.

  1. Begin with the your clock program yesterdays lab, and draw the face and tick-marks, but don't draw the clock hands.

  2. Somewhere in the window (perhaps beneath the clock) display the current time in digital form in normal (non-military) format with am or pm. For example, 1:32pm. (You'll need to position the components separately.)

  3. Be sure to test your code so far by using both a morning and afternoon time. The best way to do this is in gdb, since gdb allows you to change the values of variables while running a program, without changing the program! To do this,
    1. Run gdb
    2. Set a breakpoint immediately after now is declared.
    3. Run your program in gdb
    4. Change the value of now by using gdb's set command.
        set expression
      
      For expression, you can use any C++ expression.

      In this case, a useful expression would add, say, 60 * 60 * 12 seconds to the time to make your program think its 12 hours later. (If you have troubles doing this, ask!)

    This technique is a good one for debugging code, since you don't have to actually change the code to test it. Were you to change the code to (temporarily) hardwire a time, you might forget to fix it up again later.

  4. Check-off: Demonstrate that you've done the set in gdb to test the am/pm part of your code.

  5. Display a message in the window, asking the user to click on where the hour hand should point. If the user clicks outside the clock circle, or too close to the center of the clock, output an appropriate message and exit.

    For this part, you need to recall how to use the inverse of the tan function, atan() in C++. It takes as an argument a number (y/x) and returns the angle the vector (x,y) points in, or the angle off by pi radians. (The angle will always be between -pi/2 and pi/2.) Be sure your program works in all four quadrants.

  6. Draw the hour hand pointing in the direction the user clicked. The hour hand should be of fixed length, not the length suggested by the mouse click.

  7. Repeat for the minute hand.

  8. If the hands are pretty close to where they should be, congratulate the user.

  9. Check-off Once done, be sure to get checked off. As always, we'll check that you have clean code.