// airtime0.cpp // class models time data type // overloads operators #include "airtime0.h" airtime airtime::operator + (airtime right) //overloaded + operator { airtime temp; temp.hours = hours + right.hours; // add data temp.minutes = minutes + right.minutes; if(temp.minutes >= 60) //check for carry { temp.hours++; temp.minutes -= 60; } return temp; // return temporary object } airtime airtime::operator - (airtime right) // subtraction operator { airtime temp; temp.hours = hours - right.hours; temp.minutes = minutes - right.minutes; if (temp.minutes < 0) { temp.minutes += 60; temp.hours -=1; } return temp; } int airtime::operator < (airtime right) // overloaded < operator { if(hours < right.hours) return 1; if(hours == right.hours && minutes < right.minutes) return 1; return 0; } airtime airtime::operator += (airtime right) { hours = hours + right.hours; minutes = minutes + right.minutes; if(minutes >= 60) // check for carry { hours++; minutes -= 60; } return airtime(hours, minutes); // return temporary object } airtime airtime::operator++ () // overloaded prefix ++ operator { ++minutes; if(minutes >= 60) { ++hours; minutes -= 60; } return airtime(hours, minutes); // return temporary object } 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-() // negation operator { // unary minus return airtime(-hours, minutes); } 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, airtime t) { s << t.hours << ':' << t.minutes; return s; }