– Program 3 – Fall 2011 – Long-Distance Calls CMPS 1043

advertisement
CMPS 1043 – Program 3 – Fall 2011 – Long-Distance Calls
Due: Wed., Oct. 5 – Thurs., Oct. 6
No problem solving steps turned in this time. I recommend you do them for your own benefit.
Problem Description
A long-distance carrier charges the following rates for telephone calls between the U.S. and Mexico:
Starting time of Call (minutes:seconds)
00:00 – 06:59 (midnight – 6:59 a.m.)
07:00 – 19:00 (7 a.m. – 7 p.m.)
19:01 – 23:59 (after 7 p.m. – before midnight)
Rate Per Minute
$ 0.12
0.55
0.35
Given the starting time of a call and the length of the call in minutes, the cost for the call is to be
calculated. The time will be input as a decimal number. That is, 5:45 will be input as 5.45. You
MUST split this into the numeric “hour” component and the “minute” component and validate the
correct format of each one. When printing, you must print the time as 5:45, with the colon not the
period.
Use if statements, properly nested, to solve the problem. All I/O is to be file based.
Data File ( Name, StartTime, Length (in minutes))
Mary
5.45
10
Joe
16.41
40
Ted
23.10
38
Joshua
45.9
2
Fred
12.42
50
Caroline
23.00
121
Jeffrey
20.00
82
Joy
24.00
13
Paul
06.59
8
Tony
7.00
29
Henry
19.01
59
Catherine
23.08
134
Titus
10.60
65
Julio
5.37
100
Rebekah
12.03
81
Input Validation: You must check the StartTime after reading it in. That is, if the “hours” potion is
greater than 23 or if the minutes portion is greater than 59, then you should print the person’s name
followed by the work “ERROR.” Otherwise, you will print the total cost.
Output Form: Make sure that your output looks as below.
Long Distance Telephone Bills
Name
Start Time Length
Charge
-----------------------------------------------------------------David
12:42
10
$5.50
Max
25:50
12
ERROR
Cindy
12:89
100
ERROR
-------------------------------------------------------------------
Download