Strings FRQ Practice

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

Question 1 of 5

Let title ← "LOGIC". substring is inclusive and 1-based.

(a) Evaluate substring(title, 1, 2). (b) Evaluate substring(title, 3, 5). (c) Evaluate substring(title, 1, 2) + substring(title, 3, 5).

Question 2 of 5

A bug report says a student used substring(msg, 1, 4) on msg ← "TEST" expecting "TES".

(a) What does the call actually return under inclusive end indexes? (b) What end index should produce "TES"? (c) Name the category of error illustrated.

Question 3 of 5

substring(s, start, end) returns the characters from index start through index end, inclusive, with the first character at index 1. Trace:

a ← "KEY"
b ← "BOARD"
c ← substring(a, 1, 2) + substring(b, 1, 3)
DISPLAY (c)
DISPLAY (a + b)

(a) What is c? (b) What does the second DISPLAY show? (c) How do the two displayed strings differ?

Question 4 of 5

Build a tag from course ← "CSP" and year ← "26".

(a) Write an expression using + that produces "CSP26". (b) Using inclusive substring, extract "CS" from course. (c) Explain why substring(course, 1, 3) + year is not the same as substring(course, 1, 2) + year.

Question 5 of 5

The table shows attempted extractions from word ← "GRAPE".

Attempt Call Intended
1 substring(word, 1, 3) GRA
2 substring(word, 2, 4) RAP
3 substring(word, 3, 5) APE

(a) Which attempts succeed under inclusive 1-based substring? (b) Give one wrong end index that would turn Attempt 1 into "GR". (c) Why might a student who learned exclusive ends mis-evaluate Attempt 2 as "RA"?