UMBC CMSC104 CSEE

Project

Write a program that, given a person's birth date will display the day of the week the person was born.

To determine the day of the week, you will first need to calculate the day of the week for December of the previous year. To calculate the day for December 31, use the formula:

((year - 1) * 365) + ((year - 1) / 4) - ((year - 1) / 100) + ((year - 1)/400) ) % 7

The formulat determines the day based on the values shown below.

Day 0: Sunday
Day 1: Monday
Day 2: Tuesday
Day 3: Wednesday
Day 4: Thursday
Day 5: Friday
Day 6: Saturday

Once you know the day for December 31, you can simply calculate the days in the year before the month in question. Use a switch statement to make this calculation. (Hint: Use case 12 first, and then fall into case 11, 10, 9,...,2.) If the desired month is 12, add the numbers of days for November (30). If it is 11, add the number of days for October (31). If it is 3, add the number of days for February (28). If it is 2, add the number of days for January (31). If you do not use a break between the months, the switch will add the days in each month before the current month.

To this figure, add the day in the current month and add the result to the day code for December 31. This number modulo seven is the day of the week.

There is one more refinement. If the current year is a leap year, and if the desired date is after February, you need to add 1 to the day code. The following formula can be used to determine if the year is a leap year.

(!(year % 4) && ( year % 100) ) || !(year % 400)

YOur test your program, run it with the following dates:

February 28, 1900, and March 1, 1900
February 28, 1955, and March 1, 1955
February 28, 1996, and March 1, 1996
February 28, 2000, and March 1, 2000
December 31, 1996
The first and last dates of the current week

Program Header Comment Block

Use the following comment block at the beginning of your source code:
        /*****************************************************/
        /* Program Header Block                              */
        /* Filename:       jdoe2p3.c                         */
        /* Name:           Ima Student                       */
        /* email address:  jdoe2@umbc.edu                    */
        /* Date:           6 Nov 2004                        */
        /* Course/section: CMSC-104/0101                     */
        /* Description:                                      */
        /*     Analysis:                                     */
        /*         Input:                                    */
        /*         Output:                                   */
        /*         Constraints:                              */
        /*         Formulas:                                 */
        /*         Assumptions:                              */
        /*     Design:                                       */
        /*         (Your psuedocode goes here.)              */
        /*                                                   */
        /* Notes:          (As needed.)                      */
        /*****************************************************/


UMBC CMSC104 CSEE | CMSC104 | Lectures