Using the Date class
The class Date is declared in date.h
and defined in date.cpp.
It's designed so
users can declare Date variables representing any date from
1752 until the year 9999, and use the dates in a variety of ways.
Although I developed the class Date as part of my book A Computer Science Tapestry, the class is
freely available to everyone. If you make any changes to the class you
think would benefit others, please send
me email. Similarly, if you have ideas on how to use the class I'd
like to hear them.
The version linked
here uses apstring as the string class, this is the string
class defined for use in Advanced Placement Computer Science courses and
is compatible with the class string/cpstring used in A Computer
Science Tapestry.
Dates can be used before control statements are covered to show how
different constructors are used. They can also be used with
conditionals and loops to solve interesting problems. Here are a few
ideas, clearly there's room for more.
- On what day of the week were you born? On what day of the
week will the new millennium begin (use both 2000 and 2001 to
satisfy everyone's version of when the millennium starts).
- How many days old are you today?
- Was 1900 a leap year? What about 2000?
- What day of the week have all your birthdays occurred on?
- What date does Thanskgiving occur on for the next 10 years?
Thanksgiving is the fourth Thursday in November.
- What about Labor day? Labor Day is the first Monday in September.
- Can you generalize the previous two problems to find on what
date the nth occurrence of weekday
day is? Use this to find Mother's Day, the second
Sunday in May.
- How many school days between Labor Day and Thanksgiving? A
school day is Monday, Tuesday, Wednesday, Thursday, Friday.
- Modify calendar.cc which currently prints
text, to print an HTML calendar, using the TABLE tag, see output
below (generated automatically, the source isn't pretty).
Two different outputs are shown below, one creates a checkerboard
pattern calendar. Creating HTML output is something students find very
engaging.
Output generated by modified calendar.cc
October 1997
Sunday
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
|
| | | 1 | 2 | 3 | 4
|
5 | 6 | 7 | 8 | 9 | 10 | 11
|
12 | 13 | 14 | 15 | 16 | 17 | 18
|
19 | 20 | 21 | 22 | 23 | 24 | 25
|
26 | 27 | 28 | 29 | 30 | 31 | |
October 1997
Sunday
| Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
|
| | | 1 | 2 | 3 | 4
|
5 | 6 | 7 | 8 | 9 | 10 | 11
|
12 | 13 | 14 | 15 | 16 | 17 | 18
|
19 | 20 | 21 | 22 | 23 | 24 | 25
|
26 | 27 | 28 | 29 | 30 | 31
| |
Owen L. Astrachan
Last modified: Sat Dec 6 16:35:16 EST 1997