Paper 2 Section B practice: design, write, test and refine

GCSE Computer Science (OCR) · OCR J277 · Algorithms and programming (Paper 2)

75 exam-style questions on this topic, at up to four difficulty levels, with full mark schemes. Notes and past-paper booklets are open to everyone. Practice needs a free account.

Or take a quick quiz: 11 questions on this subtopic in GCSE Computer Science (OCR), marked as you tap.

Revision notes

Section B of Paper 2 is worth 30 marks. Its questions follow one scenario and ask you to design, write, test and refine programs. Where a question says so, you must write your code in OCR Exam Reference Language or a high-level programming language you have studied: flowcharts, pseudocode and written English gain no marks there.

Key facts

  • Section B = 30 marks: one scenario to design, write, test and refine
  • Code must be ERL or a high-level language when the question says so
  • Underline every requirement: about one mark each
  • Initialise totals and counters (total = 0) before the loop
  • Cast numeric input: int(input("…"))
  • Validation: do … until the input is valid
  • Fixed number of repeats: for i = 1 to n … next i
  • Output results after the loop unless asked otherwise
  • Test data: normal, boundary, invalid, erroneous, each with an expected result

Notes

What Section B asks

  • One scenario, such as a club, a shop or a game, runs through several linked parts.
  • Typical parts: inputs, processes and outputs, or a validation check; completing or correcting code; writing a program; testing it; refining it to add a feature or fix a problem.
  • The longer program-writing parts carry the most marks, with roughly one mark for each requirement met.
  • Look for the sentence 'You must use either OCR Exam Reference Language or a high-level programming language that you have studied'. If it is there, only code gains marks.

Planning a program answer

diagram
  • Underline every requirement in the question. Each one usually earns a mark.
  • Decide the inputs, outputs and constructs needed: a loop? which type? selection? an array or a file?
  • StartInput ticketstickets from1 to 10?NoYestotal = 0anotherticket?YesInput kind (A/C)add 8 if A, 5 if Cto totalNoOutput totalStop
    A quick plan of the cinema program in the question below, before writing the code
  • Set totals and counters to 0 before loops. Cast numeric inputs with int() or real() (float() in Python).
  • Use the variable, array and file names the question gives.
  • Indent your code, then tick off each requirement to check nothing is missing.

Techniques that come up again and again

  • A validation loop: do … until the input is valid.
  • A running total, count, largest or smallest value.
  • Searching an array for a value, or looping through every element.
  • Reading every line of a file, or writing lines to a file.
  • A function with parameters that returns a value.
  • String handling: length, substring, upper and concatenation.

Testing and refining

  • Test plans need normal, boundary, invalid and erroneous data, each with the expected result.
  • To refine code, state exactly which lines change and where new lines go, or rewrite the whole section.
  • Trace your program with one test value before moving on.

How to answer each type of question

Write a program for the scenario

6 to 8 marksGrade 7
  1. List the requirements from the bullet points.
  2. Plan the order: validated input, loop, processing, output.
  3. Write the code in ERL or a high-level language, indented, using the names given.
  4. Tick off each requirement and trace with one simple test.

Example. A cinema charges £8 for an adult ticket and £5 for a child ticket. Write a program that:
• asks how many tickets are wanted, and keeps asking until a number from 1 to 10 is entered
• for each ticket, asks whether it is for an adult or a child (A or C)
• outputs the total cost.
You must use either OCR Exam Reference Language or a high-level programming language that you have studied. [6]

Show the model answerHide the model answer
do
   tickets = int(input("How many tickets (1-10)?"))
until tickets >= 1 AND tickets <= 10
total = 0
for i = 1 to tickets
   kind = input("Adult or child (A/C)?")
   if kind == "A" then
      total = total + 8
   elseif kind == "C" then
      total = total + 5
   endif
next i
print("Total cost: £" + str(total))
Inputs the number of tickets as an integer (1); repeats the input until it is from 1 to 10 (1); a loop that runs once for each ticket (1); inputs the ticket type inside the loop (1); adds 8 for A and 5 for C to a total set to 0 before the loop (1); outputs the total after the loop (1).

Complete a test plan for the program

3 to 4 marksGrade 5
  1. Use the rule from the scenario (here, 1 to 10 tickets).
  2. Choose one value for each type of test asked for.
  3. Give the expected result: accepted, or rejected and asked again.

Example. Complete a test plan for the input of the number of tickets in the cinema program, with one normal, one boundary, one invalid and one erroneous test. [4]

Show the model answerHide the model answer
Type of testTest dataExpected result
Normal4Accepted (1)
Boundary10 (or 1)Accepted (1)
Invalid11 (or 0)Rejected and asked again (1)
Erroneous"six"Rejected and asked again (1)
(The program above would need a type check added to pass the erroneous test, because int() cannot convert "six".)

Identify and fix an error in given code

2 to 3 marksGrade 6
  1. Trace the code with a small value to see what really happens.
  2. Find the line that causes the difference.
  3. Write the corrected line in full.

Example. A student wrote this line for the ticket loop: for i = 0 to tickets
Explain the problem and write a corrected line. [2]

Show the model answerHide the model answer
The loop runs tickets + 1 times, so the program asks about one ticket too many (1). Corrected: for i = 1 to tickets (or for i = 0 to tickets - 1) (1).

Refine the program

3 marksGrade 9
  1. Decide what new code is needed and exactly where it must go.
  2. Write the new lines in full.
  3. Check the change does not stop the rest of the program working.

Example. The cinema now takes £2 off the total cost when 5 or more tickets are bought. Write the extra code needed and state where it goes in the program. [3]

Show the model answerHide the model answer
if tickets >= 5 then
   total = total - 2
endif
Condition tickets >= 5 (1); subtracts 2 from the total (1); placed after the loop and before the total is output (1).

Don’t lose marks

  • Answering a code question in pseudocode, a flowchart or English when ERL or a high-level language is required.
  • Forgetting to cast input to an integer, so comparisons and arithmetic go wrong.
  • Validating with an if statement only, so an invalid value is never asked for again.
  • Setting the total to 0 inside the loop, so it resets every time.
  • Putting the output inside the loop, or missing a requirement from the list.

More tips

Memory tricks

  • Before writing, make a mini-plan: Inputs, Loop, Decide, Output (ILDO).
  • Each bullet point in the question is a checklist item: tick it off in your code.
  • Trace with the smallest valid input (such as 1 ticket) to catch loop errors.

Exam technique

  • Read the whole scenario first: later parts often reuse the variables and code from earlier ones.
  • Small syntax slips are not usually penalised if the logic is clear, so focus on getting the logic right.
  • Spend your time in proportion to the marks; if stuck, write the parts you can (inputs, loop, output) to pick up marks.

What each grade needs

What you need to be able to do, from the first marks up to the top grade.

  1. Grade 4
    Identify inputs, processes and outputs for a scenarioPick out the data in, what is done with it and what comes out.
  2. Grade 5
    Complete a test plan for a scenarioChoose normal, boundary, invalid and erroneous data with expected results.
  3. Grade 5
    Complete or correct lines of given codeFill gaps or fix errors so the code does what the scenario needs.
  4. Grade 6
    Write a program with input, selection and iterationCombine loops, if statements and variables to meet every requirement.
  5. Grade 7
    Validate input inside a loopKeep asking until the input meets the rule, before using it.
  6. Grade 8
    Use arrays, files or sub programs in solutionsStore and process data with the right structure, such as an array of names.
  7. Grade 9
    Refine a program to meet new requirementsChange working code accurately, without breaking what it already does.

Quick recall

Cover the answers and test yourself. The app has these as flashcards that come back just before you'd forget them.

Complete the sentences using words from the box. Each word may be used once.
syntax   logic   normal   boundary

A ______________ error breaks the rules of the programming language, so the program cannot be run.
A ______________ error does not stop the program from running, but it makes the program give an incorrect result.
syntax; logic
An online form will not let a user continue until something has been typed into the ‘Surname’ box. Name the validation check that does this.
Presence check
State one purpose of testing a program.
To find errors and make sure the program works as intended.
State what is meant by decomposition.
Breaking a problem down into smaller parts.

Sample questions

Written for this site in the style of OCR exam questions. They are not taken from real past papers.

Question 1Easy1 mark
A program accepts a quiz score that must be a whole number from 0 to 20 inclusive. Which one of these is boundary test data for the program? Tick (✓) one box.
[1]
  • 20
  • 10
  • −5
  • ten
Show the answer and mark scheme
Answer: 20
Question 2Medium2 marks
A game asks the player to give a rating from 1 to 5 stars. A tester only tries the ratings 2, 3 and 4. Explain why this testing is not enough.
[2]
Show the answer and mark scheme
Answer: Boundary and invalid data have not been tested, so errors at the edges of the range or in the validation could be missed.
  • boundary data (1 and 5) has not been tested, so errors at the edges of the range would be missed (for example > used instead of >=)
  • invalid data (for example 0, 6 or text) has not been tested, so it is not known whether it is rejected
  • only normal data has been tested
Question 3Hard6 marks
A company is developing a booking program for a cinema. A customer chooses a film, enters the number of tickets they want (from 1 to 8) and pays. Staff use a separate part of the program to change film times and ticket prices.
Discuss how the developers can make sure the program is robust and works correctly before it is released.
[6]
Show the answer and mark scheme
Answer: A good answer discusses anticipating misuse, validation, authentication, a test plan with normal, boundary and invalid data, and iterative and final testing, and links each to the cinema program.
  • anticipate misuse: customers may enter letters, negative numbers or leave the box empty
  • input validation: range check (1 to 8 tickets), type check (whole number) and presence check
  • authentication (for example username and password) so that only staff can change film times or prices
  • a test plan with normal (for example 3), boundary (1 and 8) and invalid / erroneous (for example 0, 9, ‘two’) data, with the expected result for each
  • iterative testing of each part (choosing a film, entering tickets, payment) as it is written
  • final testing of the whole program against the requirements before release
  • maintainability (comments, meaningful names, subprograms) so faults found later are easier to fix
  • re-test after any fault is fixed

Marked with levels of response: the full level descriptors are in the app.

Stuck? Get 1-to-1 help.

Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.