0% found this document useful (0 votes)
15 views44 pages

7 1 Programming Techniques 3mtdyhh8JvDrfQ3K

The document outlines an A Level OCR Computer Science exam consisting of 42 questions covering various programming concepts such as data types, programming constructs, and algorithms. It includes easy, medium, and hard questions related to programming techniques, pseudocode, and the use of functions and procedures. The exam is structured to test students' understanding of programming principles and their application in solving problems.

Uploaded by

sabriyayaqoob2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views44 pages

7 1 Programming Techniques 3mtdyhh8JvDrfQ3K

The document outlines an A Level OCR Computer Science exam consisting of 42 questions covering various programming concepts such as data types, programming constructs, and algorithms. It includes easy, medium, and hard questions related to programming techniques, pseudocode, and the use of functions and procedures. The exam is structured to test students' understanding of programming principles and their application in solving problems.

Uploaded by

sabriyayaqoob2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

A Level OCR Computer Science 3 hours 42 questions

Exam Questions

7.1 Programming
Techniques
Data Types / Arithmetic, Logical & Boolean Operators / Programming Constructs /
Selection / Iteration / Modularity, Functions & Procedures / Parameter Passing /
Recursion / Global & Local Variables / Integrated Development Environment (IDE) /
Programming Classes, Objects, Methods & Attributes / Programming Inheritance /
Programming Encapsulation / Programming Polymorphism

Easy (14 questions) /27 Scan here to return to the course


or visit savemyexams.com
Medium (18 questions) /92

Hard (10 questions) /64

Total Marks /183

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 1
Easy Questions
1 A programmer has designed a program that includes a reusable program component

The reusable program component is a function called isInteger(). This will take a string as
an argument and then check that each digit is between 0 and 9. For example if 103 is
input, it will check that the digits 1, 0 and 3 are each between 0 and 9.

The asc() function returns the ASCII value of each digit. For example asc("1") returns 49.

The ASCII value for 0 is 48. The ASCII value for 9 is 57.

01 function isInteger(number)

02 result = true

03 for count = 0 to number.length-1

04 asciiValue = asc(number.substring(count, 1))

05 if not(asciiValue >= 48 and asciiValue <= 57) then

06 result = false

07 endif

08 next count

09 return result

10 endfunction
Give the line number where the iteration construct starts in the function isInteger().

(1 mark)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 2
2 A card game uses a set of 52 standard playing cards. There are four suits; hearts,
diamonds, clubs and spades. Each suit has a card with a number from; 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13.

The card game randomly gives 2 players 7 cards each. The unallocated cards become
known as the deck.

The players then take it in turns to turn over a card. A valid move is a card of the same
suit or the same number as the last card played.

The winner is the first player to play all of their cards.

A function, checkValid(), takes the card the player has selected, and the last card played as
parameters.

It returns true if the player’s move is valid and returns false if the player’s move is not
valid.

State the reason why checkValid() is a function and not a procedure.

(1 mark)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 3
3 The following pseudocode procedure performs an insertion sort on the array parameter.

01 procedure insertionSort(dataArray:byRef)

02 for i = 1 to dataArray.Length - 1

03 temp = dataArray[i]

04 tempPos = i – 1

05 exit = false

06 while tempPos >= 0 and exit == false

07 if dataArray[tempPos] < temp then

08 dataArray[tempPos + 1] = dataArray[tempPos]

09 tempPos = tempPos - 1

10 else

11 exit = true

12 endif

13 endwhile

14 dataArray[tempPos + 1] = temp

15 next i

16 endprocedure
Explain why dataArray is passed by reference and not by value.

(2 marks)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 4
4 A doCheck() function takes an integer value as a parameter, carries out a series of
calculations and returns an integer value.

The function is shown here.

function doCheck(number)
temp = str(number)
max = temp.length – 1
total = 0
for x = 0 to max
total = total + int(temp.subString(x,1))
next x
return total MOD 10
endfunction
State the value returned from the function when doCheck(3178) is called

(1 mark)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 5
5 (a) A programmer has designed a program that includes a reusable program component.

The reusable program component is a function called isInteger(). This will take a string as
an argument and then check that each digit is between 0 and 9. For example if 103 is
input, it will check that the digits 1, 0 and 3 are each between 0 and 9.

The asc() function returns the ASCII value of each digit. For example asc("1") returns 49.

The ASCII value for 0 is 48. The ASCII value for 9 is 57.

01 function isInteger(number)
02 result = true
03 for count = 0 to number.length-1
04 asciiValue = asc(number.substring(count, 1))
05 if not(asciiValue >= 48 and asciiValue <= 57) then
06 result = false
07 endif
08 next count
09 return result
10 endfunction
Identify one identifier used in the function isInteger().

(1 mark)

(b) Give the line number where the branching (selection) construct starts in the function
isInteger().

(1 mark)

6 Give two reasons why reusable program components are used in programs.

(2 marks)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 6
7 (a) A programmer creates this function shown in Fig. 5 using a high-level language.

function mystery(x,y)

total = x + y

while x >= 10 then

x = x – 10

y = y – 10

total = total + x + y

endwhile

return total

endfunction
State the value output by the line print(mystery(10,20))

(1 mark)

(b) State the value output by the line print(mystery(0,70))

(1 mark)

(c) State the value output by the line print(mystery(45,55))

(1 mark)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 7
8 (a) The array words is defined as a global variable and contains these values:

"house" "boat" "car" "telephone" "garden" "spice" "elephant"

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

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

function useWords(numberOfWords : byVal)

contents = ""

for count = 0 to numberOfWords - 1

contents = contents + words[count] + " "

next count

return contents

endfunction
Identify two variables in the function useWords().

(2 marks)

(b) numberOfWords is a parameter passed by value.

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

(2 marks)

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

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 8
(2 marks)

10 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 marks)

11 Functions and procedures are reusable components.

Give two benefits of writing a program with reusable components.

(2 marks)

12 A program uses the recursive function calculate(). The function is written in pseudocode.

1. function calculate(number : byVal)


2. if number == 1 then
3. return number
4. else
5. return number + calculate (number - 1)
6. endif
7. endfunction
Give the line number in the algorithm calculate() where a recursive call is made.

(1 mark)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 9
13 A program uses the recursive function calculate(). The function is written in pseudocode.

1. function calculate(number : byVal)


2. if number == 1 then
3. return number
4. else
5. return number + calculate (number - 1)
6. endif
7. endfunction
Give the pseudocode function call that would return 55 from the recursive function
calculate().

(1 mark)

14 The algorithm uses a while loop

State a different type of loop that could be used instead of the while loop in the given
algorithm.

(1 mark)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 10
Medium Questions
1 (a) A Nonogram is a logic puzzle where a player needs to colour in boxes. The puzzle is laid
out as a grid and each square needs to be either coloured black or left white.

The numbers at the side of each row and column tells the player how many of the boxes
are coloured in consecutively. Where a row has two or more numbers, there must be a
white square between the coloured squares.

Juan is creating a program that will store a series of Nonograms for a user to play. The
game will randomly select a puzzle and display the blank grid with the numbers for each
row and column to the user.

The user plays the game by selecting a box to change its colour. If the box is white it will
change to black and if it is black it will change to white. The user can choose to check the
answer at any point, and the game will compare the grid to the answers and tell the user
if they have got it correct or not.

Juan creates 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.

Juan creates a function, countRow(), to count the number of coloured boxes in one row
and return the number of consecutive coloured boxes in that row. If there is more than
one set of coloured boxes in the row, these are joined together and the string is
returned.

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 11
For example, in the following grid countRow for row 0 will return "2" as a string, and
countRow for row 2 will return "1 1" as a string. If there are no 1s in a row, then "0" is
returned as a string.

Complete the pseudocode algorithm countRow().

01 function countRow(puzzle:byref, rowNum:byval)

02 count = 0

03 output = " "

04 for i = 0 to ……………………………………………

05 if puzzle[rowNum, i] == …………………………………………… then

06 count = count + 1

07 elseif count >= 1 then

08 output = output + str(……………………………………………) + " "

09 count = 0

10 endif

11 next i

12 if count>= 1 then

13 output=output+str(count)

14 elseif output == "" then

15 output = "……………………………………………"

16 endif

17 return ……………………………………………

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 12
18 endfunction

(5 marks)

(b) Explain the purpose of line 03 in the function countRow.

(2 marks)

(c) Describe the purpose of branching and iteration in the function countRow.

(3 marks)

(d) The procedure displayRowAnswer() takes puzzle as a parameter and outputs the value in
each box. Each box in a row is separated by a space. At the end of each row there are
two spaces and (by calling the function countRow from part a the clue values for that row.

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 13
For example the puzzle below:

Would output

Write pseudocode or program code for the procedure displayRowAnswer()

(6 marks)

(e) 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.

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 14
(9 marks)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 15
2 Hugh has written a recursive function called thisFunction() using pseudocode.

01 function thisFunction(theArray, num1, num2, num3)

02 result = num1 + ((num2 - num1) DIV 2)

03 if num2 < num1 then

04 return -1

05 else

06 if theArray[result] < num3 then

07 return thisFunction(theArray, result + 1, num2, num3)

08 elseif theArray[result] > num3 then

09 return thisFunction(theArray, num1, result - 1, num3)

10 else

11 return result

12 endif

13 endif

14 endfunction
The function DIV calculates integer division, e.g. 5 DIV 3 = 1

Hugh could have written thisFunction() using iteration instead of recursion.

Compare two differences between recursion and iteration.

(4 marks)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 16
3 A programmer has designed a program that includes a reusable program component.

01 function isInteger(number)
02 result = true
03 for count = 0 to number.length-1
04 asciiValue = asc(number.substring(count, 1))
05 if not(asciiValue >= 48 and asciiValue <= 57) then
06 result = false
07 endif
08 next count
09 return result
10 endfunction
Describe the purpose of the following lines in the function isInteger().

Line 03

Line 04

Line 09

(3 marks)

4 A recursive pseudocode function, recursiveAlgorithm(), is shown.

01 function recursiveAlgorithm(value)
02 if value <= 0 then
03 return 1
04 elseif value MOD 2 = 0 then
05 return value + recursiveAlgorithm(value – 3)
06 else
07 return value + recursiveAlgorithm(value – 1)
08 endif
09 endfunction
Describe the key features of a recursive algorithm.

You may refer to the function, recursiveAlgorithm() in your answer.

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 17
(3 marks)

5 A programmer uses an Integrated Development Environment (IDE).

Complete the table by identifying and describing three IDE features that can help the
programmer to develop, or debug a program.

IDE feature Description

(6 marks)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 18
6 (a) 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."

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.

class: Treasure

attributes:
private value : integer
private level : string

methods:
new()
function getValue()
function getLevel()

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

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

(2 marks)

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

(2 marks)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 19
7 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.

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 marks)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 20
8 A programmer creates this function shown in Fig. 5 using a high-level language.

function mystery(x,y)
total = x + y
while x >= 10 then
x = x – 10
y = y – 10
total = total + x + y
endwhile
return total
endfunction
The programmer creates another function to count and return how many capital letters
are in a string that is passed into the function as a parameter.

The asc() function takes in a character and returns its ASCII value. For example asc("A")
returns 65. Capital letters have ASCII values between 65 and 90 inclusive.

Complete the function below

function countCapitals(text)
// initialise counter to 0
capCount = 0
// loop through each character in the string passed in
for x = 0 to text.length-1
c = text.subString(x, 1)
// check if character is a capital
if asc(c) >= 65 ……………………………………………………………
// if so, increment counter
…………………………………………………………………………
endif
next x
……………………………………………………………………
endfunction

(3 marks)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 21
9 The array words is defined as a global variable and contains these values:

function useWords(numberOfWords : byVal)


contents = ""
for count = 0 to numberOfWords - 1
contents = contents + words[count] + " "
next count
return contents
endfunction
The pseudocode function useWords() here uses the global array words.

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

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)

(4 marks)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 22
10 A card game uses a set of 52 standard playing cards. There are four suits; hearts,
diamonds, clubs and spades. Each suit has a card with a number from; 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13.

The card game randomly gives 2 players 7 cards each. The unallocated cards become
known as the deck.

The players then take it in turns to turn over a card. A valid move is a card of the same
suit or the same number as the last card played.

The winner is the first player to play all of their cards.

A function, checkValid(), takes the card the player has selected, and the last card played as
parameters.

It returns true if the player’s move is valid and returns false if the player’s move is not
valid.

The programmer will use a branching (selection) construct to make decisions.

Describe the decisions that will be made in the checkValid() function and how these
change the return values.

(3 marks)

11 A program uses the recursive function calculate(). The function is written in pseudocode.

1. function calculate(number : byVal)


2. if number == 1 then
3. return number
4. else
5. return number + calculate (number - 1)
6. endif
7. endfunction
State two features of any recursive algorithm.

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 23
(2 marks)

12 1. function calculate(number : byVal)


2. if number == 1 then
3. return number
4. else
5. return number + calculate (number - 1)
6. endif
7. endfunction
Trace the recursive function calculate() and give the final return value, when the following
function call is run:

calculate(5)

You may choose to use the table below to give your answer

Function call number return

calculate(5)

(5 marks)

13 Christoff is writing a program to simulate a city using object-oriented programming. He is


designing classes to store different types of buildings and their location on the road. He

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 24
has created the following plan for some of the buildings:

Part of the declaration for the class building is shown.

Complete the pseudocode declaration by filling in the missing statements.

class building
private numberFloors
private width
private ………………………………………………………………………
public procedure new(pFloors, pWidth, pHeight)
numberFloors = ………………………………………………………………………
width = pWidth

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 25
height = pHeight
endprocedure
public function getNumberFloors()
return ………………………………………………………………………
endfunction
public function setNumberFloors(pFloors)
//sets the value of numberFloors when the parameter is >= 1
//returns true if numberFloors is successfully changed,
//returns false otherwise
if pFloors >= 1 then
numberFloors = ………………………………………………………………………
return true
else
return ………………………………………………………………………
endif
endfunction
endclass

(5 marks)

14 Christoff is writing a program to simulate a city using object-oriented programming. He is


designing classes to store different types of buildings and their location on the road. He

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 26
has created the following plan for some of the buildings:

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.

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 27
(6 marks)

15 Christoff is writing a program to simulate a city using object-oriented programming. He is


designing classes to store different types of buildings and their location on the road. He

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 28
has created the following plan for some of the buildings:

Christoff develops a new class to store the houses in one road.

His class design is shown:

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 29
class : houseRoad

attributes:

private buildings(100) //array of class house

private numberBuildings //records the number of houses currently stored in the array buildings

methods:

new(building)

function getBuilding(buildingNum)

procedure newbuilding(pBuilding)

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 marks)

16 Christoff is writing a program to simulate a city using object-oriented programming. He is


designing classes to store different types of buildings and their location on the road. He

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 30
has created the following plan for some of the buildings:

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.

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 31
(4 marks)

17 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.

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

01 procedure printLinkedList(headPointer)
02 tempPointer = headPointer - 1
03 dataToPrint = ″″
04 if tempPointer == -1 then
05 print(″List is full″)
06 else
07 while linkedList[pointer].getPointer() != -1
08 dataToPrint = dataToPrint + ″ ″ + linkedList[tempPointer,0]
09 linkedList[tempPointer].getPointer() = tempPointer
10 endwhile
11 print(dataToPrint + ″ ″ + linkedList[tempPointer].getData()
12 endif
13 endprocedure
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.

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 32
(6 marks)

18 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.

01 function checkWon(puzzle)
02 for row = 0 to 4
03 for column = 0 to 4
04 if puzzle[row, column] == answerGrid[row, column] then
05 return false
06 endif
07 next column
08 next column
09 return true
10 endfunction
There are three logic errors in the function checkWon.

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

(3 marks)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 33
Hard Questions
1 A class, Board, is used to store a 10 row (x coordinate) by 20 column (y coordinate) grid

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

class: Board

attributes:
private grid : Array of Treasure

methods:
new()
function getGridItem(x, y)
function setGridItem(x, y, treasureToInsert)

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.

public procedure new()


for row = ............................. to 9
for column = 0 to .............................
............ [row, column] = new Treasure(...........,"")
next .............................
next row
endprocedure

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 34
(5 marks)

2 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 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 marks)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 35
3 The recursive function thisFunction().

01 function thisFunction(theArray, num1, num2, num3)


02 result = num1 + ((num2 - num1) DIV 2)
03 if num2 < num1 then
04 return -1
05 else
06 if theArray[result] < num3 then
07 return thisFunction(theArray, result + 1, num2, num3)
08 elseif theArray[result] > num3 then
09 return thisFunction(theArray, num1, result - 1, num3)
10 else
11 return result
12 endif
13 endif
14 endfunction
Rewrite the function thisFunction() so that it uses iteration instead of recursion.

You should write your answer using pseudocode or program code.

(6 marks)

4 A recursive pseudocode function, recursiveAlgorithm(), is shown.

01 function recursiveAlgorithm(value)
02 if value <= 0 then
03 return 1
04 elseif value MOD 2 = 0 then
05 return value + recursiveAlgorithm(value – 3)
06 else
07 return value + recursiveAlgorithm(value – 1)
08 endif
09 endfunction

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 36
Trace the recursive function, recursiveAlgorithm(), and give the final return value when
called with recursiveAlgorithm(10).

You may choose to use the table below to give your answer.

Function call value return

recursiveAlgorithm(10)

(5 marks)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 37
5 Octal is a base 8 number system

To convert a denary number to base 8:

the denary value is divided by 8 and the remainder is stored

the integer value after division is divided by 8 repeatedly until 0 is reached

the remainders are then displayed in reverse order.

Example 1:
Denary 38
38 / 8 = 4 remainder 6 6
4 / 8 = 0 remainder 4 4
Octal = 46

Example 2:
Denary 57
57 / 8 = 7 remainder 1 1
7 / 8 = 0 remainder 7 7
Octal = 71

Write an algorithm to:

take a denary value as input from the user

convert the number to octal

output the octal value.

You do not need to validate the input from the user.

Write your algorithm using pseudocode or program code.

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 38
(6 marks)

6 A 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

class: Treasure

attributes:
private value : integer
private level : string

methods:
new()
function getValue()
function getLevel()

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.

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 39
(5 marks)

7 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.

class: Board

attributes:

private grid : Array of Treasure

methods:

new() function getGridItem(x, y) function setGridItem(x, y, treasureToInsert)

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.

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 40
(9 marks)

8 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.

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

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 41
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.

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 marks)

9 Anna currently writes her program code in a text editor and then runs the compiler.

She has been told that using an Integrated Development Environment (IDE) would be
more helpful.

Discuss the benefits of Anna using an IDE to write and test her program rather than
using a text editor.

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 42
(9 marks)

10 A doCheck() function takes an integer value as a parameter, carries out a series of


calculations and returns an integer value.

The function is shown here.

function doCheck(number)
temp = str(number)
max = temp.length – 1
total = 0
for x = 0 to max
total = total + int(temp.subString(x,1))
next x
return total MOD 10
endfunction
Write an algorithm that will:

allow the user to enter an integer value

pass the value entered into the doCheck() function as a parameter

store both the value input and the value returned from the function in a text file
with name "storedvalues.txt"

You should write your algorithm using either pseudocode or program code.

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 43
(5 marks)

© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 44

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy