// airtime.cpp // class models time data type // overloads operators #include "airtime.h" airtime airtime::operator + (const airtime& right) const //overloaded + operator { int temphrs = hours + right.hours; // add data int tempmins = minutes + right.minutes; if(tempmins >= 60) //check for carry { temphrs++; tempmins -= 60; } return airtime(temphrs, tempmins); // return unnamed temporary object } int airtime::operator < (const airtime& right) const // overloaded < operator { if(hours < right.hours) return 1; if(hours == right.hours && minutes < right.minutes) return 1; return 0; } airtime& airtime::operator += (const airtime& right) { hours += right.hours; // add argument to us minutes += right.minutes; if(minutes >= 60) // check for carry { hours++; minutes -= 60; } return *this; // return by reference } airtime& airtime::operator++ () // overloaded prefix ++ operator { ++minutes; if(minutes >= 60) { ++hours; minutes -= 60; } return *this; // return object by reference } airtime airtime::operator++ (int) // overloaded postfix ++ operator { airtime temp(hours, minutes); // save original value ++minutes; // increment this object if(minutes >= 60) { ++hours; minutes -= 60; } return temp; // return old original value } airtime airtime::operator-() const // negation operator { // unary minus return airtime(-hours, minutes); } airtime airtime::operator-(const airtime& right) const // subtraction operator { int thours = hours - right.hours; int tminutes = minutes - right.minutes; if (tminutes < 0) { tminutes += 60; thours -=1; } return airtime(thours, tminutes); } istream& operator >> (istream& s, airtime& t) // get time { char dummy; // from user cout <<"\nEnter time (format 12:59): "; // using s >> t.hours >> dummy >> t.minutes; // overloaded >> operator return s; } ostream& operator << (ostream& s, const airtime& t) { s << t.hours << ':' << t.minutes; return s; }