#include #include "smalldate.h" using namespace std; const int smalldate::pre[] = { 0, //dummy element to give january subscript 0 0, //january pre[ 1] + length[ 1], //february pre[ 2] + length[ 2], //march pre[ 3] + length[ 3], //april pre[ 4] + length[ 4], //may pre[ 5] + length[ 5], //june pre[ 6] + length[ 6], //july pre[ 7] + length[ 7], //august pre[ 8] + length[ 8], //september pre[ 9] + length[ 9], //october pre[10] + length[10], //november pre[11] + length[11] //december }; void smalldate::print(ostream& ost) const { div_t d = div(day, 365); if (d.rem < 0) { //Make sure remainder is non-negative. d.rem += 365; --d.quot; } int julian = d.rem + 1; //Julian date is in range 1 to 365, not 0 to 364. int month; //uninitialized variable for (month = 1; julian > length[month]; ++month) { julian -= length[month]; } ost << month << "/" << julian << "/" << d.quot; }