- #1
Jamin2112
- 986
- 12
Today I wanted to use my Windows phone to time myself doing a workout. After realizing that my phone doesn't have a stopwatch, I thought, "Oh, I'll make one." I've never made a Windows phone app before, but Microsoft has some documentation that should guide me later: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj681687(v=vs.105).aspx.
I'd like to do this as correctly as possible. There will be no fancy algorithms involved, which should make it easier to focus on straightforward implementation.
I'm sure you've all used a stopwatch. A stopwatch has two buttons, a left one and a right one. You push the right one to first get the clock running.
While the clock is running, if you push the right button, you pause the clock, and if you push the left button, you put the stopwatch into the next "lap", i.e. it saves the the time up until now in a previous lap. The number of laps is indefinite.
While the clock is paused, if you push the right button, you start the clock again, and if you push the left button, you've made the current lap your final lap and officially ended your workout/race/whatever.
Now, here's what my programming intuition tells me:
Any thoughts so far? I need help gaining a better programming intuition.
I'd like to do this as correctly as possible. There will be no fancy algorithms involved, which should make it easier to focus on straightforward implementation.
I'm sure you've all used a stopwatch. A stopwatch has two buttons, a left one and a right one. You push the right one to first get the clock running.
While the clock is running, if you push the right button, you pause the clock, and if you push the left button, you put the stopwatch into the next "lap", i.e. it saves the the time up until now in a previous lap. The number of laps is indefinite.
While the clock is paused, if you push the right button, you start the clock again, and if you push the left button, you've made the current lap your final lap and officially ended your workout/race/whatever.
Now, here's what my programming intuition tells me:
- This should be a class. A stopwatch, as I've described it, is an object that gets instantiated. So the first thing I should do is write class Stopwatch in Notepad.
- A stopwatch object is in one of 3 states: it's either unstarted, timing a lap or paused on a lap. So I should have a private variable clock_mode cur_mode; where clock_mode is an enumerator enum clock_mode {unstarted, running, paused};
- There should be 2 and only 2 public functions: void start() and void stop(). The inner workings of this object will subsequently be called by those functions.
- The laps need to be stored in a linked list or similar structure. Each new lap gets pushed back onto the structure. This calls for a vector, according to Bjarne Stroustrop: .
- I will be needing to bring in <ctime.h> or whichever library is the one for time.
Any thoughts so far? I need help gaining a better programming intuition.
Last edited by a moderator: