CS33 -- Laboratory 8

Due: Thursday, Oct 28 by 11:59 pm

You are encouraged to work with a partner.

I will show you on Wednesday, 27 Oct, how to make a 'tarball' of a directory. Work in a subdirectory called initslab8, where inits are your initials. Once you have completed the C programs and made script files to demonstrate your testing of each, remove any extraneous files so that your directory contains just the 3 .c files and the 3 script files. Then make a tarball of that directory and send it to me as an attachment to the email whose subject line should be CS33 Lab8. Send the email to cfk@cs.swarthmore.edu.

Each program must follow these following guidelines:

  1. Write a program (called timediff.c) which prompts the user for two times in 24-hour format and displays the difference in hours and minutes between the two times. You should assume that both times are on the same day. Your output must be the same as the output that I have provided. You do not need to do any error checking on the input values for this question: you can assume that the user enters valid times.

    Some examples of times in 24-hour format are:

    Some hints:

    The following are some sample runs of this program. Underlined words are entries that the user typed in:

    Run 1:
    Enter the first time: 10:46
    Enter the second time: 13:51
    The difference between the times is 3 hours and 5 minutes.

    Run 2 - Make sure you say "1 hour" (or "1 minute") not "1 hours" (or "1 minutes"):
    Enter the first time: 13:15
    Enter the second time: 14:30
    The difference between the times is 1 hour and 15 minutes.

    Run 3 - If the hours are 0, don't print them:
    Enter the first time: 17:59
    Enter the second time: 18:00
    The difference between the times is 1 minute.

    Run 4 - If the minutes are 0, don't print them. Note that the second time isn't always later in the day than the first time:
    Enter the first time: 03:22
    Enter the second time: 07:22
    The difference between the times is 4 hours.

    Run 5 - If there is no difference, say so:
    Enter the first time: 09:29
    Enter the second time: 09:29
    There is no difference between the times.

  2. Write a program (called countdown.c) which solves exercise 12.18 on page 341 of P&P.
  3. A perfect number is a positive integer equal to the sum of all its divisors. For example, the divisors of 28 are 1, 2, 4, 7 and 14, and 1 + 2 + 4 + 7 + 14 = 28. Note that you should not consider 1 to be a divisor of itself. You should first calculate the sum of the divisors, and then compare this to the number itself. If they are equal, the number is perfect.

    Your program (called perfect.c) should calculate and print out the first 4 perfect numbers (one per line); the fifth perfect number is quite large (33550336), so you should be sure you stop after four!



Note: As of 8 October, the final exam for CS33 has been scheduled by the registrar for Friday 12/17/2010, 9:00am-12:00pm in SC240. Plan to attend.