Libraries FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

A library documents: distance(x1, y1, x2, y2) returns the Euclidean distance between points (x1, y1) and (x2, y2). (a) Write one correct call that finds the distance from (0, 0) to (3, 4). (b) Explain why reading the parameter order in the documentation matters before writing the call. (c) State one advantage of calling this library procedure instead of rewriting the distance formula.

Question 2 of 5

API table:

Name Parameters Returns
contains(text, piece) two strings true if piece appears inside text
indexOf(text, piece) two strings 1-based start index of piece in text, or 0 if absent

(a) Which call checks whether "cat" appears in "concatenate"? (b) If indexOf("concatenate", "cat") returns 4, explain what that number means using the table. (c) Why is the API table necessary for correct use?

Question 3 of 5

A sensor library documents: average(readings) returns the mean of a list of numbers. (a) Write a call that averages the list [2, 4, 6]. (b) Trace the expected return value. (c) Explain how using average manages complexity in a larger data-logging program.

Question 4 of 5

Library docs: roundTo(n, d) returns n rounded to d digits after the decimal point. (a) Give the call that rounds 3.14159 to 2 digits. (b) Explain why roundTo(3.14159) would not match the documentation. (c) Describe one risk of calling a library procedure without reading its parameter list.

Question 5 of 5

A student reimplements a sorting procedure that already exists in a trusted library. (a) Identify a better approach using the library. (b) Give one reason the library approach can be safer. (c) State what the student still must read before calling the library sort.