Program #7

In this assignment you will write two separate classes. The main class you will write is a Date class. A second class you will write will be used by the Date class. That second class will be a MonthInfo class. You will then test your Date class by compiling it with a test program I will provide.You may not change the test program in any way whatsoever. Note that this means that you may not change any of the specifications of the Date class.

The MonthInfo Class

For the MonthInfo class, here is the complete interface. You should write the implementation.You can place this class in the Date.h file after the Date declaration. Place the implementation in Date.cpp.

class MonthInfo
{
  public:
      // Return a string of length three representing
      // the month (with is 1-12) and vice-versa
      // Provide a reasonable return value in case of errors.
    static string getMonth( int month );
    static int    getMonth( const string & month );

    static int daysInMonth( int month, int year );

  private:
    static bool isLeapYear( int year );
    static const string monthArray[ ];
};

The Date Class

Here is the Date class, skeleton:

// Provide any preprocessor directives, including the #ifndef/#endif trick
class Date
{
  public:
    // Provide three constructors.
    // One takes no parameters, the other two take
    // a month, day, and year, in that order. One of these three-parameter
    // constructors takes the month as an integer, while the other
    // takes it as a string.
 

    // Provide a setDate method that takes three integers:
    // the month, day, and year. There is no return value.
 

    // Provide a printDate method that takes an output stream.
    // There is no return value.
 

    // Provide an equals and a lessThan method. Each take
    // another Date object and return a bool.
 

    // Provide a daysBetween method that takes another Date object
    // and returns the number of days between them.
    // (The number is positive if the current Date is after the parameter Date.

 
    // Provide a dateAfter method that returns the Date after the current Date.
    // Note: the current Date is unchanged.
 

    // Provide a futureDate method that returns the Date in the future.
    // It takes one parameter that tells how many days in the future to look.
    // If the parameter is negative treat it as a zero.
    // Note: the current Date is unchanged.
 

    // Provide a toString method as in Java.
 

  private:
    // Provide three data members: the month, day, and year, represented
    // as integers. The month will range from 1-12, the day from 1-31, and
    // the year from 1600 onwards.
};

In addition to the class methods specified, overload global operator<< to output a Date, and also overload the two equality and four relational operators (as non-class methods). Also, provide an overloaded operator+ and operator- consistent with futureDate and daysBetween. Make operator+ and operator- class methods. Because all of these overloaded operators can be implemented by calling public (named) Date methods, you should not need to use any friend declarations. Simply list each of these methods as declarations in the Date.h file and provide implementations (mostly one liners) in the Date.cpp file.

C++ Constructs To Use

Several C++ constructs discussed in the lecture should be used. Pay attention to parameter passing, use of const for accessor functions, and the ifndef trick.

Test Program

The test program is  assign7.cpp.