#include <iostream>
using namespace std;

class Clock {
public:
    void reset(); // Sets the clock to 00:00
    void pulse(); // Advances the clock to the next minute
    int get_hours() const; // Gets the hours of the clock
    int get_minutes() const; // Gets the minutes of the clock
private:
    int hours; // Hours (between 0 and 23)
    int minutes; // Minutes (between 0 and 59)
};

void Clock::reset() {
    hours = 0; // Reset hours to 0
    minutes = 0; // Reset minutes to 0
}

void Clock::pulse() {
    minutes++; // Increment minutes
    if (minutes == 60) { // If minutes reach 60, reset to 0 and increment hours
        minutes = 0;
        hours++;
        if (hours == 24) { // If hours reach 24, reset to 0
            hours = 0;
        }
    }
}

int Clock::get_hours() const {
    return hours; // Return the current hours
}

int Clock::get_minutes() const {
    return minutes; // Return the current minutes
}

int main() {
    Clock my_clock;
    my_clock.reset();

    for (int i = 0; i < 100; i++) { 
        my_clock.pulse(); 
    }
    cout << my_clock.get_hours() << endl;
    cout << "Expected: 1" << endl;
    cout << my_clock.get_minutes() << endl;
    cout << "Expected: 40" << endl;

    for (int i = 0; i < 70; i++) { 
        my_clock.pulse(); 
    }
    cout << my_clock.get_hours() << endl;
    cout << "Expected: 2" << endl;
    cout << my_clock.get_minutes() << endl;
    cout << "Expected: 50" << endl;

    for (int i = 0; i < 1270; i++) { 
        my_clock.pulse(); 
    }
    cout << my_clock.get_hours() << endl;
    cout << "Expected: 0" << endl;
    cout << my_clock.get_minutes() << endl;
    cout << "Expected: 0" << endl;

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: