In the function round of Display 3.6, which of these explains what happens in the body of the function? We reproduce the one line from the function body here:
return static_cast(floor(number+0.5));

a. This is overkill, it would be sufficient to use the floor function alone.
b. Adding 0.5 to number pushes the range up so floor can produce the correct rounding.
c. The static_cast is used because floor returns a double. If the double value were returned, there would be at least a warning of a double to int conversion in returning the value.
d. This is wrong. The argument for the floor function should be number-0.5.


b) and c) are correct.
Explanation: Numbers between floor(number)+0.5 and floor(number)+1 should round to floor(number)+1 . The expression number+0.5 pushes numbers in the range floor(number) and floor(number)+0.5 up so floor will produce the correct rounded number. It pushes numbers between floor(number) and floor(number)+0.5 to floor(number)+0.5 up but leaves them so that floor will produce the correct rounded value, namely floor(number).

Computer Science & Information Technology

You might also like to view...

Text ____ defines the appearance and shape of letters, numbers, punctuation marks, and symbols.

A. size B. style C. format D. font

Computer Science & Information Technology

6. The d’Arcy James cosmetic firm requires its salespeople to use notebooks to enter orders from retail department stores (their biggest customers). This information is then relayed to warehouses, and orders are shipped on a first come, first-served basis. Unfortunately, the stores are aware of this policy and are extremely competitive about which one of them will offer a new d’Arcy James product first. Many retailers have taken the low road and persuaded salespeople to falsify their order dates on sales forms by making them earlier than they actually were.

a. This problem is creating havoc at the warehouse. Disciplining any of the personnel involved is not feasible. How can the warehouse computer be used to certify when orders are actually placed? Explain in a paragraph. b. Salespeople are complaining that they have to ignore their true job of selling so that they can key in order data. List the data items relating to sales of cosmetics to retailers that should be stored in and retrieved from the central computer rather than keyed in for every order. c. Describe in a paragraph or two how bar coding might help solve the problem in Problem 6b

Computer Science & Information Technology

You use the Match case check box in the Find and Replace dialog box when you'd like the case of what you're searching for to be matched

Indicate whether the statement is true or false

Computer Science & Information Technology

The retrieve function follows the left-right structure of the tree until the desired node is found.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology