#pragma once #include #include class Date; /////////////////////////// // Function declarations // /////////////////////////// // Insert date into an output stream. std::ostream &operator<<( std::ostream &out, Date const &date ); ////////////////////// // Class definition // /////////////////////// class Date { public: // Construct the specified date. Date( unsigned int const year, unsigned int const month, unsigned int const day ); // Return the year. unsigned int year() const; // Return the month. unsigned int month() const; // Return the day. unsigned int day() const; // Move to the next date and return this object. Date &operator++(); // Move to the next date and return the previous value. Date operator++( int ); // Move to the previous date and return this object. Date &operator--(); // Move to the previous date and return the previous value. Date operator--( int ); // Return a string representation of this date. std::string to_string() const; private: // Store the year, month and day. unsigned int year_; unsigned int month_; unsigned int day_; // Determine whether the specified year is a leap year. static bool is_leap_year( unsigned int const year ); // Return the number of days in the specified month. static unsigned int days_in_month( unsigned int const year, unsigned int const month ); // Determine whether the specified values form a valid date. static bool is_valid( unsigned int const year, unsigned int const month, unsigned int const day ); };