×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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.

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

    What exactly do you need help on? Can you give us a small example?

James P. Cottingham

International Veneer Co., Inc.
All opinions are mine alone and do not necessarily reflect those of my employer.

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

(OP)
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.
To be more specific the following class definition is provided for a class Time representing a time in hours and minutes:

class Time
 {
  private:
    int h;
    int m;
  public:
    Time();
    Time( int H, int M);
    void setTime( int H, int M);
    void getTime( int&H, int&M);
    void showTime();
    void increment();
 };

I have to write the code for a function increment() that adds one minute to the time each time it is called, eg.
         for(i=0;i<90;i++)
         t1.increment();
   will step the time on by 1 hour and 30 minutes.

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

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

    Since this is a test, I won't do all the code but I'll see if I can help you just the same.

    What it sounds like is you want increment() to add 1 to m. The trick is that if m is equal to 60 then you have to set m to 0 and add 1 to h. increment will have to see what h and m is before adding 1 to m. Am I on the right track?

increment()
{
    //get h and m

    m++;
    if (m == 60) // what happens if m > 60???
    {
        m = 0;
        h++;
    }

    //set h and m
}

    Is this what you needed? The one problem is does setTime have any error checking for m > 60? If not, you may need to check for that in your function.

James P. Cottingham

International Veneer Co., Inc.
All opinions are mine alone and do not necessarily reflect those of my employer.

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

(OP)
Thanks a loy for your help. I hope we meet again. :)

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close