// File: Year.cpp // Simple class for Year; days count improved // Prepared by Dr. Spiegel #include "Year.h" int Year::daysInYear=365; /*! * Default Constructor - inactive * */ Year::Year(){} /*! * Constructor: Mutator: Set the date components * \param monthVal month * \param dayVal day * \param yearval year * */ Year::Year(int monthVal,int dayVal,int yearVal) {month=monthVal; day=dayVal; year=yearVal; } /*! * Inspector - this should be static, as the value is the same for all * non-leap years * return Days in a non-leap year * */ int Year::getDaysInYear() {return(daysInYear);} /*! * Facilitator: Determine days elapsed from data members * Note exploitation of fall through behavior in switch * */ int Year::daysElapsed() {int days=0; switch (month) { // if month is Dec, add days for months 1-11, plus days in Dec case 12:days+=30; case 11:days+=31; case 10:days+=30; case 9:days+=31; case 8:days+=31; case 7:days+=30; case 6:days+=31; case 5:days+=30; case 4:days+=31; case 3:days+=28; // if month is Feb, add days for month 1, plus days in Feb case 2:days+=31; } days+=day; return(days); } /*! * * */ double Year::percentOfYear(int daysElapsed) {return(100.0*daysElapsed/getDaysInYear());} /*! * Determine if a year is a leap year * Static, so it must take the year as an argument (Why??) * */ bool Year::isLeapYear(int Year) {return((Year%4==0 && Year%100!=0) || Year%400==0);}