2.2.1 Programming Techniques
2.2.1 Programming Techniques
The interest rate is currently 10% but it may change in the future.
José writes the following program to calculate the monthly payment for a loan.
[1]
[2]
[2]
(ii) State the names of the two parameters of the procedure ReceiveMessage. For each parameter, state the
most appropriate data type.
[3]
[2]
(b). 0 is an evil number.
Describe each step of the execution of the call IsEvil(0), showing that it returns the value TRUE.
[3]
(c). Using the trace table below, show what happens in the execution of the call IsEvil(2), showing that 2 is not an
evil number.
You should use a new row in the table for every line that is executed, and show any values that are changed
during the execution of that line. Yo u may not need every row in the table. The first two rows have been filled in
for you.
01 2 Call IsEvil(2)
[6]
All numbers that are not evil are known as odious numbers.
[2]
(ii) The same variable name may be used in more than one procedure in a program.
Explain how a variable named result may be used in different procedures without causing errors.
[2]
[5]
[4]
(ii) State two features of global variables that distinguish them from local variables.
[2]
[2]
(ii) Explain what is meant by ‘scope’ in relation to global and local variables.
[2]
Hourly rate.
Hours worked.
Tax paid.
National Insurance paid.
Explain the term ‘scope’ in relation to variables within a program that calls several different procedures.
[6]
Construct 1: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Example: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Construct 2: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Example: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Construct 3: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Example: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[6]
Explain why this program outputs Sam rather than Hello Sam.
[2]
(b). Explain the advantages of writing an application using a modular approach.
[6]
In the game, the player controls a character who moves through a virtual world. The game starts with a load-up
screen. The player can select which area to move to on an on-screen map, and then they control the movements
of their character using a keyboard to solve puzzles on the screen.
The following pseudocode algorithm is for the sub-procedure of the game created characterMovement.
[3]
(ii) Describe the decision that is made in this procedure and how the decision affects the flow through the
procedure.
(iii) Explain why characterx and charactery are passed byRef and not byVal.
[3]
Identify three features of an IDE that the programmer would use when writing the code and describe how the
features benefit the programmer.
[6]
[4]
[1]
[1]
Part of the array, numStack, is shown when one number has been input.
index stackItem
9
8
7
6
top 1 5
4
3
2
1
0 20
The pointer, top, points to the next free space in the stack.
A function, addItem, takes a number as a parameter and adds the number to the stack. The function returns
true if this was successful, and false if the stack is already full.
(i) Give one reason why a function is used instead of a procedure in this scenario.
[1]
By value
[4]
(iv) The procedure, calculate, takes each item in turn from the stack. It alternately adds then subtracts the
numbers until there are none left.
Complete the trace table for the procedure calculate. The current array and pointer values when the
procedure is called are on the first line of the trace table.
numstak
top 0 1 2 3 4 5 total add output
5 20 2 6 12 8
[6]
Fig. 1
A computer program is required to keep track of the scores for each competition. The user will enter the number
of players, and the name of each player, in that competition to a maximum of 10.
The program is decomposed into multiple sub-programs, that each perform a specific task.
Explain why the array scores has been declared as global instead of local.
[2]
Describe how the IDE could be used to create the Kidz Arrowz program.
[3]
Trace the algorithm to show the value returned when generate(7) is called. Show each step of your working.
[6]
[2]
(c). * Parameters can be used to reduce the use of global variables.
[6]
(b). Describe what is meant by the term IDE (Integrated Development Environment).
[2]
18. Describe one difference between a global and a local variable.
[2]
The managers of Nobugs enforce standard rules on their programmers about how program functions should be
written.
The following are some of the rules that they insist upon:
[2]
Describe how the programmers could make use of the following IDE tools:
Breakpoints _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Stepping _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
[4]
1 i *
has higher precedence than + 1 Allow follows rules of BODMAS / BIDMAS
Examiner's Comments
iii So the formula is calculated correctly 2 The 2nd bullet is worth two marks if that is
The * is done before the \ the only point made
Total 5
Total 5
b (line 02) Temp is set to TRUE 3 Do not accept code line i.e. Temp=TRUE
Condition in line 3 is false (so it skips
the loop) Examiner's Comments
in line 10, it returns TEMP (which was
set to TRUE) Many candidates lost the first point by
simply copying the Temp = true line from
the given algorithm.
Examiner's Comments
Total 11
Total 9
5 i Defined within one module… 4 For module allow procedure / function / sub
… accessible only in that module / Any routine / block of code
mention of scope
Can be used as parameters Examiner's Comments
Data is lost at end of module
Same variable name can be used in Well answered by most candidates.
other modules without overwriting
values/causing errors
Can overwrite global variables (with the
same name)
Total 6
Total 4
Total 6
Total 6
Total 8
10 i 1 mark for each parameter – case sensitive 3 No spaces allowed in parameter names
Examiner's Comment:
Most candidates had a good understanding
of what parameters were and could hence
answer the question well.
Examiner's Comment:
ByRef and ByVal continue to be an area
that candidates struggle with. Those with
experience of languages that implement
this tended to do better.
Total 9
11 1 mark for feature, 1 for benefit. Max 2 per 6 Question states when writing the code,
feature. AO1.1 therefore use of compiler / producing .exe
e.g. (3) etc. are not awarded marks
AO1.2
Auto-complete (3) Accept any suitable features e.g. traces,
crash dump, stack contents, cross-
Can view identifiers / avoid spelling references, line numbers, auto-indent
mistakes
Stepping
Breakpoints
Error diagnostics
Total 6
Examiner’s Comment:
Many candidates struggled to produce
good answers which could have been
calculated and did not require factual
recall.
Total 4
13 a Iteration [1] 1
AO2.1
(1)
Examiner's Comment:
Well answered by most candidates.
Examiner's Comment:
A number of candidates clearly did not
appreciate how functions differ from
procedures.
Total 2
Total 16
Total 5
0 marks
No attempt to answer the question or
response is not worthy of credit.
Total 17
17 a Debugging tools allow inspection of 6 1 mark (AO 1.1) for each correct
variable values (1 – AO 1.1) this can identification up to a maximum of three
allow run-time detection of errors (1 – identifications plus up to a further 1 mark
AO 1.2). (AO 1.2) for each of three valid
Code can be examined as it is running descriptions.
(1 – AO 1.1) which allows logical errors
to be pinpointed (1 – AO 1.2).
IDE debugging can produce a crash
dump (1 – AO 1.1), which shows the
state of variables at the point where an
error occurs (1 – AO 1.2).
It can display stack contents (1 – AO
1.1) which show the sequencing
through procedures / modules (1 – AO
1.2).
It can step through code (1 – AO 1.1),
which allows the programmer to watch
the effects each line of code (1 – AO
1.2).
The insertion of a break-point (1 – AO
1.1) allows the program to be stopped
at a predetermined point in order to
inspect its state (1 – AO 1.2).
Total 8
Total 2
Total 2
Stepping
Total 4