Chap 7 Question Paper
Chap 7 Question Paper
3$*(
&+$37(5
3$*(
3$*(
10
............................................................................................................................................. [1]
...................................................................................................................................................
...................................................................................................................................................
...........................................
.........................................................................................................
...................................................................................................................................................
.......................................
................................................................................................................
...................................................................................................................................................
...........................
............................................................................................................................
...................................................................................................................................................
..
.......
................
. .....
.........................................
.......................
....................
..........
. ..............
....
......
......
.....................
................................................................................................................................................... . ......
................
.....
.....
...................................................................................................................................................
...................................................................................................................................................
......
....................
.......................................................................................................................... [2]
.............................................................................................................................................
Value OUTPUT
[3]
11
[5]
© UCLES 2019 2210/21/M/J/19 [Turn over
3$*(
Section B
2 (a) An algorithm has been written in pseudocode to input 100 numbers, select and print the
largest number and smallest number.
Count 1
INPUT Number
High Number
Low Count
REPEAT
INPUT Number
IF Number > High
THEN
High Number
ENDIF
IF Number > Low
THEN
Low Number
ENDIF
Count Count + 1
UNTIL Count > 99
PRINT "Largest
"Largeest
s Number is ", Number
PRINT "Smallest
"Sma
mall
ma ll
lest Number is ", Low
Erro
Er rorr 1 ..
ro
Error ........
. .....
.........................................
.........
. ............
....................
.........
. ..............
....
......
......
......
.......................................
........................................................................................................................................
Cor
rrectiion
rrec
rr o ..................................................................................................................................
Correction ...................................................................................................................................
......
................
. ....
................................................................................................................................
...................................................................................................................................................
Error 2 ................................
..........................................................................................................
........................................................................................................................................
Correction ..........................
........................................................................................................
.................................................................................................................................
...................................................................................................................................................
Error 3 ........................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 4 ........................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
[4]
(b) Show how you would change the corrected algorithm to total the numbers and print the total.
Use a variable Total.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [4]
10
3 This flowchart inputs the marks gained in an examination. An input of –1 ends the routine.
START
Total 0
Count 0
Distinction 0
INPUT Mark
Is Mark = –1 ? Yes
Total Total + Mark
Count Count + 1
No
No
o Is OUTPUT "Number of
Mark
M k >=
ark >= Dist
Di tinct
ctio
ions
Distinctions s ",
", Distinction
Dis
Di sti
inct
c ion
0?
80 OUT
OUTPUT
UT "Average
OUTPUT "Av
Aveerag
age
e Mark
Mark
rk "
Total/Count
Yes
Ye
es
Di
Distinction
n Distinction
Distinction + 1 END
[4]
© UCLES 2019 2210/22/M/J/19
3$*(
11
4 For each of the fourr groups of statements in the table, place a tick in the correct column to show
whether it is an example of Selection or Repetition.
Valida
atitio
Validationon ..........................................................................................................................................
............
.......................................................................................................................................
...........
............
..........
. ..
. .......
...........................................................................................................................
..........................................................................................................................................................
...........
...
. ...........
..............................
.. ..........................................................................................................
..........................................................................................................................................................
....................................................
.......................................................................................................
..........................................................................................................................................................
Example .....................................
........................................................................................................
...........................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Verification ........................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Example ...........................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
[6]
Section B
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.
Number RandInt(100)
TotalTry 1
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
TotalTry Guess + 1
UNTIL Guess <>> Number
TotalTry TotalTry
Tot
talTry - 1
PRINT "Number
"Numbeer of
of guesses ", TotalTry
Error 1 ...............................................................................................................................................
...................
..........................
. ...........
....................
.. . ...............
.......
.........
.....
. ...............................
. ....
. ......
. ......
................
Correcti
ion
on ..
Correction .............................................................................................................................................
.........................................................................................................................................
...........................................................................................................................................................
...............
. ..........
....
......................................................................................................................................
Error 2 ......................................
..........................................................................................................
..............................................................................................................................................
Correction ...................................
........................................................................................................
.........................................................................................................................................
..........................................................................................................................................................
Error 3 ..............................................................................................................................................
Correction .........................................................................................................................................
..........................................................................................................................................................
Error 4 ..............................................................................................................................................
Correction .........................................................................................................................................
..........................................................................................................................................................
[4]
3 (a) The flowchart checks the lengths of a batch of 10 ropes. For the batch to be accepted 90% of
the lengths need to be between 24.9 and 25.1 metres.
START
Reject 0
Count 0
Yes
Is Count =
10 ?
No
No
Count Count + 1 Is Reject
<= 1 ?
INPUT Length
Yes
OUTPUT "Batch
rejected"
Yes Is Length
Lengt
g h <
gt
25.1
5.1 AND
25 AND
Lengthh > 24.9
th 24.9?
4.9
No
Reject Reject + 1
OUTPUT "Batch
accepted"
END
24.88, 25.01, 24.98, 25.00, 25.05, 24.99, 24.97, 25.04, 25.19, 25.07
[4]
(b) (i) It h
has been
as been
ee n decided to
ooonly
nly reject batches of rope that contain ropes that are too short.
Sttat
ate
Statee the
the change
cha
change required
requ
uired to the algorithm.
...........................................................................................................................................
...
.............................................................................................................................................
.....................................................................................................................................
................................................................................................. [1]
.....................................
(ii) algorith
th
hm to reject batches could be improved to make it more effective.
Explain how the algorithm
...........................................................................................................................................
...........................................................................................................................................
...........................................................................................................................................
..................................................................................................................................... [2]
10
Explain, including
inc
ncludi
ludi
dinng examples
ng examples
xa programming statements, how totalling and counting could be used
of programming
in this program.
prog
prog
ogra
graam.
To
ota
tallling
Totallingg ..
.........
....
.........
.................................................................................................................................
.............................................................................................................................................
..................................................
..........................................................................................................
..........................................................................................................................................................
...................................................
........................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
Counting ...........................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
[4]
10
DIV means integer division, so only the whole number part of the result is returned
e.g. 7 DIV 2 returns a value of 3
First 0
Last 16
Found FALSE
INPUT UserIn
WHILE (First <= Last) AND (Found = FALSE) DO
Middle (First + Last) DIV 2
IF MyData[Middle] = UserIn
THEN
Found TRUE
ELSE
IF UserIn < MyData[Middle]
THEN
Last Middle - 1
ELSE
First Middle + 1
ENDIF
ENDIF
ENDWHILE
OUTPUT Found
This table
ble sshows
tab
ab h ws
ho ws tthe
he ccontents
ontents of
of the
eaarray:
rray:
rra a a e.g.
ay: MyData
MyDat
yDat e.g. MyD
yDat
ata[
at 2] stores
g. MyData[2]
a[2] oress tthe
stor he vvalue
a ue 5
al
MyData
Index [0]
[0] [1]
[1] [2]
[1 [2] [3]
[3] [4] [5]
5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16]
[5
Value 2 3 5 6 8 10 0 12
12 13 14 16 18 20 25 27 29 34 36
[6]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
© UCLES 2019 2210/23/O/N/19
3$*(
11
6 Draw fourr different flowchart symbols and describe how they are used in a program flowchart.
[4]
Section B
2 Tick (9) one box in each row to identify if the statement about structure diagrams is true or false.
True False
Statement
(9) (9)
A structure diagram is a piece of code that is available throughout the
structure of a program.
A structure diagram shows the hierarchy of a system.
3 Programs can perform validation and verification checks when data is entered.
Check 1 .................
......
.... .............
.........................................................................................................
.....................................................................................................................................
Purp
rpos
rp osse ....
Purpose ....
....
. ........................
.............
........
. ....
..............
.........................
.............................
. ...................................
.....................................................................................................................................
.......
...................................................................................................................................................
...................................................................................................................................................
....................................................................................................................................................
...........
....
. ...........................................................................................................................................
Ch
hecck 2 .............................
Check ..........................................................................................................
.....................................................................................................................................
Purpose ..............................
........................................................................................................
.....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[4]
............................................................................................................................................. [1]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
4 The pseudocode algorithm shown should allow numbers to be entered and should allow
50 numbers to be stored in an array.
Count 0 ĸ
REPEAT
INPUT Values[Count]
Count Count + 1 ĸ
UNTIL Count = 0
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
...........................
........
....
.....................................................................................................................
...................................................................................................................................................
..
....
...................
. ....
................................................
. ...............................
.........
. ..............
....
...........
.....................
................................................................................................................................................... . ......
................
.....
...
. ...................................................................................................................................................
...................................................................................................................................................
......
................
. ....
................................................................................................................................
...................................................................................................................................................
...........................................
..........................................................................................................
...................................................................................................................................................
.............................................
........................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [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]
10
The predefined function DIV gives the value of the result of integer division,
for example, y ĸ 9 DIV 4 gives y a value of 2
START
INPUT
Value
IS Yes
Value =
-1 ?
No
Calc1
Calc
lc1 Value DIV 2
Calc2
Calc
lc2
lc Value DIV 3
IS
No Calc1 =
Value / 2 ?
Yes
IS
No Calc2 =
Value / 3 ?
Yes
OUTPUT
Value
END
11
[4]
...
........................
. ...............................................................................................................................
...................................................................................................................................................
....
........
.. ...
. ..........
. ..................................................................................................................................
...................................................................................................................................................
.........
...
...........
............................................................................................................................... [2]
.............................................................................................................................................
3 (a) An algorithm has been written in pseudocode to input the names and marks of 35 students.
The algorithm stores the names and marks in two arrays Name[ ] and Mark[ ]. The highest
mark awarded is found and the number of students with that mark is counted. Both of these
values are output.
01 HighestMark 100 ĸ
02 HighestMarkStudents 0 ĸ
03 FOR Count ĸ
1 TO 35
04 OUTPUT "Please enter student name"
05 INPUT Name[Count]
06 OUTPUT "Please enter student mark"
07 INPUT Mark[Counter]
08 IF Mark[Count] = HighestMark
09 THEN
10 HighestMarkStudents HighestMarkStudents – 1 ĸ
11 ENDIF
12 IF Mark[Count] > HighestMark
13 THEN
14 Mark[Count] HighestMark ĸ
15 HighestMarkStudents 1 ĸ
16 ENDIF
17 NEXT Count
18 Hig
i hestMarkStudents," with the highest mark of ",
OUTPUT "There are ", HighestMarkStudents,"
HighestMark
lin
Give linene numbers
numb
num er
mb e s where
where the
the fo
four
urr err
rro
rrors are
errors are to be
be found
f und in
fo n the
the pseudocode.
pse
seudoccod
ode. Suggest
Sug
uggest a
corr
correc
rre tition
ec
correctionon
on for
for each
eac
achh error.
Erro
ro
or 1 lilline
Error ine
n n umbe
um b r ...........
be
number ..........................................................................................................
...................................................................................................................
C orr
rrrec
e ti
tion
Correction n .....
...............................................................................................................................
.................................................................................................................................
...........................................
..........................................................................................................
...................................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
[4]
(b) Explain how you could extend the algorithm to also find the lowest mark awarded, count the
number of students with that mark, and output both these values.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...........................................
.........................................................................................................
...................................................................................................................................................
.................................
.....................................................................................................................
...................................................................................................................................................
.............
........
....
....
....
. ...............................................
.. . ........................................................................
. ............
................................................................................................................................................... ................
........
.........
...........
.. . ..............................................................................................................................
...................................................................................................................................................
....................................................................................................................................................
......
.. .....................
. ..................................................................................................................................
.....
...
....
. ..
.. ....
..........................................................................................................................................
...................................................................................................................................................
.............................................
.......................................................................................................
...................................................................................................................................................
.............................................
........................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [6]
© UCLES 2020 2210/22/M/J/20 [Turn over
3$*(
10
4 This flowchart inputs the points won and the points lost when playing a game. The difference
between the points won and lost is calculated and depending on the result the player can: move
up to the next level, stay at the same level, or move down to the previous level. The flowchart
finishes when the input for points won is –1.
START
INPUT
PointsWon, PointsLost
IS
Yes END
PointsWon = –1 ?
No
Difference
PointsWon - PointsLost
OUTPUT
OUTP
OUTPUT
TP T IS
Yes
Ye
es
"Wel
"Well
el
"Welll done
done Difference > =
moove
ve up"
move up" 1000 ?
No
OUTPUT Yes IS
"Sorry move Difference < 0 ?
down"
No
OUTPUT
"Keep on trying"
11
[3]
(b) The flowchart needs to be changed. When the difference is more than 5000 the output
message is ‘Fantastic leap up two levels’.
....................................
..................................................................................................................
....
...................................................................................................................................................
.........................
........
.........................
....
. ..
.........................
... ............
....
....
. .................
........
......
................
. .........
................................................................................................................................................... ................
..
..........................................................................................................................................................
...................................................................................................................................................
.....
...
............................
..........................................................................................................................
...................................................................................................................................................
.....
.....
....
.......
..........................................................................................................................................
...................................................................................................................................................
...........................................
..........................................................................................................
...................................................................................................................................................
.............................................
........................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]
2 Describe the purpose of validation and verification checks during data entry.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
[4]
3 Tick (9) one box to show the named section of a program that performs a specific task.
A file
B function
C parameter
D process
[1]
[4]
5 An algorithm has been written in pseudocode to input some numbers. It only outputs any numbers
that are greater than or equal to 100. The number 999 is not output and stops the algorithm.
INPUT Number
WHILE Numbers <> 999 DO
IF Number > 100
THEN
OUTPUT Number
ENDIF
ENDWHILE
OUTPUT Number
(a) Identify the fourr errors in the pseudocode and suggest corrections.
Error 1 .......................................................................................................................................
Correction .................................................................................................................................
...................................................................................................................................................
Error 2 ...............................
.........................................................................................................
.......................................................................................................................................
Correction ....................
.........
.........................................................................................................
.................................................................................................................................
...........................
.............................................................................................................................
...................................................................................................................................................
Erro
Er ror 3 ........................................................................................................................................
ro
Error ...........
........................................
.. ........................
....................
.. .........
.. ..............
......
. ..
.. .....
...... .............................
.. ................
Cor
rrec
rr ectiion
Correctiono ..
..................................................................................................................................
........
..............................................................................................................................
......
..............
.. .......................................................................................................................................
...................................................................................................................................................
Error 4 ...............................
..........................................................................................................
.......................................................................................................................................
Correction ..........................
........................................................................................................
.................................................................................................................................
...................................................................................................................................................
[4]
(b) Write a pseudocode statement to change the corrected algorithm to output all numbers
between 100 and 200 inclusive.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]
START
Flag m 0
Count m 1
IS Name[Count] Yes
> Name[Count + 1]? Temp m Name[Count]
No Name[Count] m Name[Count + 1]
Name[Count + 1] m Temp
Flag
Fl
F lag
g m 1
Count
Co
Couun
nt m Count
t + 1
No IS Count
=4?
Yes
No IS Flag
=0?
Yes
STOP
(a) The array Name[1:4] used in the flowchart contains the following data:
Complete the trace table using the data given in the array.
[5]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [2]