Libraries MCQ Practice

Question 1 of 10

A math library documents: abs(n) returns the absolute value of n. Which call returns 9?

  1. A. abs("nine")
  2. B. abs()
  3. C. abs(-9)
  4. D. abs(-9, 9)

Question 2 of 10

API: swapCase(s) returns a new string with uppercase and lowercase letters swapped. Which call matches the documentation?

  1. A. swapCase("AbC", true)
  2. B. swapCase()
  3. C. swapCase = "AbC"
  4. D. swapCase("AbC")

Question 3 of 10

A list library documents: slice(list, start, end) returns a new list of elements from 1-based index start through end inclusive. For nums ← [10, 20, 30, 40], which call returns [20, 30]?

  1. A. slice(nums, 2, 3)
  2. B. slice(nums, 1, 2)
  3. C. slice(nums, 2)
  4. D. slice(2, 3)

Question 4 of 10

Which statement about software libraries is accurate?

  1. A. Using a library always requires rewriting its source before each call.
  2. B. A library is a collection of procedures that may be used when creating new programs.
  3. C. A library replaces the need for any procedure names.
  4. D. Library procedures never take parameters.

Question 5 of 10

Docs: min3(a, b, c) returns the smallest of three numbers. Which call returns 2?

  1. A. min3()
  2. B. min3(2)
  3. C. min3(5, 2, 9)
  4. D. min3(5, 9)

Question 6 of 10

A networking library documents: checksum(bytes) returns an integer check value for list bytes. A student wants a check value for [7, 3, 1]. Which call matches?

  1. A. checksum()
  2. B. checksum("7,3,1", true)
  3. C. checksum(7, 3, 1)
  4. D. checksum([7, 3, 1])

Question 7 of 10

The table documents two procedures from a color library.

Procedure Returns
rgb(r, g, b) a color value from red, green, blue components 0-255
gray(level) a gray color with equal RGB components equal to level

Which call creates a gray color with level 128?

  1. A. gray(128)
  2. B. gray(128, 128, 128)
  3. C. rgb()
  4. D. rgb(128)

Question 8 of 10

A program needs sine values. A math library provides sin(degrees). What should the programmer do first?

  1. A. Call sin with whatever arguments feel convenient without reading docs.
  2. B. Read the documentation for parameter units and return meaning, then call sin appropriately.
  3. C. Delete the library so that sine must be guessed.
  4. D. Rename sin to cosine inside the binary before calling.

Question 9 of 10

Docs: padLeft(s, width, ch) returns s padded on the left with character ch until the result has length width. Which call yields "00ab" if LENGTH("ab") is 2 and width is 4?

  1. A. padLeft("ab", 4)
  2. B. padLeft(4, "0", "ab")
  3. C. padLeft("ab", 4, "0")
  4. D. padLeft("ab", "0", 4)

Question 10 of 10

Using a library procedure mainly helps a programmer by:

  1. A. guaranteeing the program has no user interface
  2. B. removing all parameters from every call site
  3. C. eliminating the need for any testing of the overall program
  4. D. reusing a documented solution to a subproblem instead of rewriting it