Background
The "Difference between Dates" case study dealt with the problem of finding the number of days between two dates in the same year. For this assignment, you will solve a more general problem, that of finding the number of days between two dates in different years. (You can use the code you write to find out how many days old you are.)
Problem
Write a procedure century-day-span that takes two dates as arguments, and returns the number of days between them, including the argument dates themselves. Assume that the first argument date is earlier than the second.
Each date is a three-word that represents a legal date between January 1, 1900 and December 31, 2999. The first word is a month name (one of january, february, ..., december). The second is an integer between 1 and the number of days in the specified month, inclusive. The third is an integer between 1900 and 2999, inclusive; it represents a year in the 20th, 21st, 22nd, 23rd, 24th, 25th, 26th, 27th, 28th, 29th, or 30th century.
Your procedure must be able to deal with leap years. A leap year between 1900 and 2999 is any year that's divisible by 400, or by 4 and not by 100. (Thus 2000 was a leap year and 1900 was not.) A leap year's February has 29 days rather than 28, and therefore it has 366 days rather than 365.
Examples
The table below lists some sample calls to century-day-span and the desired return values.
expression | desired return value |
(century-day-span '(january 3 1990) '(january 9 1990)) | 7 |
(century-day-span '(march 30 1989) '(february 2 1990)) | 310 |
(century-day-span '(january 1 1984) '(january 1 1985)) | 367 |
(century-day-span '(january 1 2001) '(january 1 2005)) | 1462 |
Miscellaneous requirements
You should write helper procedures and call them from century-day-span, rather than doing all the computation in century-day-span itself. Restrict your use of Scheme to material covered in Simply Scheme chapters 3 through 6. Test your century-day-span procedure at least on the following:
-
dates in the same month;
-
dates in the same year in different months;
-
dates in different years, where the month of the first date precedes the month of the second date;
-
dates in different years, where the month of the first date follows the month of the second date;
-
dates in different years that do not span a "leap day";
-
dates in different years that span a "leap day";
-
dates that span the leap day in the year 2000;
-
dates that span the non-leap day in the year 1900;
-
dates in different years with the first date in a leap year;
-
dates in different years with the second date in a leap year;
-
dates in different years with both dates in a leap year.
(Note that these are not guaranteed to reveal all your bugs.) Test your helper procedures individually.
Put your century-day-span procedure and its helper procedures in a file named c.day-span.scm in your mp1 directory. ("mp" stands for "miniproject". You'll need to create this directory.) Include your tests for the century-day-span proceedure in the same file, at the end, surrounded by multi-line comments. Please add comments for each test. If you don't want to do the math to test your code, you can go here instead. However, you will need to add 1 to every answer it gives you.
Submit you file electronically in the usual way (i.e., within unix enter the mp1 directory, perhaps via cd ~/mp1, and then type submit mp1).
You have longer to work on this assignment than a regular homework assignment. Check with your TA or the course website for the due date. |