Trace Table G 11
Trace Table G 11
Trace Table G 11
3 The global trade item number (GTIN-8) barcode has seven digits and a check digit.
This pseudocode algorithm inputs seven digits and calculates the eighth digit, then outputs the
GTIN-8.
DIV(X,Y), finds the number of divides in division for example DIV(23,10) is 2.
MOD(X,Y), finds the remainder in division for example MOD(23,10) is 3.
FOR Count 1 TO 7
INPUT Number
Digit(Count) Number
NEXT
Sum (Digit(1)+Digit(3)+Digit(5)+Digit(7))*3+Digit(2)+Digit(4)+Digit(6)
IF MOD(Sum,10) <> 0
THEN Digit(8) DIV(Sum,10)*10 + 10 - Sum
ELSE Digit(8) 0
ENDIF
OUTPUT "GTIN-8"
FOR Count 1 TO 8
OUTPUT Digit(Count)
NEXT
Digit(1) Digit(2) Digit(3) Digit(4) Digit(5) Digit(6) Digit(7) Digit(8) Sum OUTPUT
Digit(1) Digit(2) Digit(3) Digit(4) Digit(5) Digit(6) Digit(7) Digit(8) Sum OUTPUT
[5]
(b) Explain how you would change the algorithm to input eight digits (seven digits and the check
digit) and output if the check digit entered is correct or not.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [3]
May/June 2018 P-22
3 This pseudocode algorithm inputs two non-zero numbers and a sign, and then performs the
calculation shown by the sign. An input of zero for the first number terminates the process.
[3]
(b) Show how you could improve the algorithm written in pseudocode by writing an alternative
type of conditional statement in pseudocode.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
May/June 2017 P-21
6 This flowchart inputs a range of temperatures in degrees Fahrenheit.
As each temperature is input, it is compared with the previous highest temperature. If it is higher
than the current highest, it replaces the previous highest temperature and then it is converted to
degrees Celsius.
For ease of calculation, the final step of the Fahrenheit to Celsius conversion has been
approximated as division by 2.
When –1 is entered, the input process stops and the highest temperature (in both Fahrenheit and
Celsius) is output.
START
HighF -100
HighC -100
INPUT TempF
Is TempF No Is TempF No
= -1? > HighF?
Yes Yes
HighF TempF
HighC (TempF-32)/2
END
Complete the trace table for the input data:
[5]
May/June 2017 P-22
3 This flowchart inputs the weight of items in kilograms to be loaded on a trailer. Any item over
25 kilograms is rejected. The trailer can take up to 100 kilograms.
START
TotalWeight 0
Reject 0
INPUT Weight
Yes
Is Weight
Reject Reject + 1
˃ 25?
No
No Is
TotalWeight
˃ 100?
Yes
END
Complete the trace table for the input data:
[5]
OCT/NOV 2017 P-22
5 (a) This flowchart checks a batch of 10 rice sacks for weight. Sacks should weigh 50 kilograms
each. Sacks weighing over 50.5 kilograms or less than 49.5 kilograms are rejected. The
number of sacks accepted and the number of sacks rejected is output.
START
Accept 0
Reject 0
Count 0
Is Count Yes
= 10?
OUTPUT
Accept Accept + 1 Accept,
No
Reject
Count Count + 1
END
INPUT
Sack
No
Is Sack
No > 50.5? Yes
Complete the trace table for the input data:
50.4, 50.3, 49.1, 50.3, 50.0, 49.5, 50.2, 50.3, 50.5, 50.6
[5]
(b) The size of the batch has increased to 50 sacks. It has been decided to only reject sacks that
are underweight.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
OCT/NOV 2017 P-23
5 The flowchart below represents a program routine.
START
Flag 0
Count 1
Is Name[Count] Yes
> Name[Count + 1]? Temp Name[Count]
No Name[Count] Name[Count + 1]
Name[Count + 1] Temp
Flag 1
Count Count + 1
No Is Count
= 4?
Yes
No Is Flag
= 0?
Yes
END
(a) The array used in the flowchart contains the following data:
Complete the trace table using the data given in the array.
[5]
...................................................................................................................................................
...............................................................................................................................................[2]
May/June 2016 P-21
4 The flowchart below inputs the height of children who want to ride on a rollercoaster. Children
under 1.2 metres are rejected. The ride starts when eight children have been accepted.
67$57
5LGHUV
5HMHFW
,1387
+HLJKW
,V <HV
+HLJKW 5HMHFW5HMHFW
"
1R
5LGHUV5LGHUV
(1'
Complete the trace table for the input data:
1.4, 1.3, 1.1, 1.3, 1.0, 1.5, 1.2, 1.3, 1.4, 1.3, 0.9, 1.5, 1.6, 1.0
[4]
May/June 2016 P-22
3 The flowchart below calculates the number of tins of paint required to paint walls. The flowchart
inputs the height and width of a wall in metres, the number of doors and the number of windows.
A value of –1 for the height stops the input.
START
Area 0
Tins 0
INPUT Height,
Width, Doors,
Windows
Is Yes
Height Tins INT(Area/10 + 0.5)
= –1?
No
OUTPUT Tins
Area Area + Height * Width
– Doors * 1.5 – Windows
END
3, 5, 1, 0, 3, 7, 0, 0, 3, 5, 0, 3, 3, 7, 1, 1, –1, 0, 0, 0
[4]
OCT/NOV 2016 P-22
3 The flowchart below inputs an integer. The predefined function DIV gives the value of the division,
for example Z ← 11 DIV 3 gives the value Z = 3. The predefined function MOD gives the value
of the remainder, for example Z ← 11 MOD 3 gives the value Z = 2.
67$57
,1387;
1R
,V;!
"
<HV
$ ;',9
% ;02' 287387;
287387% (1'
; $
Complete a trace table for each of the two input values 33 and 75.
X A B OUTPUT
X A B OUTPUT
[4]
OCT/NOV 2016 P-23
3 The flowchart below inputs the price of an item under $10. The change from a $10 note is output.
Any amount less than 5 cents is rounded up to 5 cents.
The predefined function INT rounds a number down to the nearest whole number; for example
Z ← INT(5.7) gives the value Z = 5
START
INPUT Price
Change 10 – Price
Is
Change Yes Dollars INT(Change)
>= 1?
OUTPUT Dollars,
" dollars"
Is
Change Yes
Change Change – 0.5
>= 0.5?
No OUTPUT "One 50
cent coin"
OUTPUT TenCents,
" ten cent coins"
No
END
Complete the trace table for the input data: 6.29
[5]
May/June 2015 P-21
3 The flowchart below inputs the weight of a number of parcels in kilograms. Parcels weighing more
than 25 kilograms are rejected. A value of –1 stops the input.
The following information is output: the total weight of the parcels accepted and number of parcels
rejected.
START
7RWDOĸ
5HMHFWĸ
INPUT
Weight
No END
Is Weight Yes
5HMHFWĸ5HMHFW
> 25?
No
7RWDOĸ7RWDO:HLJKW
Complete the trace table for the input data:
1.8, 26.0, 7.0, 11.3, 10.0, 2.5, 25.2, 5.0, 19.8, 29.3, –1
[5]
May/June 2015 P-22
3 (a) The flowchart below inputs six single digit numbers. The predefined function MOD gives the
value of the remainder, for example, Y ← 10 MOD 3 gives the value Y = 1
START
INPUT
A, B, C, D, E, F
No
OUTPUT
'Reject'
END
Complete a trace table for each of the two sets of input data.
Set 1 5, 2, 4, 3, 1, 5
Set 2 3, 2, 1, 0, 7, 3
[4]
(b) State the purpose of the flowchart in part (a).
...................................................................................................................................................
...............................................................................................................................................[1]
(c) Identify a problem with this flowchart and explain how to correct it.
Problem ....................................................................................................................................
...................................................................................................................................................
Solution .....................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
OCT/NOV 2015 P-22
3 (a) The flowchart inputs an integer. The predefined function DIV gives the integer result of the
division, e.g. Y 10 DIV 3 gives the value Y = 3. The predefined function MOD gives the
value of the remainder, e.g. Y 10 MOD 3 gives the value Y = 1.
START
Posn @ 1
New @ 0
INPUT X
T1 @ X DIV 2
T2 @ X MOD 2
New @New+T2 * Posn
Posn @Posn * 10
X @T1
Yes is T1
>= 2?
No
OUTPUT New
END
Complete a trace table for each of the two input values 5 and 12.
[6]
...............................................................................................................................................[1]
OCT/NOV 2015 P-23
3 (a) This pseudocode inputs an integer. The predefined function DIV gives the value of the
division, e.g. Y 10 DIV 3 gives the value Y = 3. The predefined function MOD gives the
value of the remainder, e.g. Y 10 MOD 3 gives the value Y = 1.
INPUT X
WHILE X > 15
DO
T1 X DIV 16
T2 X MOD 16
CASE T2 OF
10:OUTPUT A
11:OUTPUT B
12:OUTPUT C
13:OUTPUT D
14:OUTPUT E
15:OUTPUT F
OTHERWISE OUTPUT T2
ENDCASE
X T1
ENDWHILE
CASE X OF
10:OUTPUT A
11:OUTPUT B
12:OUTPUT C
13:OUTPUT D
14:OUTPUT E
15:OUTPUT F
OTHERWISE OUTPUT X
ENDCASE
Complete a trace table for each of the two input values 37 and 191.
Trace table for input value 37
X T1 T2 OUTPUT
X T1 T2 OUTPUT
[4]
(b) State the purpose of the pseudocode in part (a).
...................................................................................................................................................
...............................................................................................................................................[2]
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
IS Yes
Y = 0? END
No
IS Yes
Y > Z? A Y MOD Z
No
A Z MOD Y
OUTPUT Yes IS
"Valid" A = 0?
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]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
5 This pseudocode represents an algorithm.
REPEAT
Flag 0
FOR Count 0 to 3
IF Num[Count] < Num[Count + 1]
THEN
Store Num[Count]
Num[Count] Num[Count + 1]
Num[Count + 1] Store
Flag 1
ENDIF
NEXT Count
UNTIL Flag = 0
(a) The contents of the array at the start of the algorithm are:
Complete the trace table for the algorithm using the data given in the array.
[5]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
4 This algorithm checks passwords.
• Each password must be 8 or more characters in length; the predefined function Length
returns the number of characters.
• Each password is entered twice, and the two entries must match.
• Either Accept or Reject is output.
• An input of 999 stops the process.
REPEAT
OUTPUT "Please enter password"
INPUT Password
IF Length(Password) >= 8
THEN
INPUT PasswordRepeat
IF Password <> PasswordRepeat
THEN
OUTPUT "Reject"
ELSE
OUTPUT "Accept"
ENDIF
ELSE
OUTPUT "Reject"
ENDIF
UNTIL Password = 999
(a) Complete the trace table for the algorithm using this input data:
Secret, Secret, VerySecret, VerySecret, Pa55word, Pa55word, 999, 888
[3]
(b) Explain how the algorithm could be extended to allow three attempts at inputting the matching
password. Any pseudocode statements used in your answer must be fully explained.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................ [4]
4 This algorithm checks the temperature of hot food being served to customers.
Error
START
Counter 0
Hot 0
Cold 0
Serve 0
INPUT Temp
No
Counter No
Counter + 1 OUTPUT
Error
Is Temp Yes
Cold Cold + 1
< 63?
No
OUTPUT
Serve Serve + 1 "Too Cold"
END
(a) Complete the trace table for the algorithm using this input data:
75, 78, 84, 87, 91, 80, 75, 70, 65, 62, –1, 20
[7]
(b) State how the final output from the algorithm could be improved.
...................................................................................................................................................
............................................................................................................................................. [1]
...................................................................................................................................................
............................................................................................................................................. [1]
5 The pseudocode represents an algorithm.
The pre-defined function DIV gives the value of the result of integer division.
For example, Y = 9 DIV 4 gives the value Y = 2
The pre-defined function MOD gives the value of the remainder of integer division.
For example, R = 9 MOD 4 gives the value R = 1
First ← 0
Last ← 0
INPUT Limit
FOR Counter ←1 TO Limit
INPUT Value
IF Value >= 100
THEN
IF Value < 1000
THEN
First ←Value DIV 100
Last ←
Value MOD 10
IF First = Last
THEN
OUTPUT Value
ENDIF
ENDIF
ENDIF
NEXT Counter
(a) Complete the trace table for the algorithm using this input data:
[5]
7 The flowchart represents an algorithm.
START
Pointer 1
INPUT
Letter
IS No
Word[Pointer, 1] Pointer Pointer + 1
= Letter ?
Yes
INPUT Choice
Yes IS No
Choice = STOP
'Y' ?
The table represents the two-dimensional (2D) array Word[] which stores the first half of the
phonetic alphabet used for radio transmission. For example, Word[10,1] is ‘J’.
Index 1 2
1 A Alpha
2 B Bravo
3 C Charlie
4 D Delta
5 E Echo
6 F Foxtrot
7 G Golf
8 H Hotel
9 I India
10 J Juliet
11 K Kilo
12 L Lima
13 M Mike
(a) Complete the trace table for the algorithm by using the input data: F, Y, D, N
[4]
9 This flowchart represents an algorithm.
START
F 0
C 1
IS X[C] < No
T X[C]
X[C + 1]?
Yes
X[C] X[C + 1]
X[C + 1] T
F 1
C C + 1
No
IS C = 5?
Yes
No
IS F = 0?
Yes
STOP
(a) The array X[1:5] used in the flowchart contains this data:
10 1 5 7 11
Complete the trace table by using the data given in the array.
10 1 5 7 11
[5]
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [2]
8 This is an algorithm to find if a batch of parts has been manufactured successfully.
START
Accept 0
Reject 0
INPUT PartOK
No
IS PartOK Reject Reject + 1
= 'Y'?
Yes
Accept Accept + 1
No IS Accept
= 10 ?
Yes
Yes
IS Reject Error Reject/Accept * 100
> 1?
No
OUTPUT
"Too many rejected ",
OUTPUT Error, "% error"
"Success"
STOP
(a) Complete the trace table using this data:
Y, Y, Y, N, Y, Y, Y, Y, N, Y, Y, Y, Y
[5]
(b) Describe how the algorithm should be changed to accept ‘Y’ or ‘y’ for a successfully
manufactured part.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
............................................................................................................................................. [3]