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=
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> {<br> private:<br> int h;<br> int m;<br> public:<br> Time();<br> Time( int H, int M);<br> void setTime( int H, int M);<br> void getTime( int&H, int&M);<br> void showTime();<br> void increment();<br> };<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> for(i=0;i<90;i++)<br> t1.increment();<br> 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
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> 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> //get h and m<br><br> m++;<br> if (m == 60) // what happens if m > 60???<br> {<br> m = 0;<br> h++;<br> }<br><br> //set h and m<br>}<br></font><br> Is this what you needed? The one problem is does <i>setTime</i> have any error checking for <i>m</i> > 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=
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.