Programming – O Level Computer Science (2210)
174 questions · page 8 of 12 · Clear filters
Question text
5
A one-dimensional array dataArray[1:20] needs each element set to zero.
(a) Write a pseudocode routine that sets each element to zero. Use the most suitable loop
structure.
…
…
…
…
…
…
…
… [3]
(b) Explain why you chose this loop structure.
…
… [1]
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) (i)
Identify one array you could have used for Task 1 and state its purpose.
Array …
Purpose …
…
…
[2]
(ii)
Identify one variable you could have used for Task 2 and state its purpose.
Variable …
Purpose …
…
…
[2]
(iii)
Identify one constant you could have used for Task 3 and state its purpose.
Constant …
Purpose …
…
…
[2]
(b) Explain the benefits of storing Price as a real data type.
…
…
…
…
…
…
… [2]
(c) Write an algorithm to show how you completed Task 1, using either pseudocode,
programming statements or a flowchart. It is not necessary to show initialisation or setting up
of arrays in your answer.
…
…
…
…
…
Question text
2
Tick (3) one box in each row to identify if the statement about subroutines is true or false.
true
false
Statement
(3)
(3)
A subroutine is called from within a program.
A subroutine is not a complete program.
A subroutine is a self-contained piece of code.
A subroutine must return a value to the code from which it was called.
[2]
Question text
4
This pseudocode algorithm allows 5000 numbers to be entered and stored in an array called
Number.
1 TO 5000
FOR Count
INPUT Number[Count]
NEXT Count
Extend and re-write the algorithm using pseudocode to also count and output how many of the
numbers stored in the array are greater than 500, using the variable Higher. Only output Higher
once with an appropriate message.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]
Question text
5
This pseudocode represents an algorithm.
REPEAT
0
Flag
0 to 3
FOR Count
IF Num[Count] < Num[Count + 1]
THEN
Num[Count]
Store
Num[Count + 1]
Num[Count]
Store
Num[Count + 1]
1
Flag
ENDIF
NEXT Count
UNTIL Flag = 0
(a) The contents of the array at the start of the algorithm are:
Num[0]
Num[1]
Num[2]
Num[3]
Num[4]
45
56
30
12
15
Complete the trace table for the algorithm using the data given in the array.
Flag
Count
Num[0]
Num[1]
Num[2]
Num[3]
Num[4]
Store
45
56
30
12
15
[5]
(b) Describe the purpose of the algorithm.
…
…
…
… [2]
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) Identify one constant and identify one variable that you could have used for Task 1. Give the
value that would be assigned to the constant. Give the data type for the variable. State what
each one could be used for.
Constant …
Value …
Use …
…
Variable …
Data type …
Use …
…
[6]
(b) (i)
Write an algorithm to allow a customer to choose the filling and salad items for their
baguette (part of Task 1), using either pseudocode, programming statements or a
flowchart. Your algorithm must only include this part of Task 1.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
2
An algorithm has been written in pseudocode to check the temperature readings taken from a
freezer are within the range –18 degrees to –25 degrees inclusive.
The algorithm counts the number of times that the temperature reading is below –25 degrees and
the number of times that the temperature reading is above –18 degrees.
An engineer is called if there are more than 10 temperature readings below –25 degrees.
An alarm sounds if there are more than 5 temperature readings above –18 degrees.
0
01
TooHot
1000
02
TooCold
03
REPEAT
04
OUTPUT "Please enter temperature"
05
INPUT Temperature
06
IF Temperature < -25
07
THEN
TooCold – 1
08
TooCold
09
ENDIF
10
IF Temperature > -18
11
THEN
TooHot + 1
12
TooHot
13
ENDIF
14
UNTIL TooHot > 5 OR TooCold > 10
15
IF TooHot < 5
16
THEN
17
INPUT "Alarm!!"
18
ENDIF
19
IF TooCold > 10
20
THEN
21
OUTPUT "Call the Engineer"
22
ENDIF
(a) Give the line number(s) from the algorithm of:
an assignment statement …
a loop …
a counting statement …
a selection statement …
[4]
(b) Give line numbers where the four errors are to be found in the pseudocode. Suggest a
correction for each error.
Error 1 line number …
Correction …
…
Error 2 line number …
Correction …
…
Error 3 line number …
Correction …
…
Error 4 line number …
Correction …
…
[4]
(c) Explain how you could extend the algorithm to count the number of times the temperature
readings are within the range –18 degrees to –25 degrees inclusive.
…
…
…
…
Question text
3
Four programming concepts and five descriptions are shown.
Draw a line to connect each Programming concept to its correct Description. Not all Descriptions
will be connected to a Programming concept.
Programming concept
Description
A subroutine that does not have to
Validation
return a value
An automatic check to ensure that data
input is reasonable and sensible
Verification
A subroutine that always returns
a value
Procedure
An overview of a program or subroutine
A check to ensure that data input
Function
matches the original
[4]
Question 4 starts on Page 12.
Question text
4
This flowchart represents an algorithm that allows the input of two numbers and performs a
calculation.
The predefined function MOD finds the remainder from integer division for example X
8 MOD 5
gives X a value of 3.
START
INPUT
Y,Z
Yes
IS
END
Y = 0 ?
No
Yes
IS
A
Y MOD Z
Y > Z ?
No
A
Z MOD Y
IS
Yes
OUTPUT
A = 0 ?
"Valid"
No
OUTPUT
"Invalid"
(a) Complete a trace table for this set of input data:
11, 4, 6, 2, 3, 9, 3, 2, 2, 6, 0, 0, 1, 1
Y
Z
A
OUTPUT
[4]
(b) Explain the purpose of this algorithm.
…
…
…
… [2]
Question text
1
All variables, constants and other identifiers must have meaningful names.
(a) (i)
Identify two arrays you could have used for Task 1 and, in each case, state its purpose.
Array 1 …
Purpose …
…
…
Array 2 …
Purpose …
…
…
[4]
(ii)
Identify two variables you could have used for Task 1 and, in each case, state its
purpose.
Variable 1 …
Purpose …
…
…
Variable 2 …
Purpose …
…
…
[4]
(b) Explain why the item code data could not be stored as a real data type and identify the most
suitable data type for the item code data.
…
…
…
…
…
… [2]
(c) Write an algorithm to show how you input your choice of mobile device and SIM card (part of
Task 1), using either pseudocode, programming statements or a flowchart. It is not necessary
to show initialisation or setting up of arrays containing product details.
…
…
Question text
4
The pseudocode algorithm shown should allow numbers to be entered and should allow
50 numbers to be stored in an array.
←
0
Count
REPEAT
INPUT Values[Count]
←
Count + 1
Count
UNTIL Count = 0
(a) Explain why the algorithm will never end.
…
…
…
…
… [2]
(b) Re-write the original pseudocode so that it terminates correctly and also prevents numbers
below 100 from being stored in the array Values[ ]
…
…
…
…
…
…
…
…
…
… [4]
(c) Describe how you could change your pseudocode in part (b) so that it prevents numbers
below 100 and above 200 from being stored in the array Values[ ]
…
…
…
… [2]
Question text
5
The flowchart represents an algorithm.
The predefined function DIV gives the value of the result of integer division,
←
9 DIV 4 gives y a value of 2
for example, y
An input value of –1 ends the algorithm.
START
INPUT
Value
IS
Yes
Value =
-1 ?
No
Calc1
Value DIV 2
Calc2
Value DIV 3
IS
No
Calc1 =
Value / 2 ?
Yes
IS
No
Calc2 =
Value / 3 ?
Yes
OUTPUT
Value
END
(a) Complete the trace table for the input data:
50, 33, 18, 15, 30, –1, 45, 12, 90, 6
Value
Calc1
Calc2
OUTPUT
[4]
(b) Describe the purpose of the algorithm.
…
…
… [2]
Question text
1
(a) All variables, constants and other identifiers must have meaningful names.
(i)
Describe the data structures that you have used to store the data for the concrete slabs
in Task 1, include the name, data type and use for each data structure.
…
…
…
…
…
…
…
…
…
…
… [5]
(ii)
State one variable that you have used in Task 3.
Give the data type for the variable. State what it is used for.
Variable name …
Data type …
Use …
…
[3]
(b) Explain how you calculated the volume of a concrete slab in Task 1.
…
…
…
…
…
… [3]
(c) Write an algorithm for Task 2, using either pseudocode, programming statements or a
flowchart. Assume that Task 1 has been completed.
…
…
…
Question text
2
An algorithm has been written in pseudocode to select a random number using the function
RandInt(n), which returns a whole number between 1 and the argument n. The algorithm then
allows the user to guess the number.
RandInt(100)
Number
1
TotalTry
REPEAT
PRINT "Enter your guess now, it must be a whole number"
INPUT Guess
IF TotalTry > Number
THEN
PRINT "Too large try again"
ENDIF
IF Guess > Number
THEN
PRINT "Too small try again"
ENDIF
Guess + 1
TotalTry
UNTIL Guess <> Number
TotalTry - 1
TotalTry
PRINT "Number of guesses ", TotalTry
Find the four errors in the pseudocode and suggest a correction to remove each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
[4]
Question text
5
A programmer writes a program to weigh baskets of fruit in grams, keeping a total of the weight
and counting the number of baskets. The total weight is stored in a variable Total and the number
of baskets is stored in a variable BasketCount.
Explain, including examples of programming statements, how totalling and counting could be used
in this program.
Totalling …
…
…
…
…
…
Counting …
…
…
…
…
…
[4]