#include #include "date.h" #include "debug.h" using namespace std; int date::n_days_in_month[12] = {31,28,31,30,31,30, 31,31,30,31,30,31}; date::date() { DEBUG << " ***** Default constructor " << endl; day = 1; month = 1; year = 1900; } date::date(const date& d) { DEBUG << " ***** Copy constructor " << endl; day = d.day; month = d.month; year = d.year; } date::date(const int& d,const int& m,const int& y) { DEBUG << " ***** Three argument constructor " << endl; check_date(d,m,y); day = d; month = m; year = y; } date::~date() { DEBUG << " ***** Destructor " << endl; } void date::set(const int& d,const int& m,const int& y) { check_date(d,m,y); day = d; month = m; year = y; } void date::print() { cout << day << '/'; cout << month << '/'; cout << year << endl; } void date::check_date(const int& d,const int& m,const int& y) { DEBUG << " ***** check date " << endl; int tm; int t; tm=m; if ( (m<1) || (m>12) ) { cout << " ***** WARNING: invalid month " << endl; cout << " ***** Setting month to January" << endl; tm=1; } else t=n_days_in_month[tm-1]; if ( (leap_year(y)) && (tm==2) ) t=29; if ( (d<1) || (d>t) ) cout << " ***** WARNING invalid number of days in month " << endl; } bool date::leap_year(const int& y) { DEBUG << " ***** leap year check " << endl; bool t; t=false; if ( (y/4 )*4 == y ) { t=true; if ( (y/400)*400 == y ) t=true; else if ( (y/100)*100 == y ) t=false; } else t=false; return(t); }