Back to the topic

The mark scheme starts on a new page, so you can print pages one and two for a student and keep the last page yourself. Everything prints in black on white whichever theme you are using.

GCSE Computer Science · 2.3

Producing Robust Programs

Section A: 10 multiple choice questions, 10 marks. Section B: 5 written questions, 21 marks. Total 31 marks.

Name

Class

Date

Mark  / 31

Section A

Circle the letter of the correct answer. One mark each.

  1. 1Which validation check would ensure a password is at least 8 characters?1
    1. AA range check
    2. BA type check
    3. CA presence check
    4. DA length check
  2. 2A program runs but calculates the average incorrectly. This is:1
    1. AA syntax error
    2. BA runtime error
    3. CA logic error
    4. DA validation error
  3. 3For a field accepting values 1 to 10, which is boundary test data?1
    1. A100
    2. B"five"
    3. C5 and 6
    4. D0 and 1
  4. 4What is the difference between validation and verification?1
    1. AVerification checks data is sensible, validation checks it was entered correctly
    2. BValidation only applies to numbers
    3. CThey are the same thing
    4. DValidation checks data is sensible, verification checks it was entered correctly
  5. 5Which is an example of a syntax error in Python?1
    1. AUsing minus instead of plus in a calculation
    2. BMissing a colon at the end of an if statement
    3. CDividing by a variable that happens to be zero
    4. DStoring a phone number as an integer
  6. 6Why is boundary test data particularly valuable?1
    1. AIt tests exactly where off by one errors in conditions occur
    2. BIt always causes the program to crash
    3. CIt is the easiest data to think of
    4. DIt takes the least time to test
  7. 7Which of these improves the maintainability of a program?1
    1. AUsing meaningful variable names and consistent indentation
    2. BAvoiding subroutines so everything is in one place
    3. CUsing single letter variable names
    4. DWriting all the code on one line to save space
  8. 8What is iterative testing?1
    1. ATesting carried out by the end user
    2. BTesting only the loops in a program
    3. CTesting carried out during development as each part is written
    4. DTesting the finished program against its requirements
  9. 9A program asks for a year group and accepts 7, 8, 9, 10 or 11. Which validation check is most appropriate?1
    1. AA length check
    2. BA look up check against the permitted list
    3. CA presence check only
    4. DA format check for an at sign
  10. 10Passwords should be stored in a hashed form so that:1
    1. AIf the database is stolen the actual passwords are not revealed
    2. BThe database takes up less storage
    3. CUsers can recover forgotten passwords more easily
    4. DLogin is faster

Section B

Answer in the space provided. The number of marks tells you how many separate points to make.

  1. 1StateState two validation checks that could be applied to a field where a user enters their email address.2
  2. 2ExplainExplain the difference between a syntax error and a logic error, giving an example of each.4
  3. 3DesignA program accepts a temperature reading between -50 and 50 degrees. Design a test plan containing four tests, stating the test data, the type of data and the expected result for each.6
  4. 4ExplainExplain three ways in which a programmer can make their code more maintainable.6
  5. 5ExplainExplain why a program that asks for a user's age should include input validation.3

Mark scheme

Section A

1D2C3D4D5B6A7A8C9B10A

Section B

1 State two validation checks that could be applied to a field where a user enters their email address. 2

One mark for each of the following, to a maximum of 2.

  • A presence check to ensure something has been entered
  • A format check to ensure it contains an at sign and a domain

Model answer. A presence check could be used to ensure that the field has not been left blank. A format check could also be applied, confirming that the entry contains an at sign followed by a domain name with a full stop, since an email address without those parts cannot be valid.

2 Explain the difference between a syntax error and a logic error, giving an example of each. 4

One mark for each of the following, to a maximum of 4.

  • A syntax error breaks the rules of the programming language
  • The program will not run at all until it is corrected
  • A logic error means the program runs but produces an incorrect result
  • Gives valid examples of each, such as a missing colon and using the wrong operator

Model answer. A syntax error occurs when the code breaks the rules of the programming language, for example a missing colon at the end of an if statement or an unclosed bracket. Because the code is not valid, the program will not run at all until the error is corrected, and the development environment will usually point to the offending line. A logic error is different: the code is completely valid and the program runs without complaint, but the instructions do not do what the programmer intended, so the output is wrong. An example would be writing total = total - price instead of total = total + price when calculating a shopping basket, or using a greater than sign where greater than or equal to was needed. Logic errors are more dangerous because nothing alerts the programmer to them, and they can only be found through careful testing.

3 A program accepts a temperature reading between -50 and 50 degrees. Design a test plan containing four tests, stating the test data, the type of data and the expected result for each. 6

One mark for each of the following, to a maximum of 6.

  • Includes normal data within the range
  • Includes boundary data at the edge of the accepted range
  • Includes boundary data just outside the accepted range
  • Includes erroneous data of the wrong type
  • States the type of each piece of test data
  • States an expected result for every test

Model answer. Test 1 uses the value 20, which is normal data well within the accepted range, and the expected result is that the value is accepted and processed. Test 2 uses the value 50, which is boundary data at the very top of the accepted range, and the expected result is that it is accepted, since the range is inclusive. Test 3 uses the value 51, which is boundary data just outside the accepted range, and the expected result is that it is rejected with an error message asking the user to try again. Test 4 uses the entry "hot", which is erroneous data of the wrong type entirely, and the expected result is that the program rejects it with an error message rather than crashing. A fifth useful test would be -51, checking the lower boundary from the outside, since an error at one end of a range does not guarantee an error at the other.

4 Explain three ways in which a programmer can make their code more maintainable. 6

One mark for each of the following, to a maximum of 6.

  • Use meaningful variable and subroutine names
  • So that another programmer can understand the purpose without tracing the logic
  • Use comments to explain sections of code
  • Use consistent indentation to show the structure
  • Use subroutines so each task is separated and can be located easily
  • Use constants rather than unexplained numbers appearing throughout the code

Model answer. The first way is to use meaningful identifiers. Naming a variable totalPriceIncludingVat rather than t means another programmer can understand what the value holds immediately, without tracing back through the code to work it out, and the same applies to subroutine names that describe the task they perform. The second way is to use comments and consistent indentation. Comments should explain why something is being done, particularly where the reason is not obvious, rather than restating what the line clearly does, and consistent indentation makes the structure of loops and selection statements visible at a glance so the flow of the program can be followed quickly. The third way is to break the program into subroutines and use named constants. Separating each task into its own subroutine means a programmer looking for a particular piece of behaviour knows exactly where to find it and can change it without risk to the rest of the program, and replacing values such as 0.2 with a named constant like VAT_RATE means the value appears once, is self explanatory, and can be updated in a single place if the rate ever changes.

5 Explain why a program that asks for a user's age should include input validation. 3

One mark for each of the following, to a maximum of 3.

  • Users may enter data that is the wrong type or outside a sensible range
  • Without validation the program may crash or produce incorrect results
  • Validation checks the input is sensible before it is used, allowing the program to ask again

Model answer. Input validation is needed because users cannot be relied upon to enter data in the expected form. Someone might type letters instead of digits, enter a negative age, leave the field blank, or enter an impossibly large number, whether by accident or deliberately. Without validation the program would attempt to use that input directly, which could cause it to crash when it tries to convert text into a number, or to continue running and produce meaningless results such as calculating a negative average. Validation checks the input against sensible criteria, such as a type check that a whole number has been entered and a range check that it falls between 0 and 120, and rejects anything that fails with a clear error message so the user can try again. This makes the program robust, meaning it keeps working correctly regardless of what the user does.