How to Answer Programming Questions (OCR GCSE Computer Science): Revision Note

Exam code: J277

Robert Hampton

Written by: Robert Hampton

Reviewed by: James Woodhouse

Updated on

How do I answer an OCR GCSE (9-1) Computer Science programming question?

  • Programming questions can appear in both papers

  • Paper 1 may include questions that test understanding and interpretation of algorithms and computational thinking principles

  • Paper 2 is the dedicated component for assessing the ability to actively design, write, test, and refine programs

    • Section A questions can be answered using either pseudocode, flowcharts, bullet points, OCR Exam Reference Language or a high-level programming language

    • Section B questions must be answered using either OCR Exam Reference Language or a high-level programming language

  • To attempt a programming question that requires the writing of a new program, you should always ask yourself the following five key questions:

    • What are the inputs?

    • What are the outputs?

    • What processes take place?

    • What constructs will I need to use?

    • Do I need to use subprograms?

Example 1

Question

Charlie is developing an adding game. The rules of the game are:

  • the player is asked 3 addition questions

  • each question asks the player to add together two random whole numbers between 1 and 10 inclusive

  • if the player gets the correct answer, 1 is added to their score

  • at the end of the game their score is displayed.

Write an algorithm to play this game.

[6 marks]

What are the inputs? What are the outputs? What processes take place?

  • the player is asked 3 addition questions

  • each question asks the player to add together two random whole numbers between 1 and 10 inclusive

  • if the player gets the correct answer, 1 is added to their score

  • at the end of the game their score is displayed.

What constructs will I need to use?

  • Iteration - a FOR loop can be used as the game is a fixed length (3 questions)

  • Selection - an IF statement can be used to check if the answer is correct

  • Declare a score variable to keep track of the score

Do I need to use subprograms?

  • This program can be written without the need to use a subprogram (function or procedure)

Answer

Pseudocode

score = 0

for count = 1 to 3

num1 = random(1, 10)

num2 = random(1, 10)

ans = input("What is” +num1 + " + " + num2 + "?")

if ans = num1 + num2 then

score = score + 1

end if

next count

print("You scored " + score)

Example 2

Question

A program written in a high-level language is used to access data from a database.

This program has a procedure, SaveLogs(), that stores the data to an external text file.

The procedure SaveLogs():

  • takes the string of data to be stored to the text file as a parameter

  • takes the filename of the text file as a parameter

  • stores the string of data to the text file.

Write the procedure SaveLogs()

You must use either:

  • OCR Exam Reference Language, or

  • A high-level programming language that you have studied

[6 marks]

What are the inputs? What are the outputs? What processes take place?

  • takes the string of data to be stored to the text file as a parameter

  • takes the filename of the text file as a parameter

  • stores the string of data to the text file.

Write the procedure SaveLogs()

What constructs will I need to use?

  • This question is testing knowledge of how to write procedures

  • Selection must be used to ensure the correct order of operations

  • No selection or iteration is required

Do I need to use subprograms?

  • This question requires the answer written as a procedure which includes 2 x parameters

  • A procedure does not return a value

Answer

Pseudocode

procedure SaveLogs(data, filename)

logFile = open(filename)

logFile.writeLine(data)

logFile.close()

endprocedure

Unlock more, it's free!

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Robert Hampton

Author: Robert Hampton

Expertise: Computer Science Content Creator

Rob has over 16 years' experience teaching Computer Science and ICT at KS3 & GCSE levels. Rob has demonstrated strong leadership as Head of Department since 2012 and previously supported teacher development as a Specialist Leader of Education, empowering departments to excel in Computer Science. Beyond his tech expertise, Robert embraces the virtual world as an avid gamer, conquering digital battlefields when he's not coding.

James Woodhouse

Reviewer: James Woodhouse

Expertise: Computer Science & English Subject Lead

James graduated from the University of Sunderland with a degree in ICT and Computing education. He has over 14 years of experience both teaching and leading in Computer Science, specialising in teaching GCSE and A-level. James has held various leadership roles, including Head of Computer Science and coordinator positions for Key Stage 3 and Key Stage 4. James has a keen interest in networking security and technologies aimed at preventing security breaches.