APCSP Abstraction Concepts 2 — Questions and Answers
Question 1: Which of the following best describes a 'procedural abstraction'?
- Hiding the implementation details of a procedure behind a named call (Correct answer)
- Storing data in a variable for later use
- Using a loop to repeat a block of code
- Converting a program from one language to another
Correct answer: Hiding the implementation details of a procedure behind a named call
Procedural abstraction lets a programmer call a named procedure without knowing how it is implemented internally.
Question 2: A programmer creates a function called `calculateTax(income)` so that other parts of the program don't need to know the tax formula. This is an example of:
- Data abstraction
- Procedural abstraction (Correct answer)
- Binary representation
- Sequencing
Correct answer: Procedural abstraction
Hiding the formula inside a named function and calling it by name is procedural abstraction.
Question 3: Which statement about layers of abstraction in computing is TRUE?
- Each layer must expose all details to the layer above it
- Higher layers hide the complexity of lower layers (Correct answer)
- Abstraction layers increase the amount of code a programmer must write
- Only hardware can define abstraction layers
Correct answer: Higher layers hide the complexity of lower layers
Each higher layer of abstraction hides the complexity of the layer beneath it, simplifying what the programmer must handle.
Question 4: In the context of AP CSP, what is a 'model' as a form of abstraction?
- An exact copy of a real-world system
- A simplified representation that captures only relevant features (Correct answer)
- A machine-language translation of source code
- A graphical user interface
Correct answer: A simplified representation that captures only relevant features
A model is an abstraction that represents only the features relevant to the problem, ignoring unnecessary details.
Question 5: Which of the following is an example of data abstraction?
- Writing a loop that iterates 10 times
- Using a list to represent a collection of student scores without specifying how the list is stored in memory (Correct answer)
- Compiling source code into machine code
- Debugging a program with a step-through debugger
Correct answer: Using a list to represent a collection of student scores without specifying how the list is stored in memory
Using a list to represent scores without knowing the underlying memory layout is data abstraction.
Question 6: Why do programmers use abstraction when building large software systems?
- To make programs run faster by removing all function calls
- To manage complexity by hiding unnecessary details (Correct answer)
- To ensure programs can only run on one type of hardware
- To prevent other developers from reading the code
Correct answer: To manage complexity by hiding unnecessary details
Abstraction manages complexity by allowing programmers to focus on high-level design rather than low-level implementation details.
Question 7: A library provides a function `sortList(list)` that sorts any list. The programmer using the library does not know whether it uses bubble sort or merge sort. This illustrates:
- The programmer has no information about the function
- Abstraction — the implementation details are hidden behind an interface (Correct answer)
- A syntax error in the library
- Binary search being applied to a list
Correct answer: Abstraction — the implementation details are hidden behind an interface
The sorting algorithm is hidden behind the function name, which is the essence of abstraction.
Which of the following best describes a 'procedural abstraction'?