## CS 115 Lab 5 If Control Structures (Individual)

### 60 Points

Due by Sunday, September 23, midnight
If you turn it in after midnight but before 9:00 am the next day, you will lose half credit. After 9:00 am, you lose all the points. Use the Canvas link to submit your program.

Educational goals of this lab - verify that every student can

• understand the if control structures
• practice with end=

The problem:

There are many programs which work with clock time, like payroll programs and calendar programs. Many times two times, expressed as hours, minutes and seconds, need to be compared to determine which one comes first. You can assume for this program that the two times are in the same DAY, and a 24-hour clock is used, so the times range from 0:00:00 to 23:59:59.

There are 3 possible results of comparing two times, Time1 is earlier than Time2, Time1 is later than Time2 or the times are the same.

## NOTES:

1. Do NOT convert the times into total seconds - that makes the logic too easy! compare the times piece by piece, hours, then minutes then seconds.

2. Make SURE you are comparing integers and not strings! If you compare strings like "9" and "23" you will be surprised at the result!

INSTRUCTIONS:

• (10 points) Individual Problem #1: Test Cases

Put the answers to the test plan as a comment at the bottom of your .py file. It should be the expected output from the above problem, given the inputs in the case.
Description Inputs Expected Outputs
hrs1,min1,sec1hrs2,min2,sec2
Time1 earlier than Time2, b/c seconds 5,10,20 5,10,45 Time1 is earlier than Time2
Time1 earlier than Time2, b/c hours 15,10,10 17,23,15 ____A.____
Time1 earlier than Time2, b/c minutes 5,0,20 5,10,5 ____B.____
Times the same 7,5,20 7,5,20 ____C.____
Time1 later than Time2, b/c seconds 9,35,45 9,35,25 ____D.____
Time1 later than Time2, b/c minutes 6,25,45 6,15,55 ____E.____

(20 points) Individual problem #2: Designing the program

• Write a design for this problem. To save yourself time, put them in a .py file and make each step a comment. It can be very high-level steps.
• Don't forget your personal info.
• State the three P's (purpose, pre-conditions and post-conditions).
• You do NOT have to NUMBER the steps!
• For a hint about writing if structures in design, see here

(30 points) Individual problem #3: Writing the program

• Input 6 integers. These 6 integers represent 2 times, the hours, minutes and seconds of Time1, and the same for Time2. You don't have to do any checking about valid times. Don't worry if someone types in 99, 99, 99. Just let the program do the usual things.
• First work on the comparing logic, don't worry about the look of the output.
• You should compare the hours first because if they are different, you can decide. Only if they are equal do you need to compare minutes and so on.
• Don't try to produce the output during the comparing logic, just produce a variable like "result" with values 1 (Time1 is earlier than Time2), 2 (Time1 is later than Time2) or 3 (The times are the same).
• After the comparison is done and you have a variable representing the result, then use a 3-way branch to print out the 3 possible results.
• AFTER you have the comparisons working, then focus on the time outputs.
• Note that the minutes and seconds always have two digits. In other words, they have a leading zero if the value was only one digit. This is NOT a fancy formatting trick. It is simple logic. The line is printed in pieces. Print up to the point where the 0 may have to be. Test to see if the zero is needed and print it if needed. Then print the next piece of the line up to where the second leading zero may be needed. Print it if needed. Then print the rest of the line.
• Sample run
```Enter Time1 hours: 12
Enter Time1 minutes: 33
Enter Time1 seconds: 15

Enter Time2 hours: 14
Enter Time2 minutes: 21
Enter Time2 seconds: 12

Time 1:   12:33:15
Time 2:   14:21:12

Time1 is earlier than Time2
```
• Sample run
```Enter Time1 hours: 1
Enter Time1 minutes: 1
Enter Time1 seconds: 1

Enter Time2 hours: 3
Enter Time2 minutes: 4
Enter Time2 seconds: 5

Time 1:   1:01:01
Time 2:   3:04:05

Time1 is earlier than Time2
```
• Sample run
```Enter Time1 hours: 10
Enter Time1 minutes: 15
Enter Time1 seconds: 9

Enter Time2 hours: 3
Enter Time2 minutes: 45
Enter Time2 seconds: 7

Time 1:   10:15:09
Time 2:   3:45:07

Time1 is later than Time2
```

Log off properly - you don't want your account misused by someone else!

Remember not to leave files on the local hard drives in this lab or anywhere else on campus! Make sure you save your projects on a portable storage device you take with you!