A C++17 program records three network delays in milliseconds. The required headers are included. Assume the requested capacity is valid and the reservation succeeds.
std::vector delays{1.8, 2.6, 3.9}; auto first = delays.begin(); auto oldCapacity = delays.capacity(); delays.reserve(oldCapacity + 1); double total = std::accumulate( delays.begin(), delays.end(), 0);
Which statements correctly describe the library operations and their consequences? Select all that apply.
The reserve call appends one stored delay because its argument exceeds the vector's previous storage capacity by one.
The stored value of total is approximately 8.3 because declaring a double result makes the running total floating point.
Replacing the initial value 0 with 0.0 gives the accumulation a floating-point running total before assignment to total.
Reading *first after the reserve call uses an invalidated iterator because the vector has reallocated its storage.
Unlock full course notes by signing up
Interpreting a parcel-mass report
A warehouse records parcel masses in kilograms. The following C++17 code runs with the required headers included and all operations succeeding.
Find total in kg to the nearest whole kilogram, mean in kg to two decimal places, matches as an exact integer count, and selected in kg to the nearest whole kilogram.
Checking an unsuccessful registry search
An instrument registry runs this C++17 search with the required headers included. No operation changes the vector during or after the search.
Complete the safety rule using an expression that calls end() directly on codes. Write the expression without spaces: reading *pos is permitted only when pos is not equal to ________.
Counting distinct sensor IDs in place
A vector named ids holds the integer sensor IDs logged during a test run, with many repeats in no particular order. You want to remove the duplicates in place using standard algorithms and then report how many distinct sensors reported. Arrange the steps in the order they must run.
Hidden insertions in a stock map
In a small warehouse program, stock is a std::map from std::string keys to int values, and it starts empty. The program then runs these statements in order:
After all statements have run, give each quantity as a whole number: the value of stock.size(), the value of stock.count("gasket"), the value stored for the key bolt, and the final value of total.