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 | |
|---|---|---|
| 1valid <- true | AThe else branch resets valid to true, which wipes out a failure from an earlier check. Set valid to true once at the start and only ever change it to false. | |
| 2if valid = true then INSERT record | BInsert the record only if every validation check left the valid flag true. | |
| 3A failed check sets the flag to false so the record will not be inserted | CThe record is inserted before the check runs, so a bad record is inserted anyway. The INSERT must come after the checks and sit inside if valid = true then. | |
| 4A record with a missing (null) field is rejected as invalid and reported instead of inserted | Dif name = null then valid <- false | |
| 5valid <- true INSERT record if age < 0 then valid <- false | EStart by assuming the record is valid. Each failing check will later change this flag to false. | |
| 6if age < 0 then valid <- false else valid <- true | Fif age < 0 then valid <- false |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
if valid = true then — Only insert the record if every validation check left the valid flag true. If any check set valid to false, skip the bad record or report it instead of inserting it.valid ← true
if age < 0 then valid ← falseif age < 0 or age > 120 then
valid ← falseif valid = true then
insert record into studentsif name = null then valid ← falseif valid = true then
insert record into students
else print "Record skipped"