Thread: chronological arrangement

  1. #1
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528

    chronological arrangement

    I have a class that I can simply define as (I have simplified the class):
    Code:
    class Time{
    public:
    
    Time(int hour,int minute,int second):hour(hour),minute(minute),second(second){}
    
    private:
    
    int hour;
    
    int minute;
    
    int second;
    
    };
    Is it possible to check for chronological arrangement of two time objects most possibly without using an if statement ?
    Well this is off topic but there may be a python guru around,..is it possible to do similar thing in python?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Huh, why would you not use an if statement, and what does this have to do with Python?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by laserlight View Post
    Huh, why would you not use an if statement
    I was just remembering having done it somwhere
    what does this have to do with Python?
    I thought that I could make the variables into a list for each object and compare the two lists.Python allows that ?

    I bet am just behaving like an idiot.
    Why not just convert everything to seconds and compare?

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    make function getSeconds() for class

    And make a comparison function to return a difference of these 2 values. Looking at the sign of the difference you will know which object is "younger".

    No function will use an if... How you write the rest of the code without it... well, it's up to you.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Yes it's possible, through various techniques, but that doesn't mean there's any reason to tell you about those ways since there is no good reason to use them.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  6. #6
    Tweaking master Aslaville's Avatar
    Join Date
    Sep 2012
    Location
    Rogueport
    Posts
    528
    Quote Originally Posted by iMalc View Post
    Yes it's possible, through various techniques, but that doesn't mean there's any reason to tell you about those ways since there is no good reason to use them.
    Give me a hint,..maybe I might need them in future.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String array arrangement problem
    By Cheerio in forum C Programming
    Replies: 1
    Last Post: 05-02-2011, 07:40 PM
  2. arbitrary column arrangement of memory debug window?
    By m37h0d in forum C++ Programming
    Replies: 2
    Last Post: 11-10-2009, 11:31 AM
  3. whats the best arrangement in writing to a FILE?
    By Huskar in forum C Programming
    Replies: 1
    Last Post: 03-30-2009, 07:12 AM
  4. arrangement of the string in every possible way
    By vijayr_singh in forum C Programming
    Replies: 2
    Last Post: 12-13-2006, 06:46 AM
  5. data arrangement and sorting.
    By cdkiller in forum C++ Programming
    Replies: 3
    Last Post: 02-15-2006, 01:55 AM