The program handin33 will only submit files in the cs33/lab/06 directory. (You should run update33 first to set up the directory and create any necessary files.)
Remember: You are encouraged to work with a partner.
In this lab, we will write C programs, write a Makefile, read from "standard in" and write to "standard out".
Each program must follow these following guidelines:
Some examples of times in 24-hour format are:
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.
Your program must prompt for and read input in the form mm/dd/yy exactly (including slashes) from the user. Then convert the month into the corresponding month name, and convert the 2-digit year into the correct 4-digit year.
You must use a switch statement (p. 368) to convert the month into the name of the month. You must use an if statement (p. 344) to convert the 2-digit year into a 4-digit year.
You should not use a variable to store the name of the month: just print each month name directly (e.g. printf("January");)
You should print out an error message if the user types in an invalid month (not between 1-12), an invalid year (not between 0-99) or types in an invalid date (depending on the month). If the year is a multiple of 4, February should have 29 days; otherwise it should have 28. Any error should result in main returning a value of 1.
The following are some sample runs of this program. Underlined words are entries that the user typed in:
Run 1:
Enter the date: 11/04/08
The date is November 4, 2008.
Run 2:
Enter the date: 12/31/08
The date is December 31, 2008.
Run 3:
Enter the date: 02/29/08
The date is February 29, 2008.
Run 4 - The function main returns 1:
Enter the date: 02/29/09
Error: Bad date entered.
Run 5: - The function main returns 1:
Enter the date: 13/29/08
Error: Bad date entered.
After running each test case, you can check that the return value is correct by typing: echo $? on the command line. $? is a special variable which stores the return value of a program after it finished executing.
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! Your solution should use one for loop (p. 353) and one while loop (p. 350).