Code Comprehension Exercise

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Deven Oza
    New Member
    • Oct 2006
    • 53

    Code Comprehension Exercise

    Code Comprehension Exercise

    Read the following code carefully before answering the questions.

    unsigned long normalise(unsig ned long input_time)
    {

    bool finished;

    // This produces a formatted time string like:
    // Thu_Nov_24_18:2 2:48_1986
    string str_time = format_time( input_time );

    while( str_time.substr (1,3) != "Sun")
    {
    input_time -= 24*60*60;
    str_time = format_time( input_time );
    }

    while( str_time.substr (11,2) != "00" )
    {
    input_time -= 60*60;
    str_time = format_time( input_time );
    }

    while( str_time.substr (14,2) != "00")
    {
    str_time = format_time( input_time );
    input_time -= 60;
    }

    while( str_time.substr (17,2) != "00")
    {
    input_time -= 1;
    str_time = format_time( input_time );
    }

    return input_time;
    }

    1) Briefly explain what you think the overall purpose of this function is (do not describe each line of code).

    2) There are two bugs in this code that prevent it from functioning correctly; circle them.

    3) What would actually happen when this code is run?

    (a) as originally written?
    (b) with the first bug fixed?

    4) Discuss the efficiency of the code assuming the bugs have been fixed.

    5) Given that input_time actually represents an integer value in seconds since the epoch – and has the value 0 at precisely "Thu Jan 1 00:00:00 1970", write
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Is it part of Oracle SQL,pl/sql ???

    Comment

    • Deven Oza
      New Member
      • Oct 2006
      • 53

      #3
      Originally posted by debasisdas
      Is it part of Oracle SQL,pl/sql ???
      this is the part of pl/sql.

      if you know how to solve this then please help me.

      Thank you

      Comment

      Working...