Fresh features from the #1 AI-enhanced learning platform.Try it free
Fresh features from the #1 AI-enhanced learning platformCrush your year with the magic of personalized studying.Try it free

Related questions with answers

Question

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

Verified
Answered 1 year ago
Answered 1 year ago
Step 1
1 of 3

The 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 startingTime\text{startingTime}. 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 &lt;< integralPart &lt;&lt; endl;

Here, the output will be the integral part of the variable val\text{val}, which is 1010.

To get the floating-point part of a value, the following statement can be used:

float val = 10.59;
float floatPart = val - static_cast&lt;int> (val);

This results in 10.5910=0.5910.59 - 10 = 0.59, which gives us the floating-point part of the variable val\text{val}.

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 by David A. Patterson, John L. Hennessy

Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionISBN: 9780124077263David A. Patterson, John L. Hennessy
226 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
866 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848 (5 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
849 solutions
Starting Out with C++: From Control Structures through Objects 6th Edition by Tony Gaddis

Starting Out with C++: From Control Structures through Objects

6th EditionISBN: 9780321545886 (1 more)Tony Gaddis
1,259 solutions

More related questions

1/4

1/7