Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help me create function increment() to put in a clock

Status
Not open for further replies.

Clock

Programmer
Jul 25, 2000
6
GR
I am trying to create a clock and I want help in the function increment that adds one minute to the time each time it is called.
 
&nbsp;&nbsp;&nbsp;&nbsp;What exactly do you need help on? Can you give us a small example?<br> <p>James P. Cottingham<br><a href=mailto: > </a><br><a href= Veneer Co., Inc.</a><br>All opinions are mine alone and do not necessarily reflect those of my employer.
 
Firstly, thanks for your interest in my query.I am a student and my query concerns a test I have to do. They ask me to write the code for a function increment() that adds one minute to the time each time it is called.<br>To be more specific the following class definition is provided for a class Time representing a time in hours and minutes:<br><br>class Time<br>&nbsp;{<br>&nbsp;&nbsp;private:<br>&nbsp;&nbsp;&nbsp;&nbsp;int h;<br>&nbsp;&nbsp;&nbsp;&nbsp;int m;<br>&nbsp;&nbsp;public:<br>&nbsp;&nbsp;&nbsp;&nbsp;Time();<br>&nbsp;&nbsp;&nbsp;&nbsp;Time( int H, int M);<br>&nbsp;&nbsp;&nbsp;&nbsp;void setTime( int H, int M);<br>&nbsp;&nbsp;&nbsp;&nbsp;void getTime( int&H, int&M);<br>&nbsp;&nbsp;&nbsp;&nbsp;void showTime();<br>&nbsp;&nbsp;&nbsp;&nbsp;void increment();<br>&nbsp;};<br><br>I have to write the code for a function increment() that adds one minute to the time each time it is called, eg.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;for(i=0;i&lt;90;i++)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;t1.increment();<br>&nbsp;&nbsp;&nbsp;will step the time on by 1 hour and 30 minutes.<br><br>That is exactly the question in the test.I hope now you have understood what I am looking for. I wiil be gratefull if you could help me as it is the first time I use the
 
&nbsp;&nbsp;&nbsp;&nbsp;Since this is a test, I won't do all the code but I'll see if I can help you just the same. <br><br>&nbsp;&nbsp;&nbsp;&nbsp;What it sounds like is you want <i>increment()</i> to add 1 to <i>m</i>. The trick is that if <i>m</i> is equal to 60 then you have to set <i>m</i> to 0 and add 1 to <i>h</i>. <i>increment</i> will have to see what <i>h</i> and <i>m</i> is before adding 1 to <i>m</i>. Am I on the right track?<br><font color=blue><br>increment()<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp;//get h and m<br><br>&nbsp;&nbsp;&nbsp;&nbsp;m++;<br>&nbsp;&nbsp;&nbsp;&nbsp;if (m == 60) // what happens if m &gt; 60???<br>&nbsp;&nbsp;&nbsp;&nbsp;{<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;m = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;h++;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;//set h and m<br>}<br></font><br>&nbsp;&nbsp;&nbsp;&nbsp;Is this what you needed? The one problem is does <i>setTime</i> have any error checking for <i>m</i> &gt; 60? If not, you may need to check for that in your function.<br> <p>James P. Cottingham<br><a href=mailto: > </a><br><a href= Veneer Co., Inc.</a><br>All opinions are mine alone and do not necessarily reflect those of my employer.
 
Thanks a loy for your help. I hope we meet again. :)<br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top