UMBC CS 201, Spring 00
UMBC CMSC 201 Spring '00 CSEE | 201 | 201 S'00 | lectures | news | help

CMSC 201
Programming Project One Solutions

General Comments

Solution 1 -- The brute force approach

Given the assumptions that 0 <= start time < end time <= 2359, there are 10 possible cases as listed below.

  1. start time in time-zone 1 and end time in time-zone 1
  2. start time in time-zone 1 and end time in time-zone 2
  3. start time in time-zone 1 and end time in time-zone 3
  4. start time in time-zone 1 and end time in time-zone 4
  5. start time in time-zone 2 and end time in time-zone 2
  6. start time in time-zone 2 and end time in time-zone 3
  7. start time in time-zone 2 and end time in time-zone 4
  8. start time in time-zone 3 and end time in time-zone 3
  9. start time in time-zone 3 and end time in time-zone 4
  10. start time in time-zone 4 and end time in time-zone 4
In solution 1, the program determines which of the 10 possible cases exist using a large if/else-if structure. It then calculates the minutes for each time-zone contained in the start time/end time range. Each of these cases is handled in one large if/else-if statment

Solution 2 -- A simpler (but less efficent) way

In solution 2, the program loops from start time to end time. It determines to which time-zone each minute of the loop belongs, and increments the number of minutes for that time-zone. In this loop, the loop index is the time that the minute begins, which determines the fee for that minute.

Solution 3 -- a more complex but efficient sulution

In solution 3,


CSEE | 201 | 201 S'00 | lectures | news | help

Thursday, 24-Feb-2000 14:58:07 EST