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.


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