Related questions with answers
A long-distance carrier charges the following rates for telephone calls:
Starting time of call | Rate per minute |
---|---|
00:00-06:59 | 0.12 |
07:00-19:00 | 0.55 |
19.01-23.59 | 0.35 |
Write a program that asks for the starting time and the number of minutes of the call, and displays the charges. The program should ask for the time to be entered as a floating point number in the form HH.MM. For example, 07:00 hours will be entered as 07.00, and 16:28 hours will be entered as 16.28.
Input Validation: The program should not accept times that are greater than 23:59. Also, no number whose last two digits are greater than S 9 should be accepted. Hint: Assuming nunt is a floating-point variable, the following expression will give you its fractional part:
num - static_cast<int>(num)
Solution
VerifiedThe program prompts the user to enter the starting time of a call and the number of minutes. The program stores the starting time in the floating-point data type, that is float, variable . The program calculates and prints the charge.
The function static_cast<dataType> casts, meaning that converts the data from one type to another. Here, in the code below, static_cast<int> is used to get an integral part of the float value.
For instance,
float val = 10.59;
int integralPart = static_cast<int> (val);
cout << integralPart << endl;
Here, the output will be the integral part of the variable , which is .
To get the floating-point part of a value, the following statement can be used:
float val = 10.59;
float floatPart = val - static_cast<int> (val);
This results in , which gives us the floating-point part of the variable .
Create an account to view solutions
Create an account to view solutions
Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface
5th Edition•ISBN: 9780124077263David A. Patterson, John L. Hennessy
Fundamentals of Database Systems
7th Edition•ISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
Introduction to Algorithms
3rd Edition•ISBN: 9780262033848 (5 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
Starting Out with C++: From Control Structures through Objects
6th Edition•ISBN: 9780321545886 (1 more)Tony GaddisMore related questions
- physical science
1/4
- physical science
1/7