Ask Question
21 December, 23:23

3. Write a function elapsed_time that takes as its arguments two time structures and returns a time structure that represents the elapsed time (in hours, minutes, and seconds) between the two times. So the call

elapsed_time (time1, time2)

where time1 represents 3:45:15 and time2 represents 9:44:03, should return a time structure that represents 5 hours, 58 minutes, and 48 seconds. Be careful with times that cross midnight

+5
Answers (1)
  1. 22 December, 01:32
    0
    Pseudocode for the function

    time elapse_time (time time1, time time2)

    {

    / * hour * /

    if (time2. hr > = time1. hr) then

    elapse_time. hr = time2. hr - time1. hr;

    else / * pass mid night * /

    elapse_time. hr = 24 + time2. hr - time1. hr;

    endif

    / * min * /

    if (time2. min > = time1. min) then

    elapse_time. min = time2. min - time1. min;

    else

    elapse_time. hr = elapse_time. hr - 1;

    elapse_time. min = 60 + time2. min - time1. min;

    endif

    / * sec * /

    if (time2. sec > = time1. sec) then

    elapse_time. sec = time2. sec - time1. sec;

    else

    elapse_time. min = elapse_time. min - 1;

    elapse_time. sec = 60 + time2. sec - time1. sec;

    endif

    return elapse_time;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “3. Write a function elapsed_time that takes as its arguments two time structures and returns a time structure that represents the elapsed ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers