data structure lab 1

ahmeddxn7
DateType.cpp

#include "DateType.h" void DateType::Initialize(int newMonth, int newDay, int newYear) // Post: month is set to newMonth; day is set to // newDay; year is set to newYear. { month = newMonth; day = newDay; year = newYear; } int DateType::GetMonth() const // Post: Class member month is returned. { return month; } int DateType::GetDay() const // Post: Class member day is returned. { return day; } int DateType::GetYear() const // Post: Class member year if returned. { return year; } //Copied from Dale int DateType::lilian() const { // Returns the Lilian Day Number of this date. // Precondition: This Date is a valid date after 10/14/1582. // // Computes the number of days between 1/1/0 and this date as if no calendar // reforms took place, then subtracts 578,100 so that October 15, 1582 is day 1. const int subDays = 578100; // number of calculated days from 1/1/0 to 10/14/1582 int numDays = 0; // Add days in years. numDays = year * 365; // Add days in the months. if (month <= 2) numDays = numDays + (month - 1) * 31; else numDays = numDays + ((month - 1) * 31) - ((4 * (month-1) + 27) / 10); // Add days in the days. numDays = numDays + day; // Take care of leap years. numDays = numDays + (year / 4) - (year / 100) + (year / 400); // Handle special case of leap year but not yet leap day. if (month < 3) { if ((year % 4) == 0) numDays = numDays - 1; if ((year % 100) == 0) numDays = numDays + 1; if ((year % 400) == 0) numDays = numDays - 1; } // Subtract extra days up to 10/14/1582. numDays = numDays - subDays; return numDays; } //Finish this function********** //Input: DateType d - a date to compare this DateType to //Output: int - Equal: 0 // Less Than: -1 // Greater Than: 1 //This function will return 0 if the DateType objects are equal, etc. int DateType::compareTo(const DateType d){ if(lilian() < d.lilian()) { return -1; } else if(lilian() > d.lilian()) { return 1; } else { return 0; } }