Extra Credit Homework #1
Due by Friday, December 17, 1999
In homework #4, we wrote a simple program to convert a numerical date, entered
as 3 integers, into a more familiar text format. I would like you to rewrite
this program, incorporating things we've learned since then. Specifically:
- Use functions: your program should have a main function (of course), a function
named InputDate, in which you read the 3 numbers from the keyboard, and a
function named PrintDate, in which you print the date corresponding with the
numbers that were entered.
- Print "Invalid date" whenever the entered date is not valid. Any
year greater than 0 is valid (the number entered should be the actual year;
don't add a "19" before it. That's what caused this whole Y2K problem!).
You should handle leap years correctly, so for the following entries:
- 2 29 1900
- Print "Invalid date!" (1900 is not a leap year)
- 2 29 1996
- Print "February 29, 1996" (1996 is a leap year)
- 2 29 1999
- Print "Invalid date!" (1999 is not a leap year)
Remember a year is a leap year if it is divisible by 4, unless it is divisible
by 100; except if it's divisible by 400 it is a leap year.
- Write another function named PrintMonthName to print the month name for
a given month number. It should take a single argument, type int, which is
the number of the month. It should print the name of the month. Alternatively,
you can write a function named just MonthName, which returns the name of the
month as a char*, which you can print using %s in printf. This is a bit more
difficult, and you might not want to try it, but you'll get extra points if
you do it right. In either case, use an array of month names, not a switch
or if statement, to convert the number to a name.
- If you're feeling really adventuresome and want a real challenge (and want
some extra points), have your program print the name of the day. That is,
if I entered "12 8 1999", it should print "Wednesday, December
8, 1999". You can refer to this web page to find out how to figure out
the day of the week for any given date:
http://www.interlog.com/~r937/doomsday.html