AP CSP topic 3.14
Libraries
A software library is a collection of procedures that others have already written and tested, such as tools for math, graphics, or maps. Libraries save time because you do not rebuild common tasks. An API, or application program interface, is the documentation that explains what each procedure does, what inputs it needs, and what it returns.
Libraries vocabulary
- Library: A collection of prewritten procedures that can be used in new programs.
- API: Application program interface: the specification for how to use a library's procedures.
- Documentation: A description of how a procedure behaves and how to use it.
- Reuse: Using existing tested code instead of writing it again.
AP-style practice questions
Try each one, then open the answer. To save your progress, take this quiz in the interactive course.
1. Which of the following best describes an API?
- (A) A type of computer virus
- (B) Documentation that explains how to use the procedures in a library
- (C) A list of all programs on a computer
- (D) A kind of compression
Show answer
(B) Documentation that explains how to use the procedures in a library An API specifies how to use a library's procedures, their inputs and outputs.
2. A student uses a mapping library to show locations in their app instead of writing map code from scratch. Which of the following is the main benefit?
- (A) The app will have no errors
- (B) The student saves time by reusing tested code
- (C) The app will not need any data
- (D) The student owns the library
Show answer
(B) The student saves time by reusing tested code Libraries let programmers reuse existing, tested procedures.
From a library's documentation: round(x, places) returns x rounded to the given number of decimal places.
3. What does round(3.14159, 2) return?
- (A) 3
- (B) 3.1
- (C) 3.14
- (D) 3.142
Show answer
(C) 3.14 Rounded to 2 decimal places, 3.14159 becomes 3.14.
4. Which of the following is the most important thing to check before using a procedure from a library?
- (A) How many lines of code it has
- (B) What inputs it needs and what it returns, as described in its documentation
- (C) The name of the person who wrote it
- (D) Whether its code is written in color
Show answer
(B) What inputs it needs and what it returns, as described in its documentation The documentation tells you how to call the procedure correctly.