Producing Robust Programs - Worksheets, Questions and Revision
15 original exam-style questions - 9 pages of questions with a full mark scheme - free printable PDF.
Producing Robust Programs revision guideMore GCSE Computer Science practiceMock exams
This topic is chapter 1 of GCSE Computer Science Topic Workbook 2 and chapter 11 of GCSE Computer Science 10-Minute Tests.
2.3 Producing Robust Programs
- A) Presence check
- B) Format check
- C) Range check
- D) Length check
- A) Presence check
- B) Format check
- C) Range check
- D) Check digit
- A) Length check
- B) Format check
- C) Range check
- D) Presence check
total <- 0 count <- 0 FOR i <- 1 TO 5 total <- total + n[i] count <- count + 1 NEXT i a <- total / count OUTPUT a
total = 0
count = 0
array numbers[5]
numbers[0] = 12
numbers[1] = 7
numbers[2] = 25
numbers[3] = 3
numbers[4] = 18
for i = 0 to 4
if numbers[i] > 10 then
total = total + numbers[i]
count = count + 1
endif
next i
print(total) print(count)
Question 1
- (a) B) Format checkB1
- (a) Answer: B) Format check
- (b) A) Presence checkB1
- (b) Answer: A) Presence check
- (c) C) Range checkB1
- (c) Answer: C) Range check
Question 2
- (a) Consistent/correct indentation of the FOR loop bodyB1
- (a) Using meaningful/descriptive identifier names instead of a, n and iB1
- (a) Answer: Indenting the lines inside the FOR loop; using meaningful identifier names instead of a, n and i.
- (b) Any meaningful name replacing a, e.g. average <- total / countB1
- (b) Answer: average <- total / count
- (c) Any suitable meaningful name, e.g. numbers, scores or marksB1
- (c) Answer: e.g. numbers
Question 3
- (a) i=0: numbers[0]=12, condition true, total=12, count=1B1
- (a) i=1: numbers[1]=7, condition false, total and count unchanged (12, 1)B1
- (a) i=2 and i=3: numbers[2]=25 true (total=37, count=2); numbers[3]=3 false (unchanged)B1
- (a) i=4: numbers[4]=18, condition true, final total=55, count=3B1
- (a) Answer: i=0: 12, true, total=12, count=1 | i=1: 7, false, total=12, count=1 | i=2: 25, true, total=37, count=2 | i=3: 3, false, total=37, count=2 | i=4: 18, true, total=55, count=3
- (b) total = 55 caoB1
- (b) count = 3 caoB1
- (b) Answer: total = 55, count = 3
Question 4
- (a) Correct method shown using place values 128, 64, 32, 16, 8, 4, 2, 1M1
- (a) 10101101 caoA1
- (a) Answer: 10101101
- (b) Correct method shown, e.g. adding place values for each set bitM1
- (b) 214 caoA1
- (b) Answer: 214
Question 5
- (a) First valid tool, e.g. breakpointsB1
- (a) Second valid tool, e.g. single stepping (step through/step into/step over) / variable (watch) window / cross-reference toolB1
- (a) Answer: Any two of: breakpoints; single stepping (stepping through code line by line); a variable/watch window; a cross-reference tool.
- (b) A breakpoint pauses execution of the program at a chosen lineM1
- (b) Single stepping then executes the remaining code one line/instruction at a time while the programmer watches variable valuesM1
- (b) This lets the programmer identify exactly which line causes a variable to take an unexpected/incorrect value, pinpointing the cause of the logic errorA1
- (b) Answer: A breakpoint pauses the program at a chosen line, then single stepping runs the remaining code one instruction at a time so the programmer can watch how each variable's value changes and identify exactly which line causes a value to become incorrect, pinpointing the logic error.
Question 6
- (a) Correct products shown: 3x7=21, 4x6=24, 5x5=25, 2x4=8, 1x3=3, 6x2=12M1
- (a) Correct total sum = 93M1
- (a) Check digit = 5 caoA1
- (a) Answer: 5
- (b) Check digit (check-digit validation)B1
- (b) Any one valid real-world example, e.g. barcodes, ISBNs, bank account numbersB1
- (b) Answer: Check digit; used, for example, in barcodes, ISBNs or bank account numbers.
Question 7
- Uses a loop that repeats the input process, e.g. do...until or while...endwhile1
- An input() statement used inside the loop to accept the number from the user1
- A condition correctly tests whether the number is outside the range 1 to 10, e.g. number < 1 OR number > 101
- The loop correctly continues while/until the number is invalid, and stops once a valid number (1 to 10) is entered1
- A print() statement used after the loop to display the valid number1
- Answer:do
number = int(input("Enter a whole number from 1 to 10"))
if number < 1 OR number > 10 thenprint("Invalid, please try again") endifuntil number ≥ 1 AND number ≤ 10print(number)
Question 8
- Use IDE debugging tools (e.g. breakpoints, single stepping) or trace the code to locate the line(s) where the actual result diverges from the expected resultM1
- Identify and correct the fault/logic error in the codeM1
- Re-run the failed test (and ideally the whole test plan) to confirm the fix works and no new faults have been introducedA1
- Answer: Use IDE debugging tools such as breakpoints and single stepping (or trace the code by hand) to find exactly where the program's behaviour diverges from what was expected; correct the fault in the code; then re-run the failed test, and ideally the whole test plan again, to confirm the program now produces the expected result and that no new errors have been introduced.
Question 9
- (a) Syntax errorB1
- (a) Answer: Syntax error
- (b) Logic errorB1
- (b) Answer: Logic error
- (c) A syntax checker only checks that the code follows the grammar/rules of the programming languageM1
- (c) It cannot check whether the logic/algorithm produces the correct or intended resultA1
- (c) Answer: A syntax checker only checks that the code follows the grammar/rules of the programming language; it cannot tell whether the logic of the algorithm actually produces the correct/intended output.
Question 10
- (a) Normal (test) dataB1
- (a) Answer: Normal test data
- (b) 0B1
- (b) 100B1
- (b) Answer: 0 and 100
- (c) Any value outside 0-100 (e.g. 105 or -3) or of the wrong data type (e.g. 'ninety')B1
- (c) Answer: e.g. 105 (a whole number outside the valid range) or 'ninety' (text instead of a number)
- (d) To check the validation routine correctly rejects/detects invalid data and the program does not crash or accept it (oe)B1
- (d) Answer: To check that the validation routine correctly rejects invalid data and the program does not crash or accept it by mistake.
Question 11
- (a) Length checkB1
- (a) Answer: Length check
- (b) Format checkB1
- (b) Answer: Format check
- (c) Presence checkB1
- (c) Answer: Presence check
- (d) The format check only tests that the data follows the correct pattern/structureM1
- (d) It cannot check that the data is true/accurate/belongs to the correct personA1
- (d) Answer: The format check only tests that the data matches the correct pattern; it cannot check whether the data is genuine or belongs to the correct person, so a valid-looking but stolen number would pass.
Question 12
- (a) Iterative testing is carried out throughout development, testing each module/section as it is writtenB1
- (a) Final (terminal) testing is carried out once the whole program has been completed, testing it as a wholeB1
- (a) Answer: Iterative testing tests each module/section of code as it is written during development; final (terminal) testing tests the whole completed program at the end.
- (b) Errors are found and can be fixed earlier/closer to when they were introduced, making them easier/cheaper to locate and correct (oe)B1
- (b) Answer: Faults are found soon after they are introduced, so there is less code to search through and they are cheaper and easier to fix.
Question 13
- (a) Any value from 17 to 64, e.g. 30B1
- (a) Expected outcome: accepted/valid, no error messageB1
- (a) Answer: 30 -> accepted
- (b) 16 or 65B1
- (b) Expected outcome: accepted/valid, since the range is inclusiveB1
- (b) Answer: 16 (or 65) -> accepted
- (c) Any value outside 16-65 (e.g. 15 or 70) or of the wrong data type (e.g. 'twenty')B1
- (c) Expected outcome: rejected, error/re-prompt message displayedB1
- (c) Answer: 70 -> rejected, error message shown and re-input requested
Question 14
- Uses a loop that continues until the sentinel value -1 is entered1
- An input() statement used inside the loop to accept each score1
- Correctly tests whether the score is within the valid range (0 to 100) before adding it to the total1
- Maintains a running total of valid scores and a count of how many valid scores have been entered1
- Invalid scores (outside 0-100 and not equal to -1) are correctly excluded from the total/count1
- After the loop ends, calculates and outputs the average (total / count) using the correct values1
- Answer:total = 0
count = 0
score = int(input("Enter a score (-1 to finish)"))
while score ≠ -1
if score ≥ 0 AND score ≤ 100 then
total = total + score
count = count + 1
endif
score = int(input("Enter a score (-1 to finish)"))
endwhileaverage = total / count print(average)
Question 15
- Level 1 Basic. Makes one or two isolated points about testing with little comparison or justification.1-2
- Level 2 Good. Describes relevant features, benefits and/or drawbacks of iterative and final testing with some comparison and justification, though the argument may be one-sided or not fully developed.3-4
- Level 3 Excellent. Gives a well-balanced, justified evaluation comparing iterative and final testing, weighing benefits (e.g. earlier/cheaper error detection, easier to isolate faults) against drawbacks (e.g. time overhead, integration errors only found later), and reaches a supported conclusion.5-6
- Indicative content:
- Iterative testing tests each module/section of code as it is written, so faults are found and can be corrected close to when they were introduced, while the relevant code is still fresh in the programmer's mind.
- This generally makes faults quicker and cheaper to isolate, because there is less new code to search through compared with testing the whole finished program at once.
- However, iterative testing takes extra time throughout development and cannot detect faults that only appear when different modules are integrated/combined.
- Final/terminal testing checks the complete, integrated program, so it can reveal problems that only occur when modules interact (e.g. data passed incorrectly between modules) that testing individual modules would miss.
- Relying only on final testing means faults could have been introduced much earlier in development, making them harder, slower and more expensive to trace back and fix, and may delay the whole project if major faults are found late.
- A balanced conclusion: most professional development uses both, iterative testing to catch faults early within modules, and final testing to confirm the complete, integrated program meets requirements and works as a whole.
Mark your answers
Check answers without an account. Some answers can be checked automatically; use the mark scheme to mark the rest.