Due on Monday April 5 by end of lab
Educational goals of this lab - verify that every student can
(90 points) Team problem: Comparing Times
Problem Description:
Comparing clock times is a common task to do in a program about
payroll or scheduling. The times can be of different precision, this
problem assumes they are represented as hours, minutes, and seconds.
It is a 24 hour clock, so hours can run from 0 to 23. So you don't
have to worry about AM or PM. The times are assumed to be both in the
same day, so you don't have to worry about "the next day". You do NOT
have to validate these inputs; you can assume they are valid.
How are they compared? The possible results of a comparison is that
the two times are the same, that the first time is earlier (before)
the second time, or the first time is later (after) the second time.
The algorithm is:
first the largest units, the hours, are compared.
If the hours are different, the decision can be made at that time.
If the hours of the first time is less than the hours of the second time,
the first time comes before the second time.
Similiarly for greater than and comes after.
If the two hours are the same, then the minutes need to be compared to see
if they can determine the order of the times, as above.
If the minutes are the same, then the seconds need to be examined.
A time is only equal to another time if all three components are equal
to the corresponding components of the other time.
Sample run
Enter first hours or -1 to stop: 1 Enter first minutes: 2 Enter first seconds: 3 Enter second hours: 1 Enter second minutes: 2 Enter second seconds: 3 Time 1: 01:02:03 Time 2: 01:02:03 They are the same times Enter first hours or -1 to stop: 10 Enter first minutes: 15 Enter first seconds: 20 Enter second hours: 10 Enter second minutes: 25 Enter second seconds: 30 Time 1: 10:15:20 Time 2: 10:25:30 Time 1 is before Time 2 Enter first hours or -1 to stop: -1
(18 points) Test cases
Case # | Description | Inputs | Expected Outcome | |
---|---|---|---|---|
Time1: Hr, Min, Sec | Time2: Hr, Min, Sec | Return value: 0 (equal), 1(Time1 is earlier), 2 (Time1 is later) | ||
1. | Times are equal | 3,5,40 | 3, 5, 40 | 0 |
2. | Time1 earlier, because hours less | 12, 15, 20 | 13, 15,20 | ___A.___ |
3. | Time1 earlier, because minutes less | 5, 7, 30 | 5, 15, 30 | ___B.___ |
4. | Time1 earlier, because seconds less | 6, 18, 30 | 6, 18, 45 | ___C.___ |
5. | Time1 later, because hours greater | 14, 5, 20 | 13, 15,20 | ___D.___ |
6. | Time1 later, because minutes greater | 5, 37, 10 | 5, 15, 30 | ___E.___ |
7. | Time1 later, because seconds greater | 6, 18, 50 | 6, 18, 45 | ___F.___ |
Case # | Description | Parameters | Expected Outcome (output) |
---|---|---|---|
1. | All componets are 2 digits | 11, 13, 45 | 11:13:45 |
2. | Hours are 1 digit | 4, 44, 15 | 04:44:15 |
3. | Minutes are 1 digit | 14, 3, 22 | 14:03:22 |
4. | Seconds are 1 digit | 14, 13, 2 | 14:13:02 |
5. | All are 1 digit | 1,2,3 | 01:02:03 |
Case # | Description | Inputs | Expected Outcome | |
---|---|---|---|---|
1. | Times that are equal | 11,2,34 | 11,2,34 | Time 1: 11:02:34, Time 2: 11:02:34, Times are equal |
(15 points) Design:
There are three functions in this program, time_compare, time_print and main. For each function there is a prolog (three P's!). The prolog for the main is the same as it's always been. The prolog for the time_compare function describes its purpose, its parameters (pre-cond), and its result or return value (post-cond). The prolog for the time_print function does the same.
After the prolog for a function, give a design of the function, what control structure(s) needed, how the thing returned is decided.
(50 points) Implementation: