Procedures: AP CSP practice
Writing and calling procedures. 8 questions in the style of the AP CSP exam.
Sample questions
What is displayed? In AP pseudocode, DISPLAY shows a value followed by a space, so type every displayed value on one line, separated by single spaces.
PROCEDURE check(n)
{
IF (n MOD 3 = 0)
{
RETURN("fizz")
}
RETURN(n)
}
DISPLAY(check(9))
DISPLAY(check(10))
DISPLAY(check(12))A program calls a procedure findTotal in many places. The programmer later rewrites the inside of findTotal to make it faster, without changing its name, parameters or what it returns. Why does the rest of the program still work?
- Procedures cannot contain logic errors
- Because the program uses lossless compression
- Procedural abstraction means callers only depend on what the procedure does, not how it does it
- The program is automatically recompiled