//-------------------------------------------------------------------- // // Laboratory 1 logbook.cpp // // SOLUTION: Implementation of the Logbook ADT // //-------------------------------------------------------------------- #include #include //#include #include "logbook.h" //-------------------------------------------------------------------- Logbook::Logbook ( int month, int year ) // Constructor. Creates an empty logbook for the specified month. : logMonth(month), logYear(year) { int j; // Loop counter for ( j = 0 ; j < 31 ; j++ ) entry[j] = 0; } //-------------------------------------------------------------------- void Logbook::putEntry ( int day, int value ) // Stores entry for the specified day. { entry[day-1] = value; } //-------------------------------------------------------------------- int Logbook::getEntry ( int day ) const // Returns entry for the specified day. { return entry[day-1]; } //-------------------------------------------------------------------- int Logbook::month () const // Returns the logbook month. { return logMonth; } //-------------------------------------------------------------------- int Logbook::year () const // Returns the logbook year. { return logYear; } //--------------------------------------------------------------------- int Logbook::daysInMonth () const // Returns the number of days in the logbook month. { int result; // Result returned switch ( logMonth ) { case 4 : case 6 : case 9 : case 11 : result = 30; break; case 2 : if ( leapYear() ) result = 29; else result = 28; break; default : result = 31; } return result; } //-------------------------------------------------------------------- int Logbook::leapYear () const // If the logbook month occurs during a leap year, then returns 1. // Otherwise, returns 0. { return ( logYear % 4 == 0 && ( logYear % 100 != 0 || logYear % 400 == 0 ) ); }