Skip to the worksheet
Revision Library
Choose a subject

Producing Robust Programs - Worksheets, Questions and Revision

15 original exam-style questions - 9 pages of questions with a full mark scheme - free printable PDF.

Grades 1-9

This topic is chapter 1 of GCSE Computer Science Topic Workbook 2 and chapter 11 of GCSE Computer Science 10-Minute Tests.

Revision Library
revisionlibrary.co.uk
GCSE · Computer Science

2.3 Producing Robust Programs

OCR J277 · Calculators not allowed · about 80 minutes
Total Marks
Name: _______________________________    Date: ____ / ____ / ______
Answer ALL questions. Show all your working.
1
A programmer is choosing the most suitable input validation check for different fields on an online form.
(a)Which check is most suitable to make sure a UK postcode is entered in the correct pattern, e.g. SW1A 1AA?(1)
  • A) Presence check
  • B) Format check
  • C) Range check
  • D) Length check
(b)Which check ensures that a customer's date of birth field is not left empty?(1)
  • A) Presence check
  • B) Format check
  • C) Range check
  • D) Check digit
(c)A 'number of tickets' field must only accept whole numbers from 1 to 8. Which check identifies that 12 has been entered?(1)
  • A) Length check
  • B) Format check
  • C) Range check
  • D) Presence check
(Total for Question 1 is 3 marks)
2
Study the following pseudocode, which calculates the mean of five numbers stored in an array:
total <- 0
count <- 0
FOR i <- 1 TO 5
total <- total + n[i]
count <- count + 1
NEXT i
a <- total / count
OUTPUT a
(a)State two maintainability techniques, other than adding comments, that could be used to improve the readability of this code without changing what it does.(2)
(b)Rewrite the line 'a <- total / count' using a more meaningful identifier name for a.(1)
(c)The array n stores a list of numbers. Suggest one more suitable identifier name for this array.(1)
(Total for Question 2 is 4 marks)
3
Study the following algorithm, written in OCR Exam Reference Language:

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)
(a)Complete a trace table for this algorithm, showing the value of i, numbers[i], total and count for each pass of the loop.(4)
(b)State the two values output by the program.(2)
(Total for Question 3 is 6 marks)
4
Binary and denary conversions (no calculator).
(a)Convert the denary number 173 to an 8-bit binary number. Show your working.(2)
(b)Convert the 8-bit binary number 11010110 to denary.(2)
(Total for Question 4 is 4 marks)
5
A programmer is using an IDE to try to find the cause of a bug in their program.
(a)Identify two tools, other than a syntax checker, provided by an IDE that can help a programmer to find the cause of an error in their code.(2)
(b)Explain how using breakpoints together with single stepping can help a programmer to find the cause of a logic error.(3)
(Total for Question 5 is 5 marks)
6
A warehouse uses a 7-digit product code. The final digit is a check digit calculated as follows: each of the first 6 digits is multiplied by a weight (7, 6, 5, 4, 3, 2, reading left to right), the six results are added together, and the check digit is the remainder when this sum is divided by 11 (if the remainder is 10, the check digit is 0). The first 6 digits of a new product code are 3 4 5 2 1 6.
(a)Calculate the check digit for this product code. Show your working.(3)
(b)State the name of this type of validation check and give one real-world example of where a check digit is used.(2)
(Total for Question 6 is 5 marks)
7
Write an algorithm, using pseudocode (OCR Exam Reference Language), that repeatedly asks the user to input a whole number from 1 to 10 inclusive. The algorithm must reject and re-ask for any number outside this range, and once a valid number has been entered, it should output that number. Any correct logic will be accepted; do not worry about minor syntax errors.
(Total for Question 7 is 5 marks)
8
A programmer runs their test plan. One of the tests has failed: the expected result and the actual result produced by the program do not match. Describe the steps the programmer should take, after this failed test, to resolve the problem.
(Total for Question 8 is 3 marks)
9
Amara is writing a program in an IDE.
(a)Amara's program will not run. The IDE highlights a missing ENDIF and displays an error message before the program starts. State the type of error this is.(1)
(b)Amara fixes this, and the program now runs, but it displays the wrong total every time. State the type of error this is now most likely to be.(1)
(c)Explain why the IDE's syntax checker did not detect the error described in part (b).(2)
(Total for Question 9 is 4 marks)
10
A program accepts a whole number representing a student's exam mark. Valid marks are whole numbers from 0 to 100 inclusive.
(a)State the term used for realistic test data that would be expected during normal use of the program.(1)
(b)Give two boundary data values that should be used to test this input.(2)
(c)Give one example of erroneous test data for this input.(1)
(d)State why it is important to test a program using erroneous data as well as normal data.(1)
(Total for Question 10 is 5 marks)
11
A registration form has three input fields: Email address, Password (must be 8 to 16 characters), and National Insurance number (format: 2 letters, 6 digits, 1 letter, e.g. QQ123456C).
(a)State which validation check would be used to make sure the password is not shorter than 8 characters.(1)
(b)State which validation check would be used to make sure the National Insurance number matches the required pattern.(1)
(c)A user submits the form with the email address field left empty. State which validation check would detect this.(1)
(d)A user enters someone else's real National Insurance number, which matches the correct format exactly. Explain why the format check would not detect this as a problem.(2)
(Total for Question 11 is 5 marks)
12
Programmers can test their code at different stages of development.
(a)State the difference between iterative testing and final/terminal testing.(2)
(b)State one advantage of using iterative testing rather than relying only on final testing.(1)
(Total for Question 12 is 3 marks)
13
A program validates a user's age before allowing them to register for a website. A valid age must be a whole number from 16 to 65 inclusive. Complete a test plan for this validation check by giving one suitable piece of test data for each of the types below, and stating the expected outcome for each.
(a)Normal data: give a value and state the expected outcome.(2)
(b)Boundary data: give a value and state the expected outcome.(2)
(c)Erroneous data: give a value and state the expected outcome.(2)
(Total for Question 13 is 6 marks)
14
Write an algorithm, using pseudocode (OCR Exam Reference Language), that repeatedly inputs whole-number exam scores from the user. Only scores from 0 to 100 inclusive should be included in a running total. The user enters -1 to indicate they have finished entering scores. Once the user has finished, the algorithm should output the average of the valid scores that were entered (assume at least one valid score is entered). Any correct logic will be accepted; do not worry about minor syntax errors.
(Total for Question 14 is 6 marks)
15
A software company is developing a large program. Evaluate the effectiveness of using iterative testing throughout development, compared with relying only on final/terminal testing once the whole program is complete.
(Total for Question 15 is 6 marks)
Mark scheme · 2.3 Producing Robust Programs

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 then
        print("Invalid, please try again")
      endif
    until number ≥ 1 AND number ≤ 10
    print(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)"))
    endwhile
    average = 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.

Question 1(a)

1 mark
Choose an answer

Question 1(b)

1 mark
Choose an answer

Question 1(c)

1 mark
Choose an answer

Question 2

4 marks
Did your answer earn the marks?

Question 3

6 marks
Did your answer earn the marks?

Question 4

4 marks
Did your answer earn the marks?

Question 5

5 marks
Did your answer earn the marks?

Question 6

5 marks
Did your answer earn the marks?

Question 7

5 marks
Did your answer earn the marks?

Question 8

3 marks
Did your answer earn the marks?

Question 9

4 marks
Did your answer earn the marks?

Question 10

5 marks
Did your answer earn the marks?

Question 11

5 marks
Did your answer earn the marks?

Question 12

3 marks
Did your answer earn the marks?

Question 13

6 marks
Did your answer earn the marks?

Question 14

6 marks
Did your answer earn the marks?

Question 15

6 marks
Did your answer earn the marks?
Mark my answers

Keep going

Worksheets are written for Revision Library and come with a full mark scheme; a few English packs quote an out-of-copyright text, and name it on the page. Exam board names and specification codes say which qualification a pack suits: we are not affiliated with, endorsed by or approved by any exam board, and no past-paper question is reproduced here. Rights queries: hello@revisionlibrary.co.uk