Thread: time class

  1. #1

    time class


    I am trying to modify the definition of this "Time" object so that time is represented internally as the number of seconds before or after noon. I want time before noon to be a negative number, time after noon will be positive and noon will be 0.
    Not for sure what to look at first. Ok the int hour is time 0 to 23, minute and sec o to 59. How do I define noon as 0, then go negative? The time as of now is initialized to 12am as 0. So how do I initialize the time so that 12pm is 0? Then to go in the neg direction? 12 am to 11:59am is negative and 12:01pm to 11:59 pm is positive.

    Thank you

    #ifndef TIME6_H
    #define TIME6_H

    class Time {
    Time( int = 0, int = 0, int = 0 );

    // set functions
    Time &setTime( int, int, int );
    Time &setHour( int );
    Time &setMinute( int );
    Time &setSecond( int );

    int getHour() const;
    int getMinute() const;
    int getSecond() const;

    void printMilitary() const;
    void printStandard() const;
    int hour;
    int minute;
    int second;


  2. #2
    Forgot to mention that I only need 1 data member. See If I could use 2 I would use something like this maybe:

    int sinceMidnight; // seconds since midnight
    int aftermidnight; // seconds after midnight

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need help in time zone
    By Gong in forum C++ Programming
    Replies: 2
    Last Post: 01-03-2007, 04:44 AM
  2. Help with assignment!
    By RVDFan85 in forum C++ Programming
    Replies: 12
    Last Post: 12-03-2006, 12:46 AM
  3. help working with class files for first time
    By jrb47 in forum C++ Programming
    Replies: 12
    Last Post: 11-30-2006, 09:20 AM
  4. I apologize. Good bye.
    By doubleanti in forum A Brief History of
    Replies: 14
    Last Post: 05-03-2002, 06:51 PM
  5. Difficulty superclassing EDIT window class
    By cDir in forum Windows Programming
    Replies: 7
    Last Post: 02-21-2002, 05:06 PM