Assignment 8 - A Date with Overloaded Operators

due November 26th

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. 100 + today).

The Required main() function

int main()
{
    // Constructors
    Date today;
    Date feb2818(2,28,18);
    Date feb2800("02/28/00");
    Date NewYearsDay("01-01-19");

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

    cout << feb2818 << endl;
    cout << ++feb2818 << endl;
    cout << --feb2818 << 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 << "one hundred days from now: " << 100 + today << endl << endl;

    // Test minus operators
    Date twentyYearsAgo = today - static_cast<int>(round(20 * 365.25));
    Date final("12/10/18");
    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 << feb2818 << " < " << NewYearsDay << " ? " << (feb2818 < NewYearsDay) << endl;
    cout << feb2818 << " > " << NewYearsDay << " ? " << (feb2818 > 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/24/18

08/24/2018
08/25/2018
08/24/2018

02/28/2018
03/01/2018
02/28/2018

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

01/01/2019
12/31/2018
01/01/2019

30 days from now: 09/23/2018
one hundred days from now: 12/02/2018

Days until the final = 108
Today is August 24, 2018
Twenty years ago was August 24, 1998

02/28/2000 < 01/01/2019 ? true
02/28/2018 < 01/01/2019 ? true
02/28/2018 > 01/01/2019 ? 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().