/* ECP: FILEname=fig14_16.cpp */ /* 1*/ ostream & /* 2*/ operator << ( ostream & Output, const Date & TheDate ) /* 3*/ { /* 4*/ long int TotalDays = TheDate.TotalDays; /* 5*/ int Month = -1, Year = -1; /* 6*/ // Find the year. /* 7*/ while( Date::DaysTillJan1[ ++Year ] < TotalDays ) /* 8*/ ; /* 9*/ Year--; /*10*/ TotalDays -= Date::DaysTillJan1[ Year ]; /*11*/ Year += Date::FirstYear; /*12*/ // Compute the month. /*13*/ if( IsLeap( Year ) ) /*14*/ Date::DaysTillFirstOfMonth[ Mar ] = 60; /*15*/ while( Date::DaysTillFirstOfMonth[ ++Month ] < TotalDays ) /*16*/ ; /*17*/ Month--; /*18*/ // The rest gives the day of the month. /*19*/ TotalDays -= Date::DaysTillFirstOfMonth[ Month ]; /*20*/ // Restore to non-leap year default. /*21*/ Date::DaysTillFirstOfMonth[ Mar ] = 59; /*22*/ // Now output the date. /*23*/ static char *MonthName[ ] = /*24*/ { "Jan", "Feb", "Mar", "Apr", "May", "Jun", /*25*/ "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; /*26*/ Output << MonthName[ Month ] << ' ' << TotalDays /*27*/ << ", " << Year; /*28*/ return Output; /*29*/ }