7 1 Programming Techniques 3mtdyhh8JvDrfQ3K
7 1 Programming Techniques 3mtdyhh8JvDrfQ3K
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
© 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
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.
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.
(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
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.
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
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)
(1 mark)
(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:
The pseudocode function useWords() here uses the global array words.
contents = ""
next count
return contents
endfunction
Identify two variables in the function useWords().
(2 marks)
(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)
(2 marks)
12 A program uses the recursive function calculate(). The function is written in pseudocode.
(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 mark)
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:
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.
02 count = 0
04 for i = 0 to ……………………………………………
06 count = count + 1
09 count = 0
10 endif
11 next i
12 if count>= 1 then
13 output=output+str(count)
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)
(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
(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.
04 return -1
05 else
10 else
11 return result
12 endif
13 endif
14 endfunction
The function DIV calculates integer division, e.g. 5 DIV 3 = 1
(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)
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.
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 17
(3 marks)
Complete the table by identifying and describing three IDE features that can help the
programmer to develop, or debug a program.
(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 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()
(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.
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.
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:
Rewrite the function useWords() to use a while loop instead of a for loop.
The function header and close have been written for you.
(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.
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.
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.
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 23
(2 marks)
calculate(5)
You may choose to use the table below to give your answer
calculate(5)
(5 marks)
© 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:
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)
© 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:
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 27
(6 marks)
© 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:
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 29
class : houseRoad
attributes:
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.
(4 marks)
© 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).
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.
© 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():
accepts the row (x) and column (y) coordinates from the user
if there is treasure at that coordinate, it outputs the level and the value of the
treasure in an appropriate message.
(7 marks)
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 35
3 The recursive function thisFunction().
(6 marks)
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.
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
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
© 2025 Save My Exams, Ltd. Get more and ace your exams at savemyexams.com 38
(6 marks)
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.
You should define the attributes and constructor method in your answer.
© 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:
methods:
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.
© 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.
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)
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:
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