BREAKING
Student's code works, nobody knows why, including student★Local teen writes pseudocode, accidentally invents a language★Binary joke told in class, exactly 10 students laugh★
  1. Home
  2. A Level
  3. Computer Science
  4. OCR
  5. Variables, constants, inputs, outputs and assignment

OCR A Level Computer Science

Topic questions Programming fundamentals Variables, constants, inputs, outputs & assignment

Variables, constants, inputs, outputs & assignment

5 questions · 159 marks · about 3 hours

Variables, constants, inputs, outputs and assignment questions

OCR H446 Variables, constants, inputs, outputs and assignment 5 questions

Algorithms and programming June 2025, Question 6 18 marks

Also involves Arrays

A student is writing a program in a high-level programming language.

(a)

The student writes the program using an Integrated Development Environment (IDE).

Complete the table by identifying and describing three features of an IDE that the student can use to debug their program.

Figure for question 6
[6]
Reveal mark scheme Mark scheme for question 6(a)
(b)

The program the student is developing includes both global and local variables.

(b)(i)

Explain the difference between a global variable and a local variable.

[2]
Reveal mark scheme Mark scheme for question 6(b)(i)
(b)(ii)

Describe one drawback of using global variables in a program.

[2]
Reveal mark scheme Mark scheme for question 6(b)(ii)
(b)(iii)

Describe one drawback of using local variables in a program.

[2]
Reveal mark scheme Mark scheme for question 6(b)(iii)
(c)

A variable can be passed as a parameter into a function by value or by reference.

Describe what parameter passing by value means.

[2]
Reveal mark scheme Mark scheme for question 6(c)
(d)

An algorithm is needed to count how many times each of the numbers from 1 to 9 appear in an array called myArray. Another array called checked is used to store each number found in myArray and the number of times it appears. For example, the contents of myArray are:

Figure for question 6

Based on these contents in myArray, the contents in checked would be:

72
33
62
51
21
–10
–10
–10
–10

–1 indicates an unused space in the array as the numbers 1, 4, 8 and 9 have not been found.

The student has written the following pseudocode for this program.

The pseudocode contains several errors.

Figure for question 6

Identify the line number of any four errors and write the corrected line for each error.

Error 1

Error 2

Error 3

Error 4

[4]
Reveal mark scheme Mark scheme for question 6(d)

Algorithms and programming June 2024, Question 9 40 marks

Also involves Arrays

A game is being written that makes use of object-oriented programming. A prototype for one part of the game is being designed that includes a character, a road and a prize to collect.

The road will have 50 spaces that a character can move along. Each space on the road will store a null value or a prize object for the user to collect. Each space is numbered sequentially from the first space (position 0) to the last space (position 49) and will not change during the game. As the player travels down the road, the position the player is on the road will be output.

(a)

The road is designed to be a 1-dimensional array with the identifier road.

Explain why an array is a suitable data structure to represent the road.

[3]
Reveal mark scheme Mark scheme for question 9(a)
(b)

The characters and prizes are designed as separate classes. 10 of the spaces on the road will contain an instance of the class Prize. The other spaces will be empty.

The class design for Prize is here.

Figure for question 9

new() is the constructor method. The name, type and value are passed to the constructor as parameters which then assigns these to the attributes.

(b)(i)

The method getName() returns the data in the attribute name.

Write the method getName() using pseudocode or program code.

[2]
Reveal mark scheme Mark scheme for question 9(b)(i)
(b)(ii)

A global 1-dimensional array, allPrizes, stores 10 objects of type Prize.

The prize in index 3 has the name "Box", the type is "money" and the value is 25.

Write pseudocode or program code to create a new object for this prize and store it in index 3 of allPrizes.

[3]
Reveal mark scheme Mark scheme for question 9(b)(ii)
(b)(iii)

The game starts with 10 prizes. Each prize is allocated to one space on the road.

An algorithm needs designing that will generate a random space on the road for each prize. Each road space can only store one prize.

Describe the decisions that will need to be made in this algorithm and how these will affect the program flow.

[3]
Reveal mark scheme Mark scheme for question 9(b)(iii)
(c)

The class design for Character is here.

Figure for question 9

The four get methods return the associated attribute.

The number of moves is passed to changePosition() as a parameter. The method adds this value to the character’s position on the road.

The type and value of an object are passed to updateValues() as parameters. If the object is money the value is added to the character’s money. If the type is experience the value is added to experience. If the type is neither money or experience no changes are made.

(c)(i)

new() is the constructor method. The name of the character is passed into the constructor as a parameter. The constructor then initialises both the experience and road position of the character to 0 and initialises the amount of money to 5.

Write the constructor method for Character using either pseudocode or program code. You do not need to declare the class, the attributes or any other methods.

[5]
Reveal mark scheme Mark scheme for question 9(c)(i)
(c)(ii)

The type and value of a prize are passed as parameters to the method updateValues. If the type is money the value is added to the character’s money. If the type is experience then the value is added to the experience. If the type is neither money or experience no changes are made.

For example, for the Character player1:

player1.updateValues("money",10) updates player1’s money by 10

player1.updateValues("experience",5) updates player1’s experience by 5

player1.updateValues("foo",9) has no effect on player1.

Write pseudocode or program code for the method updateValues().

[5]
Reveal mark scheme Mark scheme for question 9(c)(ii)
(d)

This incomplete pseudocode algorithm:

• creates a new character with the name Jamal

• loops until the character reaches the end of the road

• generates a random number of spaces to move between 1 and 4 (including 1 and 4)

• moves the character and checks if the new space has a prize

• updates the character attributes if there is a prize

• outputs the character’s new attribute values.

Complete the pseudocode algorithm.

Figure for question 9
[6]
Reveal mark scheme Mark scheme for question 9(d)
(e)

The procedure displayRoad() outputs the contents of each space in the road. The number of each space is output with either:

• the word "empty" if there is no prize

• the name of the prize if there is a prize.

Figure for question 9

The algorithm contains errors.

Give the line number of four different errors and write the corrected line for each error.

Error 1

Error 2

Error 3

Error 4

[4]
Reveal mark scheme Mark scheme for question 9(e)
(f)

* A programmer is going to create a prototype for one small part of the game. Both road and allPrizes will be needed throughout the whole prototype. The programmer is considering making these global arrays as she thinks it will reduce the development time. Another programmer has suggested that doing this may create some problems when the rest of the game is created at a later stage.

Compare the use of global and local variables in this program.

You should include the following in your answer:

• the use of local and global variables

• alternative methods to using global variables

• the appropriateness of each to this program design.

[9]
Reveal mark scheme Mark scheme for question 9(f)

Algorithms and programming June 2023, Question 9 40 marks

Also involves Arrays

A text-based computer game allows a user to dig for treasure on an island. The island is designed as a grid with 10 rows and 20 columns to store the treasure. Each square is given an x and y coordinate. Some of the squares in the grid store the name of a treasure object. Each treasure object has a value, e.g. 100 and a level, e.g. "Bronze."

(a)

The computer game makes use of abstraction.

(a)(i)

Describe what is meant by the term abstraction and give an example of how abstraction can be used in the treasure game.

[3]
Reveal mark scheme Mark scheme for question 9(a)(i)
(a)(ii)

Give three benefits of using abstraction when writing a program.

[3]
Reveal mark scheme Mark scheme for question 9(a)(ii)
(b)

The treasure game is being programmed using an object-oriented paradigm.

A class, Treasure, is used to store the treasure objects.

The design for the Treasure class, its attributes and methods is shown here.

Figure for question 9
(b)(i)

The constructor method takes a value as an integer, e.g. 100, and a level, e.g. "bronze", as parameters and assigns these to the attributes.

Write pseudocode or program code to declare the class Treasure.

You should define the attributes and constructor method in your answer.

You do not need to write the get methods.

[5]
Reveal mark scheme Mark scheme for question 9(b)(i)
(b)(ii)

The get method getLevel() will return the appropriate attribute.

Write the method getLevel() using either pseudocode or program code.

[2]
Reveal mark scheme Mark scheme for question 9(b)(ii)
(b)(iii)

Describe the object-oriented programming technique being used in part 9(b)(ii).

[2]
Reveal mark scheme Mark scheme for question 9(b)(iii)
(c)

A class, Board, is used to store the 10 row (x coordinate) by 20 column (y coordinate) grid.

The design for the Board class, its attributes and methods is shown here.

Figure for question 9

The constructor initialises each space in the grid to a treasure object with value as-1 and level as an empty string.

Complete the following pseudocode for the constructor method.

Figure for question 9
[5]
Reveal mark scheme Mark scheme for question 9(c)
(d)

A procedure, guessGrid():

• takes a Board object as a parameter

• accepts the row (x) and column (y) coordinates from the user

• outputs "No treasure" if there is no treasure found at the coordinate (level is an empty string)

• if there is treasure at that coordinate, it outputs the level and the value of the treasure in an appropriate message.

Write the procedure guessGrid() using either pseudocode or program code.

[7]
Reveal mark scheme Mark scheme for question 9(d)
(e)

Describe two benefits of using an object-oriented paradigm rather than a procedural paradigm.

[4]
Reveal mark scheme Mark scheme for question 9(e)
(f)

* The main program initialises a new instance of Board. The programmer is considering declaring this as a global variable or as a local variable and then passing this into the subroutines that control the game.

Compare the use of variables and parameters in this game.

You should include the following in your answer:

• what is meant by a local variable and global variable

• how local and global variables can be used in this program

• the use of passing parameters by value and by reference.

[9]
Reveal mark scheme Mark scheme for question 9(f)

Algorithms and programming June 2022, Question 1 21 marks

A computer program stores data in an array named words.

(a)

The data in the array needs to be searched for a value that the user inputs.

(a)(i)

One example of a searching algorithm is a binary search.

Identify the precondition for a binary search.

[1]
Reveal mark scheme Mark scheme for question 1(a)(i)
(a)(ii)

A second example of a searching algorithm is a linear search.

Describe how a linear search works.

[4]
Reveal mark scheme Mark scheme for question 1(a)(ii)
(b)

The array words is defined as a global variable and contains these values:

Figure for question 1

The pseudocode function useWords() here uses the global array words.

The number of words in the array words is passed as a parameter.

Figure for question 1
(b)(i)

Identify two variables in the function useWords().

[2]
Reveal mark scheme Mark scheme for question 1(b)(i)
(b)(ii)

numberOfWords is a parameter passed by value.

Describe the difference between passing a parameter by value and by reference.

[2]
Reveal mark scheme Mark scheme for question 1(b)(ii)
(b)(iii)

Rewrite the function useWords() to use a while loop instead of a for loop.

The function header and close have been written for you.

Write your answer using pseudocode or program code.

function useWords(numberOfWords: byVal)

endfunction

[4]
Reveal mark scheme Mark scheme for question 1(b)(iii)
(c)

Give one benefit and one drawback of declaring the array as a global variable instead of a local variable.

[2]
Reveal mark scheme Mark scheme for question 1(c)
(d)

Describe one feature of an Integrated Development Environment (IDE) that can be used to help write the program and one feature that can be used to help test the program.

[4]
Reveal mark scheme Mark scheme for question 1(d)
(e)

Functions and procedures are reusable components.

Give two benefits of writing a program with reusable components.

[2]
Reveal mark scheme Mark scheme for question 1(e)

Algorithms and programming November 2021, Question 8 40 marks

Also involves Syntax and logic errors · Arrays

Figure for question 8
(a)

Juan is creating a structure diagram to design the game.

(a)(i)
Figure for question 8
[3]
Reveal mark scheme Mark scheme for question 8(a)(i)
(a)(ii)

A structure diagram is one method of showing the decomposition of a problem.

Explain why decomposing a problem can help a developer design a solution.

[2]
Reveal mark scheme Mark scheme for question 8(a)(ii)
(a)(iii)

Identify one input, one process and one output required for the game.

[3]
Reveal mark scheme Mark scheme for question 8(a)(iii)
(b)

Juan uses the structure diagram to create a modular program with a number of subroutines. The program will use two integer 2-dimensional arrays to store the puzzles:

• puzzle(5,5) stores the solution

• answerGrid(5,5) stores the user’s current grid.

A 0 represents a white box and a 1 represents a black box.

(b)(i)
Figure for question 8
[5]
Reveal mark scheme Mark scheme for question 8(b)(i)
(b)(ii)

Explain the purpose of line 03 in the function countRow.

[2]
Reveal mark scheme Mark scheme for question 8(b)(ii)
(b)(iii)

Describe the purpose of branching and iteration in the function countRow.

[3]
Reveal mark scheme Mark scheme for question 8(b)(iii)
(b)(iv)
Figure for question 8
[6]
Reveal mark scheme Mark scheme for question 8(b)(iv)
(b)(v)

The function checkWon() takes answerGrid and puzzle as parameters and compares each element in the grids. If they are identical, it returns true, otherwise returns false.

Figure for question 8

There are three logic errors in the function checkWon.

State the line number of each error and give the corrected line.

Error 1 line number........

Error 1 correction........

Error 2 line number........

Error 2 correction........

Error 3 line number........

Error 3 correction........

[3]
Reveal mark scheme Mark scheme for question 8(b)(v)
(c)

* Juan passed the two arrays as parameters, but he did consider making them globally accessible.

Compare the use of global and local variables and data structures in this program. Include the use of parameters and program efficiency in your answer.

[9]
Reveal mark scheme Mark scheme for question 8(c)
(d)

Juan wants to create a program that will generate new Nonograms with different grid sizes. For example a Nonogram with a 10 × 10 grid or a 5 × 20 grid.

Describe how the program could be written to automatically generate a new Nonogram.

[4]
Reveal mark scheme Mark scheme for question 8(d)

Report a problem with a question on this page
What is wrong?

Goes to whoever maintains the question split. No account needed and nothing is published on this page.

Memes

Certified Computer Science memes. Peer-reviewed by nobody.

Laugh now. Cry in the exam hall later. Then come back and do a past paper.

Write a proper algorithm
Write ‘sort it’ and leave
Me on the 6-mark pseudocode question
Debugging with print statements
Using a trace table
Knowing the difference between = and ==
Explaining recursion by explaining recursion
Code enlightenment, ranked

Mum 💖

can you fix the wifi since you do computers 🥰

that's not what computer science is

so that's a no then

📱 Screen time this week · Discord8h 2m

Turned it off and on again

Computer Science starter pack

Laptop with 47 tabs openPython error on line 1Counting binary on fingersThis website
Compiled with zero errors