Dating Exercises

Refactoring Code

In the current version of dating.cpp there is a lot of redundant code in the functions LaborDay, Thanksgiving, and MothersDay. You should write one function with several parameters that can be used in place of each of these functions. Here is how the function will be used in main.
  Date labor = findNthDay(9, 1, year, "Monday");
  Date thanks = findNthDay(11, 4, year, "Thursday");
  Date mom = findNthDay(5, 2, year, "Sunday");
  

The idea is to factor out the code in common to the three functions you are given and write one function, findNthDay, that can be used in place of the three original functions. Be sure to provide good parameter names and a proper postcondition for your new function, findNthDay

Added Features

  1. Add code in main so that the date on which Father's day occurs is also printed. Father's day is the third Sunday in June.
     
  2. Add code and functions as appropriate to calculate the number of days of daylight savings time in a given year. Daylight savings time starts on the first Sunday in April and ends on the last Sunday in October. As much as possible, try to use the function findNthDay in calculating the number of days of daylight savings time.
  3. Add code and functions as appropriate to calculate the number of school days (Monday, Tuesday, Wednesday, Thursday, Friday) between Labor day and Thanksgiving in a given year.

  4. Generalize the code you wrote above to provide a function the finds the number of week days between any two given dates.