Math 171 Spring 2005, Lab 7 (double lab)

Due Thursday, February 17, 11:59 P.M.

  1. Overview
  2. Assignment
  3. Hints
  4. Extra Credit

Overview

The purpose of this lab is to give you practice using logical expressions and branching statements in Fortran. Additionally, this lab will introduce you to the process of incremental development, i.e. starting with a small core of the full functionality and iteratively repeating a cycle of coding/compiling/testing as you add new features one at a time.

Top

Assignment

Write a Fortran program called holiday that takes a date as input, and prints a message telling whether today is a holiday or other special day as output. The date should be given in the form month day year, where the name of the month is spelled out and the day and year are given as integers. Your program should recognize the following holidays:

  1. New Year's Day
  2. Martin Luther King Day (the first Monday following Martin Luther King's Birthday, January 15)
  3. President's Day (The third Monday in February)
  4. Daylight Saving Time begins (The first Sunday in April)
  5. Earth Day (April 22)
  6. Mother's Day (The second Sunday in May)
  7. Memorial Day (The last Monday in May)
  8. Father's Day (The third Sunday in June)
  9. Independence Day
  10. Labor Day (The first Monday in September)
  11. Daylight Saving Time ends (The last Sunday in October)
  12. Election Day (The Tuesday following the first Monday in November)
  13. Thanksgiving (The Fourth Thursday in November)
  14. New Year's Eve

After making sure your program works correctly, delete your executable and any other extraneous files you have lying in your lab directory, and submit your lab using the ~gbutler/bin/m171_submit command.

Top

Hints

If the assignment seems overwhelming, following the steps below will help you break it into more manageable chunks. At each stage, you will want to output the values of all your intermediate variables. You should also try out your program with several different dates to make sure everything works correctly before proceeding to each successive step.

  1. To start out, just write a program that reads in the date with the month given as a character string and prints the date out again in numerical form.
  2. Go ahead and add recognition for those holidays listed above that only depend on the date, and make sure your program recognizes these dates correctly for several different years.
  3. Now figure out the day of the week on which the specified year started. Use the following facts: There is an intrinsic Fortran function called MOD that will help you here. Its usage is MOD(M,N), which returns the remainder when M is divided by N. You will probably want to store the day of the week as a remainder mod 7 and convert the number to a day name only when printing it out.
  4. Now determine whether this year is a leap year, and the current day of the year. For example, January 20, 2005 is the 20th day of the year, February 8, 2005 is the 39th day of the year, and March 17, 2005 is the 76th day of the year. There is a sample Fortran program in the book that implements this functionality using a combination of loops and branching statements, but it is also possible to implement this feature using only branches. You should use the latter approach.
  5. Now use the variable values you stored from the previous two steps to print out the current day of the week.
  6. Now implement the rest of the holidays. Note that the usual description of the date on which each holiday falls is not the most convenient way of describing them in Fortran. You will need to figure out what the possible range of days for each holiday is. For example, MLK day is the first Monday following January 15, so the possible range of days is Jan. 15-Jan. 21. Since only one of these days is a Monday in any given year, this provides a straightforward way to test whether today is MLK day in Fortran.
  7. Now go back and clean up all the extraneous output statements you generated in the previous steps so that only the current holiday (if any) is printed. Note that instead of deleting the extra output statements, you should probably just comment out these lines (i.e. put the comment character ! at the head of each line). This way you will be able to easily re-enable the extra output later on if you need to.
  8. Finally, test your code some more before submitting. In addition to comparing your results to my code, make sure the output of your program is consistent with any old wall calendars you have lying around. You may also want to compare your results with this Online Holiday Calendar.
  9. Q:Oops! The Gregorian calendar has only been in use since 1582. Now what? A:Don't worry about it. Most of the holidays in the list have been in observance much less time than that. Your program doesn't have to do everything.

Top

Extra Credit

For extra credit, add recognition for any of the following lists of religious observances to your program. Note that the relevant astrological/astronomical events vary from year to year, and that some religions use calendars that do not align consistently with the Gregorian calendar. This means determining the correct date for each holiday may be fairly complex. I recommend using the articles at Wikipedia to get started on determining the correct dates.

There is no deadline for any of these extra credit assignments. Just resubmit your lab after you have completed them.

Top

Back to the course information page