MCS273 Introduction to C++ Programming (January 2013)

Multiple clocks


The goal of this lab is to write a program that displays multiple clocks representing various different time zones. You will write this program using appropriately designed functions and procedures that will make the programming much easier and more easily understood than the code you have written up to this point.

Static clocks (2 points)

We are providing a starting point for your program, namely the program shell I talked about in class. You can obtain this program shell and a working solution executable by downloading the following files:

BTW, when I downloaded these files in Chrome, they were all renamed. For example, was renamed many-clocks.cp. Check that they are correctly named by doing an ls -l in the directory. If not, then will have to rename them using the unix command mv. For example, in my case I did the following command in Terminal to take care of the first file:

   mv many-clocks.cp
Before running solution and solution-animated, make them executable by Mac OS X by running the following commands in the directory you downloaded them to:
   chmod 755 solution
   chmod 755 solution-animated
The file will compile and display a message telling (briefly) you what to do. You should also probably run solution so that you know what your goal is.

Check-offs (2 points): When I check you off, I'll verify that you have:

  1. Documentation for the program, documentation for the procedure angleOfHourHand, and an appropriately written Makefile. Refer to C++ Style Guide for documentation format. Use A1.2.2 Header comment for the program documentation and A1.3. Functions for the procedure documentation. Read through the document how to format comments for variables, constants, etc.

    As the book describes, documentation involves comments at the head describing what the program does, and a brief comment at the head of each procedure saying what the procedure computes. Since you'll choose clear variables and procedure names, each comment can be quite short. Remember to state any preconditions, if there are any.

  2. The procedures angleOfMinuteHand, radialSegment, and drawTick, including testing and documentation.

    You can demonstrate testing either by code in your main (which you'll later remove) in the debugger.

  3. The procedures drawClock and drawLabeledClock, including testing and documentation.

  4. Write main so that the program does what it should.

Animating your clocks (1 point)

You can animate your clocks if you wish. Add a second hand so you can see the animation. You'll need a few new ideas:

  1. You'll need to clear the graphics window and redraw. Go to "ccc_win.h" reference for a summary of the graphics commands.

  2. If you refresh too often, the window will blink annoyingly. Use sleep(1) to sleep for 1 second between refreshes. When you type man -k sleep, there are a couple relevant entries:

        sleep                (1)  - delay for a specified amount of time
        sleep                (3)  - Sleep for the specified number of seconds
    One of these, from Chapter 1 of the on-line manual, is a Linux shell command, and the one from Chapter 3 is a C library command. To learn about the sleep from Chapter 3, type
        man 3 sleep

  3. The graphics window buffers graphics. It only get around to displaying your graphics when (a) the buffer gets full, (b) you perform a get_mouse or (c) you exit. The following code will fill the buffer and force a redraw:

      for (int i=0; i<500; i++)
         cwin << Point (10,10);

  4. Lastly, you need drawing of the clock to keep repeating. We haven't covered any loops yet but here is a skeleton you can use to animate the clock.

      while (true) {
        // put all the statements that draw the clock, including the second hand
        // put the code to fill the buffer
        // then, put the code to sleep
        // finally, clear the window

  5. Check-off: AS above, in addition to checking the code and that it works, I will expect that you continue your good documentation.