You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
This lesson provides comprehensive exam practice for the Producing Robust Programs topic, covering the key content from OCR J277 Section 2.4 that appears on Paper 2: Computational Thinking, Algorithms and Programming. This lesson brings together defensive design, input validation, authentication, maintainability, error types, testing, test data, trace tables, and optimisation.
The Producing Robust Programs section typically accounts for 10–20 marks on Paper 2. Questions test your understanding of how to write reliable, well-tested, maintainable code.
| Question Type | Typical Marks | What You Need to Do |
|---|---|---|
| Define a term | 1–2 marks | Define validation, verification, syntax error, etc. |
| Identify validation checks | 2–3 marks | Name and explain appropriate checks for a scenario |
| Select test data | 3–4 marks | Choose normal, boundary, and erroneous data |
| Identify error type | 1–2 marks | State whether an error is syntax, logic, or runtime |
| Improve maintainability | 2–4 marks | Suggest specific improvements to given code |
| Debug with trace table | 4–6 marks | Find and fix a logic error |
| Write validation code | 3–5 marks | Write pseudocode for input validation |
Question: Define the following terms: (a) Syntax error (1 mark) (b) Logic error (1 mark) (c) Runtime error (1 mark)
Model Answer: (a) A syntax error is a mistake in the code that breaks the rules of the programming language, preventing the program from running. (b) A logic error is a mistake in the algorithm's logic that causes the program to produce incorrect output, but the program still runs without crashing. (c) A runtime error is an error that occurs while the program is running, causing it to crash (e.g. division by zero or accessing an invalid array index).
Question: A program asks the user to enter a UK phone number (must start with "0", must be exactly 11 digits, must contain only numbers). Identify two appropriate validation checks and explain how each would be applied.
Model Answer:
(Also acceptable: type check to ensure only numeric characters, presence check to ensure it is not empty.)
Question: A program accepts a percentage mark from 0 to 100. Provide four items of test data, one of each type (normal, boundary valid, boundary invalid, erroneous), stating the expected outcome for each.
Model Answer:
| Test Data | Type | Expected Outcome |
|---|---|---|
| 65 | Normal | Accepted — processed normally |
| 0 | Boundary (valid) | Accepted — lower boundary |
| 101 | Boundary (invalid) | Rejected — "Mark must be 0–100" |
| "abc" | Erroneous | Rejected — "Please enter a number" |
Question: Explain the difference between validation and verification. (2 marks)
Model Answer: Validation checks that data is reasonable, sensible and meets certain rules (e.g. an age must be between 0 and 150) — it checks if data could be correct, but not that it IS correct. Verification checks that data has been entered or transmitted accurately (e.g. asking the user to enter their email address twice and comparing the two entries to confirm no typing errors were made).
OCR Exam Tip: This is one of the most frequently asked questions in the OCR exam. Learn a clear one-sentence definition for each. Validation = checks data is reasonable. Verification = checks data is accurate.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.