bool operator!=(const Clock a, const Clock b) { if (a.getHour() == b.getHour() && a.getMin() == b.getMin() && a.getSec() == b.getSec()) { return false; } else {return true;} }
Clock operator+(Clock a, const Clock b) { a.setHour(a.getHour() + b.getHour()); a.setMin(a.getMin() + b.getMin()); a.setSec(a.getSec() + b.getSec()); while(a.getSec() >= 60) { a.setMin(a.getMin()+1); a.setSec(a.getSec()-60); } while(a.getMin() >= 60) { a.setHour(a.getHour()+1); a.setMin(a.getMin()-60); } while(a.getHour() >= 24) { a.setHour(a.getHour()-24); } return a; }
Clock operator-(Clock a, const Clock b) { a.setHour(a.getHour() - b.getHour()); a.setMin(a.getMin() - b.getMin()); a.setSec(a.getSec() - b.getSec()); while(a.getSec() < 0) { a.setMin(a.getMin()-1); a.setSec(a.getSec()+60); } while(a.getMin() < 0) { a.setHour(a.getHour()-1); a.setMin(a.getMin()+60); } while(a.getHour() < 0 ) { a.setHour(a.getHour()+24); } return a; }
int main() { Clock clock; clock.setDay(2); clock.setHour(23); clock.setMinute(59); clock.setSecond(55); cout << "Day: " << clock.getDay() << endl; cout << "Hour: " << clock.getHour() << endl; cout << "Minute: " << clock.getMinute() << endl; cout << "Second: " << clock.getSecond() << endl; cout << endl; system("Pause"); bool done = false; while (!done) { system("cls"); clock.tick(); clock.output(); Sleep(1000); } system("Pause"); return 0; }