Due Thursday, February 17, 11:59 P.M.
- Overview
- Assignment
- Hints
- Extra Credit
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
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:
- New Year's Day
- Martin Luther King Day (the first Monday following Martin Luther
King's Birthday, January 15)
- President's Day (The third Monday in February)
- Daylight Saving Time begins (The first Sunday in April)
- Earth Day (April 22)
- Mother's Day (The second Sunday in May)
- Memorial Day (The last Monday in May)
- Father's Day (The third Sunday in June)
- Independence Day
- Labor Day (The first Monday in September)
- Daylight Saving Time ends (The last Sunday in October)
- Election Day (The Tuesday following the first Monday in November)
- Thanksgiving (The Fourth Thursday in November)
- 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
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.
- 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.
- 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.
- Now figure out the day of the week on which the specified year started.
Use the following facts:
- January 1, 2000 was a Saturday
- Most years contan 365 days, except for leap years which contain
366 days.
- Leap years occur every four years, except for years that are multiples
of 100 (which are not leap years unless they are also multiples of 400). So
e.g. 1996, 2000, 2004 were all leap years, but 1900 was not.
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.
- 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.
- Now use the variable values you stored from the previous two steps
to print out the current day of the week.
- 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.
- 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.
- 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.
- 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
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.
- (20 pts) The eight Sabbats of the ancient Celts.
- (40 pts) The Christian Holidays Valentine's Day, St. Patrick's Day,
Mardi Gras, Ash Wednesday, Palm Sunday, Good Friday, Easter, and Christmas.
- (60 pts) The Muslim Sacred Days listed in Wikipedia's Muslim
Calendar Article.
- (80 pts) The Buddhist Festival Days described on this page.
- (100 pts) The Jewish Holidays Rosh Hashannah, Yom Kippur, Chanukah,
Passover, and Pentecost.
- Any other set of observances/special days you want your program to
recognize. Send me an email
describing the additional holidays and I will determine how many extra
points to award based on how much work appears to be involved.
Top
Back to the course information page