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. Object-oriented programming

OCR A Level Computer Science

Topic questions Programming languages and Integrated Development Environments Object-oriented programming

Object-oriented programming

15 questions · 454 marks · about 8 hours

Object-oriented programming questions

TopicObject-oriented programming

OCR H446 Object-oriented programming 15 questions

Algorithms and programming June 2025, Question 8 40 marks

Also involves Arrays · Linked lists

A linked list data structure is designed using object-oriented programming.

The design includes two classes called node and linkedList.

(a)

Describe the features of a linked list data structure.

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

The class design for node is shown here.

Figure for question 8

new() is the constructor method. The constructor method takes a parameter and assigns this to the value attribute.

(b)(i)

The method getNextNode() returns the attribute nextNode.

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

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

The method setValue() takes an integer as a parameter and assigns this to the attribute value

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

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

The class design for linkedList is shown here.

Figure for question 8

new() is the constructor method. The constructor initialises the attribute headNode to a null value.

(c)(i)

Write the constructor method using pseudocode or program code.

[2]
Reveal mark scheme Mark scheme for question 8(c)(i)
(c)(ii)

The class design for node and linkedList are shown again here for your reference.

Figure for question 8

The method getValue() will return the value of a node. The method getNextNode() will return the next node to be accessed in the linked list.

The method outputList() traverses the linked list starting at the node headNode. The method joins the data in each node and returns it.

Complete the method outputList() using pseudocode or program code.

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

The method insertNode() will insert a new node into the linked list.

The method accepts an integer as a parameter, creates a new node with that data and inserts it into the linked list, e.g. insertNode(8) creates a node object with the data 8 and adds it to the linked list.

The program needs to store the following data items in the linked list in the order they are given: 10 25 39

The program then needs to output all of the data in the list using the appropriate method.

Write an algorithm using pseudocode or program code to:

• create a new linkedList object with the identifier createList

• insert each of the data items into the linked list (10, 25, 39)

• output the content of the linked list.

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

A new method is needed to remove a node from the linked list. The method needs to take the data to remove as a parameter and then find this data in the linked list before removing the node.

Describe the steps that this method will need to follow and the decisions that need to be made in the method to remove the correct node.

[5]
Reveal mark scheme Mark scheme for question 8(e)
(f)

The program developer made use of computational methods when designing the object-oriented programming solution. One computational method is divide-and-conquer.

Identify three other computational methods that the program developer could have used.

[3]
Reveal mark scheme Mark scheme for question 8(f)
(g)

* This program uses classes and objects to create a linked list.

An alternative method is creating a 2-dimensional array. In this design the first index stores the data and the second element stores the index of the next data item. Array elements not currently used are also linked together to form a chain of empty values to identify where the next data item can be inserted.

Compare the two different methods of creating a linked list that have been described.

You should include the following in your answer:

• the features of both methods including the reusability of program components

• benefits and drawbacks of both methods in this program

• a conclusion evaluating the efficiency of both methods when designing a program that needs

a linked list.

[12]
Reveal mark scheme Mark scheme for question 8(g)

Computer systems June 2024, Question 9 5 marks

OCR DogCare look after dogs while their owners are at work. They use a program developed in an object-oriented paradigm to store details about each dog.

Figure for question 9

The constructor method sets all the attributes to the values passed in as parameters.

Write pseudocode or program code to define the class Dog. You should include the attributes and constructor method.

You do not need to write the set or get methods.

[5]
Reveal mark scheme Mark scheme for question 9

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)

Computer systems June 2022, Question 2 38 marks

A video streaming service uses a relational database. An extract of the data from two tables from this database is shown in Fig. 2.

Membership contains data about current memberships that customers hold and package contains data about different streaming packages available.

Figure for question 2
(a)(i)

State what is meant by the term ‘primary key’.

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

Identify the foreign key used in the database and the table name where this is a foreign key.

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

Identify the data type of the CostPerMonth(£) field.

[1]
Reveal mark scheme Mark scheme for question 2(a)(iii)
(a)(iv)

Give the name of the field that could be stored using a Boolean data type.

[1]
Reveal mark scheme Mark scheme for question 2(a)(iv)
(b)

The Adverts field indicates if customers will be shown adverts. true indicates that customers will be shown adverts, and false indicates that adverts are not shown.

Write Structured Query Language (SQL) to return the Username and FirstName fields for all customers who see adverts.

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

When new customers join the streaming service, their name, email address and contact details are captured so that they can be entered into the database.

(c)(i)

Identify one method of capturing a new customer’s personal data, describing why this method is suitable.

[3]
Reveal mark scheme Mark scheme for question 2(c)(i)
(c)(ii)

Sometimes the company may need to move or backup its data they hold about customers.

Identify two methods of exchanging data with other computer systems.

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

The database supports ACID transactions. ACID stands for Atomicity, Consistency, Isolation and Durability.

(d)(i)

Describe what is meant by a transaction being durable.

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

Give one way that durability can be achieved for a completed transaction.

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

Explain how record locking can be used to ensure that the ACID principle of isolation is achieved when carrying out multiple transactions.

[3]
Reveal mark scheme Mark scheme for question 2(d)(iii)
(d)(iv)

Give one disadvantage of using record locking.

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

The Copyright Designs and Patents Act 1988 applies to all videos that are streamed.

Explain how this act applies to the videos.

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

All videos that are streamed are compressed. Customers have the option to choose from watching the videos with lossy compression or lossless compression.

Explain how this choice will impact the customer.

[5]
Reveal mark scheme Mark scheme for question 2(f)
(g)

A program is written using an object-oriented programming paradigm and uses a class called video to organise the videos that are streamed to customers.

The class video has these attributes:

• name

• number of views

• star rating.

The constructor method will set the name attribute to the name that is passed in as a parameter. The constructor will also initially set the number of views to 0 and the star rating to 3.

(g)(i)

Write program code or pseudocode to declare the class video and initialise the required attributes as private.

You should include both the attribute definitions and the constructor method in your answer.

[7]
Reveal mark scheme Mark scheme for question 2(g)(i)
(g)(ii)

A public method called updateviews() will update the number of views after a video has been viewed. This method is defined inside the video class.

Write program code or pseudocode for the method updateviews() to increase the number of views by one.

[2]
Reveal mark scheme Mark scheme for question 2(g)(ii)

Algorithms and programming June 2022, Question 8 40 marks

Also involves Programming paradigms

A computer uses a stack data structure, implemented using an array, to store numbers entered by the user.

The array is zero based and has 100 locations.

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

State the purpose of pointerValue.

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

The stack is programmed as an object using object-oriented programming. The design for the class, its attributes and methods are shown:

Figure for question 8
(b)(i)

The method pop() returns the next value in the stack, or –1 if the stack is empty.

Complete the pseudocode method pop().

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

The method push() accepts an integer as a parameter and adds it to the top of the stack unless the stack is already full.

If the push is successful the method returns true.

If the push is unsuccessful due to the stack being full the method returns false.

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

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

The main program initialises a new object of type stack with the identifier mathsStack

Write pseudocode or program code to declare the object.

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

The main program needs to:

• take numbers as input from the user

• push them onto the stack mathsStack until the stack is full

• output an appropriate message if the stack is full.

Complete the pseudocode algorithm to meet these requirements.

Figure for question 8
[4]
Reveal mark scheme Mark scheme for question 8(b)(iv)
(b)(v)

The main program also needs to:

• remove one item from the stack at a time and add this to a total

• output the total every time an item is removed

• stop removing items when either the stack is empty, or 20 items have been removed.

Write pseudocode or program code to meet these requirements.

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

The program is amended to include the use of several queue data structures.

(c)(i)

Describe how an array can be used to implement a queue data structure.

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

* Discuss the use of object-oriented programming and procedural programming to create and manipulate the queue data structures.

You should include the following in your answer:

• the features of object-oriented programming

• the features of procedural programming

• the benefits of using object-oriented instead of procedural programming when creating several queue structures.

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

Computer systems November 2021, Question 7 24 marks

Also involves Algorithm efficiency and Big O notation

A business uses an array with the identifier wNames to store workers’ names. A variable with the identifier top is used to store the index of the last element to be added to the array, which is also the element which will next be removed.

Figure for question 7
(a)(i)

State the name of the type of data structure described above.

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

Using pseudocode, write an algorithm that allows the user to enter a name which is then pushed onto the data structure above, checking first that the data structure is not full.

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

The same workers’ names are stored in a binary search tree which is ordered alphabetically.

Kirstie is set as the root node, with Martyn, Louise, Alex and Anna added one by one.

Figure for question 7
Reveal mark scheme Mark scheme for question 7(b)
(b)(i)

Complete the tree diagram above to show where Martyn, Louise, Alex and Anna would

be added to this binary search tree.

[4]
(b)(ii)

Describe the process of using the binary search tree above to search for the name “Zoe”.

[3]
(b)(iii)

Compare the efficiency of a binary search tree to a linked list when searching for data.

[2]
(b)(iv)

Compare the efficiency of a binary search tree to a hash table when searching for data.

[2]
(c)

An object oriented system is implemented to organise further information about each worker’s attendance. Classes, objects, methods and attributes are used in this system.

(c)(i)

State the meaning of each of the following terms:

Object........

Method........

Attribute........

[3]
Reveal mark scheme Mark scheme for question 7(c)(i)
(c)(ii)

Each worker has a name and an attendance figure which can be between 0 and 100.

Write a definition for a fully encapsulated customer class, providing both get and set methods for all attributes. You do not have to write code for the constructor method.

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

Algorithms and programming November 2021, Question 5 22 marks

Also involves Arrays

Figure for question 5
(a)

The method new is used to denote the constructor for each class.

State the purpose of the constructor.

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

The classes office and house inherit from building.

Describe what is meant by inheritance with reference to these classes.

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

Part of the declaration for the class building is shown.

Complete the pseudocode declaration by filling in the missing statements.

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

Write program code or pseudocode to declare the class house.

Define the attributes and constructor method in your answer. You do not need to write the get or set methods.

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

Christoff develops a new class to store the houses in one road. His class design is shown:

Figure for question 5

The method newbuilding() takes a new building as a parameter, and stores this in the next free space in the array buildings.

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

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

Christoff wants to create a new house called houseOne. It has the properties: 2 floors, 8(m) width, 10(m) height, 3 bedrooms and 2 bathrooms.

The house is located on a road with the identifier limeAvenue of type houseRoad houseOne is the first house in this road.

Write pseudocode or program code to declare the house houseOne, road limeAvenue and assign houseOne to the first array position in the road.

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

Computer systems November 2020, Question 2 17 marks

A supermarket uses an object-oriented approach to organise items that it offers for sale. Part of the class definition for the ItemForSale class is shown below.

Figure for question 2
(a)

The discount attribute represents a percentage discount on the price. The discount can be between 0 and 50 (inclusive). All new items for sale initially have a discount value of 0.

(a)(i)

Write the constructor method for the ItemForSale class.

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

Write a line of code to create an object of type ItemForSale called mushypeas that has a name of “mushy peas” and a price of £0.89

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

Write the calculatePrice() method, which applies the percentage discount to the price and returns the new value.

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

The supermarket has previously had issues with discounts being set as values above 50.

Explain how encapsulation could be applied to the ItemForSale class to stop this problem from occurring.

You are not expected to write any code in your answer to this question.

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

Some items in the supermarket are only available through home delivery. These items are the same as ItemsForSale with the following exceptions:

• the supermarket also stores the location of the stock

• the percentage discount allowed is up to 75 rather than the standard 50.

Explain how inheritance can be used to implement the above requirements.

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

Computer systems November 2020, Question 8 12 marks

8* Procedural programming and object-oriented programming are two paradigms commonly used by programmers when developing computer games.

Discuss the advantages of using object-oriented programming over procedural programming when developing computer games. You should refer to inheritance, encapsulation and polymorphism in your answer.

[12]
Reveal mark scheme Mark scheme for question 8

Algorithms and programming November 2020, Question 6 40 marks

Barney is writing a program to store data in a linked list. He is writing the initial program for a maximum of 10 data items.

Each node in the linked list has a data value and a pointer (to the next item).

A null pointer is stored with the value –1.

(a)
Figure for question 6
(a)(i)

Describe the purpose of freeListPointer.

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

State the purpose of headPointer.

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

Barney wants the nodes to be stored as objects using object-oriented programming. He designs the following class.

Figure for question 6

The constructor assigns the parameters to the attributes to create an object.

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

The class node, uses get methods and set methods.

Describe one difference between get methods and set methods.

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

The function findNodePath() takes the data item to find in the linked list as a parameter and follows the pointers to find the required node.

The function returns the array indexes of all the nodes it visits and joins this to a suitable message stating whether the data was found or not found and then returns this as one string.

Describe how the function findNodePath() will search for the data item and return the required message.

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

The procedure printLinkedList() follows the pointers to print all of the elements in the linked list.

Figure for question 6

The procedure has a number of errors.

(d)(i)

Identify the line of each error and write 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 6(d)(i)
(d)(ii)

Barney will use an Integrated Development Environment (IDE) to debug his program code.

Describe three features commonly found in IDEs that Barney could use to debug his program code.

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

* Barney would like his linked list to be part of a base program that is saved in a library. This means that it can be reused and changed by other programs.

Discuss the benefits of using different object-oriented techniques that Barney could use to achieve this.

[12]
Reveal mark scheme Mark scheme for question 6(e)

Algorithms and programming June 2019, Question 7 40 marks

Figure for question 7
(a)

The programmer will use abstraction to produce the program interface to represent the garden.

(a)(i)

Give two different examples of how abstraction has been used to produce the layout of the garden.

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

Explain the need for abstraction in the production of this program.

[3]
Reveal mark scheme Mark scheme for question 7(a)(ii)
(a)(iii)

The user needs to input data into the program to set up their garden layout.

Identify three pieces of data that the user may input into this program.

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

The program is to be built using object oriented programming.

All items that can be added to the garden are declared as instances of the class GardenItem

The class has the following attributes:

Figure for question 7
(b)(i)

The constructor method sets the attributes to values that are passed as parameters.

Write pseudocode or program code to declare the class GardenItem and its constructor. All attributes should be private and initialised through the constructor (e.g. daisies =

new GardenItem("Flowerbed",2,1) maths symbol

[4]
Reveal mark scheme Mark scheme for question 7(b)(i)
(b)(ii)

The trees in the garden layouts are defined by the class Tree. This class inherits from GardenItem.

The class Tree has the additional attributes: height, sun, shade.

If sun is true then the tree can grow in full sun, if it is false then it cannot.

If shade is true then the tree can grow in full shade, if it is false then it cannot.

The length and width of a tree are the same. Only one value for these measurements is passed to the constructor.

Write an algorithm, using pseudocode or program code, to declare the class Tree Declare all attributes as private.

[5]
Reveal mark scheme Mark scheme for question 7(b)(ii)
(b)(iii)

The Common Oak is a type of tree. It has a maximum height, length and width of 40 m. It can grow in sun and shade.

Write a statement, using pseudocode or program code, to declare an instance of tree for the Common Oak. Give the object the identifier firstTree.

[4]
Reveal mark scheme Mark scheme for question 7(b)(iii)
(b)(iv)

The classes GardenItem and Tree use get and set methods to access and alter their private attributes.

Write the get method getItemName and set method setItemName for class GardenItem. The set method takes the new value as a parameter.

Do not write any other methods, or re-declare the class.

[4]
Reveal mark scheme Mark scheme for question 7(b)(iv)
(b)(v)
Figure for question 7
[6]
Reveal mark scheme Mark scheme for question 7(b)(v)
(c)

* The programmer is designing the program to make use of caching and re-useable components.

Explain and evaluate the use of caching and re-useable components in the design of the garden program.

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

Computer systems June 2018, Question 7 16 marks

Also involves Ethical, legal, cultural and environmental impacts of digital technology

A taxi firm is investigating replacing its drivers with self-driving cars.

(a)

Explain why the self-driving system will use a real-time operating system.

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

The code for the self-driving system has been written using an object-oriented programming language.

It recognises obstacles in the road and then classifies them. The class for Obstacle is shown below.

Figure for question 7
(b)(i)

Write a line of code to create an object called bollard of type Obstacle which is not moving and is 7.8 metres away in a direction of 8 degrees.

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

Describe an example of encapsulation in the class definition code above.

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

Describe the advantages of using encapsulation.

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

The self-driving program recognises people as a special type of obstacle and the class Person should inherit the methods and attributes of Obstacle. People are treated like other obstacles except:

• when the updateDistance method is called, if the person is more than 2 metres away but is 5 metres (or less) away, the method Controls.beepHorn() is called.

• when the person is 2 metres away (or closer), the method Controls.applyBrakes() is called as well as Controls.beepHorn().

Complete the class Person.

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

Give one advantage and one disadvantage to the customers of the taxi using self-driving cars rather than drivers.

Advantage

Figure for question 7

Disadvantage

Figure for question 7
[2]
Reveal mark scheme Mark scheme for question 7(d)

Algorithms and programming June 2018, Question 6 40 marks

Also involves File handling · Records · Stacks and queues

Kamran is writing a program to manipulate the data for a set of items.

For each item, the program needs to store:

• Item name (e.g. Box)

• Cost (e.g. 22.58)

• Date of arrival (e.g. 1/5/2018)

• Transferred (e.g. true)

The items are added to a queue for processing.

The queue is defined as a class, itemQueue.

Figure for question 6

The head attribute points to the first element in the queue. The tail attribute points to the next available space in the queue. The numItems attribute states how many items are currently in the queue.

(a)

The data about the items can be stored using either a record structure, or as objects of a class.

(a)(i)

Explain the similarities and differences between a record and a class.

Figure for question 6

maths symbol

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

Kamran chooses to use a record structure to store the data about the items.

Record structures may be declared using the following syntax:

Figure for question 6

Complete the pseudocode to declare a record called items.

Figure for question 6
[5]
Reveal mark scheme Mark scheme for question 6(a)(ii)
(a)(iii)

New records may be created using the following syntax:

Figure for question 6

Write a programming statement to create a new item, using the identifier ‘box1’, with the item name “Box”, the cost 22.58, date of arrival 1/5/2018 and transferred true.

Figure for question 6

maths symbol

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

The array, theItems, stores the items in the queue. When the tail of the queue exceeds the last element in the array, it adds a new item to the first element if it is vacant.

For example, in the following queue, the next item to be added would be placed at index 0.

Index0123456789
ElementDataDataDataDataDataDataData
(b)(i)

Define the term ‘queue’.

Figure for question 6

maths symbol

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

The attributes in itemQueue are all declared as private.

Explain how a private attribute improves the integrity of the data.

Figure for question 6

maths symbol

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

The constructor method creates a new instance of itemQueue and sets the head, tail and numItems attributes to 0.

Write an algorithm, using pseudocode or program code, for the constructor including the initialisation for all attributes.

Figure for question 6

maths symbol

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

The enqueue method:

maths symbol takes as a parameter the item to insert in the queue

maths symbol checks if the queue is full

maths symbol reports an error and returns false if the queue is full

maths symbol does the following if the queue is not full: o adds the item to the array at the tail position and adjusts the pointer(s) o returns true

The attribute numItems stores the number of items currently in the queue.

Write an algorithm, using pseudocode or program code, for the enqueue method.

Figure for question 6

maths symbol

[6]
Reveal mark scheme Mark scheme for question 6(b)(iv)
(b)(v)

Write a programming statement to declare an instance of itemQueue called myItems

Figure for question 6
[1]
Reveal mark scheme Mark scheme for question 6(b)(v)
(b)(vi)

Write a procedure, insertItems(), to ask the user to input the data for an item. The item is then added to the queue myItems. The user is continually asked to input data items until the queue is full.

Figure for question 6

maths symbol

[5]
Reveal mark scheme Mark scheme for question 6(b)(vi)
(b)(vii)

When the main program ends, the items and the queue no longer exist.

Describe how Kamran could amend the program to make sure the items and queue still exist and are used the next time the program is run.

Figure for question 6

maths symbol

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

* Kamran wants to expand the program to allow it to handle up to 100,000,000 items and to allow him to search for data about items. Kamran is worried that the increase in the number of items will cause a decrease in the performance of the program. He decides to investigate the benefits of caching and concurrent processing.

Evaluate the use of caching and concurrent processing in this scenario and make a recommendation to Kamran.

Figure for question 6

maths symbol

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

Algorithms and programming June 2017, Question 6 40 marks

A software developer is creating a Virtual Pet game.

The user can choose the type of animal they would like as their pet, give it a name and then they are responsible for caring for that animal. The user will need to feed, play with, and educate their pet.

The aim is to keep the animal alive and happy, for example if the animal is not fed over a set period of time then the pet will die.

• The game tells the user how hungry or bored the animal is as a percentage (%) and the animal’s intelligence is ranked as a number between 0 and 150 (inclusive).

• Hunger and boredom increase by 1% with every tick of a timer.

• When the feed option is selected, hunger is reduced to 0.

• When the play option is selected, bored is reduced to 0.

• When the read option is selected, the intelligence is increased by 0.6% of its current value.

An example of the game is shown:

Figure for question 6

Fig. 1.1

(a)

Identify three inputs that the user will have to enter to start, and/or play the game.

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

The developer is using decomposition to design the game.

(b)(i)

Describe the process of decomposition.

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

The developer needs to write procedures for the options play and read. Each of the options changes its corresponding value, and outputs the results to the screen.

(c)(i)

Write a procedure, using pseudocode, to reset bored and output the new value in an appropriate message.

[3]
Reveal mark scheme Mark scheme for question 6(c)(i)
(c)(ii)

Write a procedure, using pseudocode, to increase intelligence by 0.6% and output the new intelligence in an appropriate message.

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

The developer is extending the game to allow users to have multiple pets of different types. The developer has written a class, Pet.

The attributes and methods in the class are described in the table:

Figure for question 6

Part of the class declaration is given:

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

Write a line of code that creates a new instance of Pet for a Tiger called “Springy”.

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

The method outputGreeting for the superclass is written as follows:

Figure for question 6

A class is needed for Tiger. The class needs to:

• inherit the methods and attributes from pet

• in the constructor, set type to Tiger, intelligence to 10, hunger to 50 and bored to 10

• extend the method outputGreeting, by outputting an additional line that says “I like to eat meat and roar”

Write, using pseudocode, the class Tiger.

[5]
Reveal mark scheme Mark scheme for question 6(d)(iii)
(e)

(e*) The developer made use of abstraction when creating the Virtual Pet game.

Discuss the need for and purpose of abstraction and how abstraction will be used in the

development of the game.

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

The developer is storing the user’s pets in a 1-dimensional array. At each timer interval, the array is searched, using a linear search, to check if any pets’ hunger or bored values are greater than 90%. If they are, an alert is displayed to the user.

(f)(i)

State the complexity of searching the pets in Big-O notation.

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

A given computer takes 4 milliseconds (ms) to search an array of 20 pets. Calculate an estimate of how long the computer will take to search an array of 100 pets.

Show your working.

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

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