Assignment 8 - A Date with Overloaded Operators

due November 27th

The purpose of this assignment is to give you practice with constuctors, static members, friend functions, and overloaded operators.


Program Overview

You are to write a Date class with the necessary constructors and overloaded operator functions that makes use of the requisite main() function to produce the indicated output below.

Requirements

  1. The program will be tested using the main() listed below.
  2. The Date class must contain:
  1. an overloaded insertion operator to print a Date using a mm/dd/yyyy format.
  2. a overloaded binary + operator to added a number of days to a Date (e.g. 60 + today).

The Required main() function

int main()
{
    // Constructors
    Date today;  // initializes Date with current date
    Date feb2815(2,28,15);
    Date feb2800("02-28-00");
    Date NewYearsDay("01/01/16");

    // Increment and decrement operators
    cout << today << endl;
    ++today;
    cout << today << endl;
    --today;
    cout << today << endl << endl;

    cout << feb2815 << endl;
    cout << ++feb2815 << endl;
    cout << --feb2815 << endl << endl;

    cout << feb2800 << endl;
    cout << ++feb2800 << endl;
    cout << --feb2800 << endl << endl;

    cout << NewYearsDay << endl;
    --NewYearsDay;
    cout << NewYearsDay << endl;
    ++NewYearsDay;
    cout << NewYearsDay << endl << endl;

    // Test plus operators
    cout << "30 days from now: " << today + 30 << endl;
    cout << "sixty days from now: " << 60 + today << endl << endl;

    // Test minus operators
    Date twentyYearsAgo = today - static_cast<int>(round(20 * 365.25));
    Date final("12/12/16");
    cout << "Days until the final = " << final - today << endl;

    // Test the ! operator
    cout << "Today is ";
    !today;
    cout << "Twenty years ago was ";
    !twentyYearsAgo;
    cout << endl;

    // Test logic operators
    cout << boolalpha;
    cout << feb2800 << " < " << NewYearsDay << " ? " << (feb2800 < NewYearsDay) << endl;
    cout << feb2815 << " < " << NewYearsDay << " ? " << (feb2815 < NewYearsDay) << endl;
    cout << feb2815 << " > " << NewYearsDay << " ? " << (feb2815 > NewYearsDay) << endl;
}


Program Output

Your output should look quite similar to the following.  Note: some dates will be different when you use your current date.

Output produced 8/14/17

08/14/2017
08/15/2017
08/14/2017

02/28/2015
03/01/2015
02/28/2015

02/28/2000
02/29/2000
02/28/2000

01/01/2017
12/31/2016
01/01/2017

30 days from now: 09/13/2017
sixty days from now: 10/13/2017

Days until the final = 119
Today is August 14, 2017
Twenty years ago was August 14, 1997

02/28/2000 < 01/01/2017 ? true
02/28/2015 < 01/01/2017 ? true
02/28/2015 > 01/01/2017 ? false



Program Hints

  1. Store the year as a 4-digit integer number
  2. Use the time() and localtime() functions to get the current date.
  3. Write a function to test for leap year.
  4. Write and test one function at a time.  Perform thorough testing, not just the the required main().