Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1fields <- split(line, ",") | Asql <- "INSERT INTO students VALUES (" + id + ", '" + name + "')" | |
| 2accepted <- accepted + 1 | Bmark <- toInteger(trim(fields[2])) | |
| 3Trim spaces off a field and convert it to a number before checking it | CBreaks one line of the file into a list of separate field values at each comma. | |
| 4Build the SQL text for a good row by joining the cleaned field values into an INSERT statement | DThe field is still text and was not trimmed or converted to a number, so the range check compares text with numbers and may fail. | |
| 5for each line in file fields <- split(line, ",") mark <- fields[2] if mark >= 0 AND mark <= 100 then | ECounts one more row that passed validation and had an INSERT statement built. | |
| 6if valid then accepted <- accepted + 1 else accepted <- accepted + 1 | FThe else branch adds to accepted instead of rejected, so rejected rows are counted as accepted and the rejected total never changes. |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
for each line in file — A loop that reads each line, splits it into fields, trims and validates them, then builds an INSERT statement for each good row and counts accepted and rejected rows.for each line in file
fields ← split(line, ",")name ← trim(fields[0])
age ← integer(fields[1])age ← integer(trim(fields[1]))sql ← "INSERT INTO students VALUES ('"
sql ← sql + name + "')"if valid then accepted ← accepted + 1
else rejected ← rejected + 1