Can anyone explain this code snippet

I'm revising for my exams and this is one of the question that came up in the previous exams. Can someone help answe the questions at the end. Also what object is 'time_t' and how why do they use 'input_time -= 24*60*60;'?
Read the following code carefully before answering the questions.
time_t normalise(time_t input_time)
     bool finished;
     // This produces a formatted time string like:
     // Thu_Nov_24_18:22: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.

Looks like it is trying to increment the time parameter back to represent midnight of the previous Sunday.

Similar Messages

  • Can anyone explain this code!

    DECLARE
    TYPE t_NumberTableType IS TABLE OF NUMBER
    INDEX BY BINARY_INTEGER;
    v_NumberTable t_NumberTableType;
    v_TempVar NUMBER;
    BEGIN
    v_TempVar := v_NumberTable(1);
    END;
    /

    That code assigns to the variable named v_TempVar the first value of the v_NumberTable collection.
    However, with no input at sight it seems pretty useless and buggy since you will get an error because no value was assigned.

  • Can anyone explain this to me, please. It's a static section question.

    Can anyone explain this to me, please. It's a static section question.
    I came across the following style of programming recently and I would like to know what the Static section is actually doing in the class. Thx.
    Here is the code.
    public class ClassA {
         private static Hashtable ClassAList = new Hashtable();
         private ClassB cB;
         private Vector goodLink;
         private Hashtable classCList;
         static
              ClassA cA = new ClassA();
              ClassAList.put("whatever", cA);
         public static ClassA getClassA()
              return (ClassA) ClassAList.get("whatever");

    hi,
    The static section shall be loaded before it's constructor is called. (i.e at the time of loading the class). Therefore making it available for any other objects to call.
    hope this clarifies ur question
    prasanna

  • Can soemone explain this code to me

    can someone explain this code to me
    import javax.swing.*;
    import BreezySwing.*;
    import java.util.Random;
    public class PennyPinch extends GBFrame
         private JButton enterButton;
         private JTextArea outputArea;
         private int[][] board = {{1,1,1,1,1},{1,2,2,2,1},{1,2,3,2,1},{1,2,2,2,1},{1,1,1,1,1}};
         private boolean[][] landing = new boolean[5][5];
         private int total;
         public PennyPinch()
         enterButton = addButton ("Pitch",2,1,1,1);
         outputArea = addTextArea("",4,1,3,4);
         public void pitch()
              Random generator = new Random();          
              int randomRow = generator.nextInt(5);
              int randomColumn = generator.nextInt(5);
              total += board[randomRow][randomColumn];
              landing[randomRow][randomColumn] = true;
         public void buttonClicked (JButton buttonObj)
              pitch();
              displayList(board, outputArea);
         private void displayList(int a[][], JTextArea output)
    output.setText("");
              for (int row = 0; row < 5; row++)
    for (int col = 0; col < 5; col++){
    if(landing[row][col] ==true)
                                  output.append(Format.justify('r',"P", 3) + " ");
                                  if (col == 4)
    output.append("\n");
                             else
                             output.append(Format.justify('r', a[row][col], 3) + " ");
                             if (col == 4)
    output.append("\n");                    }
              output.append("the total is " + total);
         public static void main (String[] args)
    PennyPinch theGUI = new PennyPinch();
    theGUI.setSize (300, 300);
    theGUI.setVisible(true);
    }

    Knowing toilets or studying under George?What kind pervert are you?
    What is written in public toilets o/c!Ah yes I see, I found example questions.
    2:3.4 please complete the following well known saying
    by filling in the blank
    Whilst you are reading what I put
    You are blank on your foot
    2:3.5 Upon seeing the announcement 'Toilet
    tennis' and following the instruction ' please
    see other wall for details' what is the standard
    message on the other wall.2:3.4. is the correct answer 'micturating' ?
    2:3.5. I believe the answer is Ibidem.

  • Can anyone explain this: Numeric or Value Error Line 1

    I have a stored procedure that starts out like so:
    PROCEDURE test_proc(param1 IN VARCHAR2, param2 IN VARCHAR2, param3 OUT
    SYS_REFCURSOR) IS
    v_var varchar2(5);
    BEGIN
    SELECT * FROM. . .
    The procedure tested fine in PL/SQL Developer. When calling from
    ODP.NET like so. . .
    OracleCommand cmd = new OracleCommand("test_proc", <connection>);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add("param1", "somevalue");
    cmd.Parameters.Add("param2", "XX");
    cmd.Parameters.Add("param3", OracleDbType.RefCursor,
    ParameterDirection.Output);
    DataSet ds = new DataSet();
    OracleDataAdapter da = new OracleDataAdapter(cmd);
    con.Open();
    da.fill(ds);
    con.Close();
    . . .the procedure executed as expected. If I changed the value of
    param2 to "XXX" or any value three chars long I got the "ORA-06502:
    Numeric or Value Error at Line 1" error.
    After beating my head against the wall for hours, I tried changing the
    size of v_var to 50, and the error disappeared. Mind you, the error
    was being thrown long before v_var was being set further down in the
    proc. Even more interesting is that the possible values of v_var were
    all less than 5 chars wide. Most interesting: the value of p_param2 had nothing whatever to do with v_var.
    Can anyone explain this?

    Hi,
    Is your database 9206 by chance? Re: Error ORA-06502 PL/SQL
    Cheers,
    Greg

  • Can anyone explain this query.?

    Can anyone explain this query.?
    select nvl(s.p_id,q.p_id),nvl(s.p_type,q.p_type),nvl(s.p_line,q.p_line),
    nvl(s.sales2004,0),nvl(s.sales2005,0),nvl(q.quota2004,0),nvl(q.quota2005,0)
    from sales s
    full outer join quota q on(s.p_id = q.p_id and s.p_type=q.p_type and s.p_line=q.p_line)

    from sales s full outer join quota qTable quota is outer joined to table sales , if there are no matching records in table quota then also the query retuns the sales record with null values for the corresponding quota record columns
    NVL() has been used to handle such cases

  • HT3275 Please can anyone explain this to me

    Please can anyone explain this to me - thank you -
    Time Machine couldn't complete the backup to time capsule - The backup disk image “/Volumes/Data-1/Alyson’s iMac.sparsebundle” is already in use.

    The explanation is a long standing bug in Lion and Mountain Lion, but what you might really be asking is how to fix the problem.
    Pull the power cord from the back of the Time Capsule
    Wait a few minutes
    Plug the power cord back in
    If that does not fix the problem you will need to dig deeper.  See #C12 in Pondini's excellent Time Machine - Troubleshooting.
    http://pondini.org/TM/Troubleshooting.html

  • When i go to my music and play a song it sounds like my headphones are blown but when i play songs on youtube they sound fine, can anyone explain this to me? please and thank you

    when i go to my music and play a song it sounds like my headphones are blown but when i play songs on youtube they sound fine, can anyone explain this to me? please and thank you

    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Unsync all music and resync
    - Reset all settings      
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                 
    iOS: How to back up                                                                
    - Restore to factory settings/new iOS device.      

  • TS3988 I have an icloud account and I view my mail with Mail V5.2. I recieve my email but the senders get messages saying the delivery failed. Can anyone explain this or help me.

    I have an icloud account and I view my mail with Mail V5.2. I recieve my email but the senders get messages saying the delivery failed. Can anyone explain this or help me.

    Thank you for replying.    Yes I deleted the old email address..   

  • I went to silence my iPhone 5s and had a box pop up--looked like one of those boxes telling me turning on Location Services would help--telling me I needed to change my password within 60 minutes.....I turned the phone off.  Can anyone explain this to me?

    I went to silence my iPhone 5s and had a box pop up--looked like one of those boxes telling me turning on Location Services would help--telling me I needed to change my password within 60 minutes.....I turned the phone off.  Can anyone explain this to me?

    I went to silence my iPhone 5s and had a box pop up--looked like one of those boxes telling me turning on Location Services would help--telling me I needed to change my password within 60 minutes.....I turned the phone off.  Can anyone explain this to me?

  • HT1430 I downloaded the lateest update and I can't turn off my apps like I did on 6os. The 7os is different and I can't seem to find out if apps turn off now by just closing them. Can anyone explain this to me? Please

    I downloaded the lateest update and I can't turn off my apps like I did on 6os. The 7os is different and I can't seem to find out if apps turn off now by just closing them. Can anyone explain this to me? Please

    Double tap the Home button and swipe the app preview page up
    iOS 7  also allows apps to run while they aren't open.
    You can manage these here:
    Settings > General > Background App Refresh

  • Post Moved Can anyone explain this baffling puzz...

    Post moved to Other BB Queries http://community.bt.com/t5/Other-BB-Queries/Can-anyone-explain-this-baffling-puzzle-with-BT-Total-BB...
    If you want to say thanks for a helpful answer,please click on the Ratings star on the left-hand side If the reply answers your question then please mark as ’Mark as Accepted Solution’

    I tend to think that the comments about MAC address filtering and wireless security are a bit misleading - if these things were the problem then it would not work at all as opposed to working sporadically.
    I must admit, reading your post I had exactly the same problem moving into a new house last year, my desktop PC in my room would get terrible wireless reception with constant erroring and was practically unusable whilst a laptop sat next to it was just fine. I tried a million different things and eventually bought an external wireless antenna like the one here:
    Edimax EA-IO7D 7dBi Indoor Omni-Directional High Gain Antenna with Desktop Stand - 1m Cable
    It solved the problem for me though I am still mystified as to what the problem is - I suspect that there is something in the environment causing interference though I don't know what. My house is of average size and fairly modern with thin walls so I would not anticipate any problems.
    Some things to try are to move the PC right next to the hub (or vice versa, whichever is easier) and see if this improves things or borrow a wireless router from a friend, turn off all encryption and see what signal strength you get there.

  • The home button has stopped working on my iphone 5c. Did the same a few months ago and recovered 24hrs later. Can anyone explain this problem. Phone still in warranty. Had steam issue recently but this was after last home button episode.

    Have an iphone 5c 8g. The home button has stopped working. Did the same a few months ago and recovered 24hrs later. Can anyone explain this problem. Phone still in warranty. Had steam issue recently but this was after last home button episode and no evidence of damage.

    If you are playing in hockey arenas a lot or if you are bringing it into bathroom same time as shower it may not seem like much but overtime the steam can acquire and build up in the phones usb dock flex cable swell as the home button flex cable. Bring again into apple store and should be covered under warranty again. could also be a delay in a 8gb 5c software may just be very lag.

  • Can anyone explain this behavior and tell me how to fix it?

    Using NetBeans 6.5 on Windows, Glassfish v2.1
    I have a JSF application with a page that has a tab set.
    On one of the tabs I have a panel with company information.
    One of the components on the page is an InputText field with the value bound to a session bean variable.
    The tab also has an Add button.
    Here is what the JSP looks like for the input text and button components
       <h:inputText binding="#{MainPage.companyNameTF}" id="companyNameTF" readonly="#{SessionBean1.readOnlyFlag}"
       <h:commandButton action="#{MainPage.mainAddBtn_action}" disabled="#{SessionBean1.disableEdit}" id="mainAddBtn"
            style="font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-weight: bold; left: 425px; top: 380px; position: absolute; width: 75px" value="Add"/>
         This is all plain vanilla stuff and I would expect that when the Add button is pushed, the session bean property would be filled with
    the value entered in the input text field.
    In the java code for the page, I have a method to process the Add button push.
    Originally, it just called a method in the session bean to check that a value was entered in the input text field by checking the bound
    session bean property.
    For some reason, that was not getting filled and I was getting either a null or empty string rather than the value in the text field.
    I added some checking in the method that processes the Add button push so I could check the values in the debugger.
    Here is a sample of that code:
        public String mainAddBtn_action() {
            String s = sb1.getCompanyName();
            s = (String)this.companyNameTF.getValue();
            s = (String)this.companyNameTF.getSubmittedValue();I check this in the debugger and NONE of the variants that I have listed have the value that was entered into the text field.
    The submittedValue is null and the others are empty strings (that is what they were initalized to).
    This is all pertty straight forward stuff and I am at a loss to explain what is happening.
    Can anyone expain this behavior, and, most important, how can I force the values to be present when the Add button is pushed.
    I have never experienced this problem before, and have no clue what is causing it.
    Thanks.

    Basically, the component bindings are just being used in plain vanilla get/set modes.
    I set them to "" when I do a clear for the fields and they are set to a value via the text field.
    No other action other than to read the values via get to insert them into the database.
    And, I always use the get/set methods rather than just setting the value directly.
    This is what is so strange about this behavior - I have created dozens of database add/update/delete pages using this same model and have not had a problem with them - even in a tab context.
    Not a clue why this one is different.
    I did notice that I had an error on the page (in IE7, you get a small triangle warning sign when something is not right).
    I figured that might be the problem - maybe buggering up the rendering process.
    I tracked that down and do not get that anymore (it had to do with the PDF display I was trying to get working a while back), but that did not resolve the problem.
    I don't think there are any tab conflicts - none of the components are shared between tabs, but I will see what happens when I move a couple of the components out of the tab context.
    I noticed that it seems to skip a cycle. Here is what I can do.
    1) Fill in text fields and add a record - works fine the first time.
    2) Clear the text fields
    3) Enter new data in the text fields and push Add
    4) I get an error saying fields are blank from my data check process.
    5) Enter new data and push Add - the record is added with the new data.
    My work around is to not enter data in step 3 and just accept the error message in step 4, then go ahead and enter the real data in step 5.
    Very ugly, but it works every time.

  • Can anyone explain this Calendar beheaviour?

    This is my code
    public static void main(String[] args) {
    Calendar checkDate = Calendar.getInstance();
    System.out.println(checkDate.getTime());
    checkDate.set(Calendar.HOUR, 23);
    System.out.println(checkDate.getTime());
    checkDate.set(Calendar.MINUTE, 59);
    System.out.println(checkDate.getTime());
    checkDate.set(Calendar.SECOND, 59);
    System.out.println(checkDate.getTime());
    checkDate.set(Calendar.MILLISECOND, 0);
    System.out.println(checkDate.getTime());
    checkDate.set(Calendar.DAY_OF_MONTH, 1);
    System.out.println(checkDate.getTime());
    checkDate.add(Calendar.DAY_OF_MONTH, -1);
    System.out.println(checkDate.getTime());
    System.out.println("---------------------------------");
    Calendar checkDate2 = Calendar.getInstance();
    checkDate2.set(Calendar.HOUR, 23);
    checkDate2.set(Calendar.MINUTE, 59);
    checkDate2.set(Calendar.SECOND, 59);
    checkDate2.set(Calendar.MILLISECOND, 0);
    checkDate2.set(Calendar.DAY_OF_MONTH, 1);
    checkDate2.add(Calendar.DAY_OF_MONTH, -1);
    System.out.println(checkDate2.getTime());
    So i'm basically doing twice the same, but the second time without the sysouts.
    But the output is:
    Thu Nov 08 18:18:43 CET 2007
    Fri Nov 09 11:18:43 CET 2007
    Fri Nov 09 11:59:43 CET 2007
    Fri Nov 09 11:59:59 CET 2007
    Fri Nov 09 11:59:59 CET 2007
    Thu Nov 01 11:59:59 CET 2007
    Wed Oct 31 11:59:59 CET 2007
    Thu Nov 01 11:59:59 CET 2007
    Can anyone explain me how this is possible?

    Cinnam wrote:
    practissum wrote:
    Here we go - use HOUR_OF_DAY instead of HOUR. I have no idea why, but this seems to work. Anyone out there have any ideas?Yes, that does the trick. My explanation would be that HOUR is used for 12 hour cycle, HOUR_OF_DAY is for 24 hour cycle. The calendar is in lenient mode because it didn't throw an exception when the OP was HOUR with the value 23. That means it will accept the value 23 and will recompute the other fields - it will basically set the hour to 11 and then add 12 hours. I guess the fields don't get recomputed if some get() isn't called, which is why the System.out.println() makes a difference.Ahh, that would make a lot of sense. I'll accept it as a valid answer/explanation. But, of course, I suppose the only person who has to do that is the OP...
    Anyhow, from my perspective, thanks!

Maybe you are looking for

  • How can you set up more than one device on iTunes. I have an iPad, iPod, itouch and iPhone. I don't want the same on all devices.

    How can you set up more than one device on iTunes? I have an iPad, iPod, itouch and iPhone. I don't want the same on all devices. I have all my music/videos on iTunes on my mac book pro. Can you set up separate folders for each device and drop in wha

  • Installing Microsoft XP on Core 2 Duo

    Gentlemen, I have attempted to install Windows on the Mac, without success so far. I downloaded Boot Camp from Apple and followed the installation instructions, including the burning of a disk of Mac drivers. I then loaded the Windows XP Pro disk wit

  • How to disable on-board mic

    I use a special headset designed for my ear.  When I plug this 4 pole male jack into my droid, the on-board speakers are disabled, but the on-board mic is not disabled.  The headset is wire properly, according to the droid pin-out. How can I disable

  • BLF SpeedDials NO Find Button

    Hi Guy,please take a look to the picture attached . I can't find the Find button to be able to search for directory numbers,instead of uing the drop down list. I have this button in different cucm servers other than this one i am working with now.

  • Field is missing an escape character for a quote

    Hello , any solution for below error in SSIS. Field is missing an escape character for a quote.Unable to update PK WHERE clause.Error processing data batch. i tried with convert tool. I ignored that column but still i am facing same error. Regards, A