Libraries (College Board AP® Computer Science Principles): Exam Questions

8 mins8 questions
1
1 point

Which of the following best describes an API (Application Programming Interface)?

  • A set of rules and specifications describing how a library's procedures can be used

  • A program that translates pseudocode into machine code

  • A physical device that stores a library of programs

  • A list of every line of source code inside a library

2
1 point

Consider the following code segment.

n ← RANDOM(1, 4)
DISPLAY(n * 2)

Which of the following is a value that could NOT be displayed?

  • 2

  • 6

  • 7

  • 8

3
1 point

A programmer includes an existing library of pre-written procedures in their program instead of writing those procedures from scratch.

Which of the following is a benefit of using the library?

  • The programmer can reuse tested code, which reduces development time and the chance of errors

  • The program is guaranteed to run faster than any code written by hand

  • The programmer no longer needs to test any part of their own program

  • The library removes the need to understand what any of its procedures do

4
1 point

A programmer wants to use a procedure from a mapping library. They read the library's API documentation but never look at the procedure's source code.

Why is the programmer still able to use the procedure correctly?

  • Source code cannot be viewed once a library has been imported into a program

  • The API describes the procedure's name, parameters, and return value, so the programmer knows how to use it without seeing its internal code

  • A library does not contain any source code, only documentation

  • The programmer must copy the source code into their own program before it will run

5
1 point

Consider the following code segment.

value ← RANDOM(3, 8)
DISPLAY(value)

How many different values could be displayed?

  • 5

  • 8

  • 6

  • 3

6
1 point

Consider the following code segment.

x ← RANDOM(2, 6)
DISPLAY(x * 3)

Which of the following describes all the values that could be displayed?

  • All integers from 6 to 18

  • All integers from 2 to 6

  • The multiples of 3 from 2 to 6

  • The multiples of 3 from 6 to 18

7
1 point

Consider the following code segment.

total ← RANDOM(1, 5) + 20
DISPLAY(total)

What is the largest value that could be displayed?

  • 25

  • 26

  • 24

  • 21

8
1 point

Consider the following code segment.

count ← 0
REPEAT 4 TIMES
{
  n ← RANDOM(1, 2)
  IF(n = 2)
  {
    count ← count + 1
  }
}
DISPLAY(count)

Which of the following is a value that could NOT be displayed?

  • 0

  • 5

  • 2

  • 4