Identifying and Correcting Errors FRQ Practice

Responses receive AI feedback against a rubric after submission. Scores are practice estimates.

Question 1 of 5

A procedure is supposed to count how many lab temperatures exceed 100:

PROCEDURE CountHot(temps)
{
    count ← 0
    FOR EACH t IN temps
    {
        IF t ≥ 100
        {
            count ← count + 1
        }
    }
    RETURN count
}

A user complains values of exactly 100 are ignored, but the code above includes them.

(a) Explain how you would verify whether the deployed code matches this listing.

(b) Write two test cases (list → expected count) assuming ≥ 100 should count.

(c) If the deployed code used IF t > 100 instead, name the error type and the fix.

Question 2 of 5

Hand-trace this fragment with x starting at 4:

x ← 4
y ← 1
REPEAT UNTIL x = 0
{
    y ← y * x
    x ← x - 1
}
DISPLAY(y)

(a) Complete a trace table for each loop entry showing x and y.

(b) State the final displayed value.

(c) Identify what mathematical value this computes for general positive integer start x.

Question 3 of 5

Classify each situation as syntax, runtime, or logic error:

(a) Misspelled PROCEDURE name causes the environment to reject the program before run.

(b) Division by zero halts while running.

(c) Program finishes but swaps first and last names in badges.

Question 4 of 5

A robot should visit the charger square but ROTATE_RIGHT was used where ROTATE_LEFT was required, so it leaves the grid.

(a) Name the error type.

(b) Describe a testing strategy on a small grid that would catch it before the contest.

(c) Give one code-level guard that reduces harm.

Question 5 of 5

An 8-bit unsigned score register caps at 255. A bonus event does score ← score + 50 when score is 230.

(a) Explain the overflow risk.

(b) Propose two defenses (validation or representation).

(c) Write a test that would expose the bug if overflow wraps to a small number.