CH-10 Pseudocode and Flowcharts-1
CH-10 Pseudocode and Flowcharts-1
Fib 1
Prev2 0
Prev1 1
INPUT Number
IF Number = 0
THEN Fib 0
ENDIF
WHILE Number > 2
Fib Prev2 + Prev1
Prev2 Prev1
Prev1 Fib
Number Number - 1
ENDWHILE
OUTPUT Fib
[4]
(b) Complete the trace table for the input data: 2
Fib Prev2 Prev1 Number OUTPUT
[2]
2 (a) Write an algorithm, using pseudocode, to input three different numbers, multiply the two
larger numbers together and output the result. Use the variables: Number1, Number2 and
Number3 for your numbers and Answer for your result.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [5]
(b) Give two sets of test data to use with your algorithm in part (a) and explain why you chose
each set.
Reason .....................................................................................................................................
...................................................................................................................................................
Reason .....................................................................................................................................
...................................................................................................................................................
[4]
5 The flowchart checks the level of chlorine and the depth of water compared to the height of the
swimming pool. Error messages are output if a problem is found.
START
INPUT Height,
Depth, Chlorine
OK True
OUTPUT
Is Depth > Yes
"Water too
Height/2 ? deep"
No
OUTPUT
Is Depth < Yes "Water too
Height/3 ? shallow"
No
OK False
OUTPUT "Too
Yes little chlorine
Is Chlorine
<1 ? add more chlorine"
No
No
Is OK = True ?
Yes
OUTPUT "Pool OK
to use"
END
(a) Complete the trace tables for each set of input data.
[6]
(b) Identify a problem with the algorithm that the flowchart represents.
...................................................................................................................................................
.............................................................................................................................................. [1]
2 (a) Draw a flowchart for an algorithm to input numbers. Reject any numbers that are negative
and count how many numbers are positive. When the number zero is input, the process ends
and the count of positive numbers is output.
(b) Explain the changes you will make to your algorithm to also count the negative numbers.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[2]
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]
2 (a) Write an algorithm to input 1000 numbers. Count how many numbers are positive and how
many numbers are zero. Then output the results. Use either pseudocode or a flowchart.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
.............................................................................................................................................. [6]
(b) Give one change you could make to your algorithm to ensure initial testing is more
manageable.
...................................................................................................................................................
.............................................................................................................................................. [1]
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]
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]
(b) Write an algorithm in pseudocode, using a single loop, to print 50 names that have been
stored in an array.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[3]
2 Write an algorithm using either pseudocode or a flowchart, to:
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
......................................................................................................................................................[6]
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]
2 (a) Write an algorithm to input three different numbers, and then output the largest number. Use
either pseudocode or a flowchart.
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
...............................................................................................................................................[4]
(b) Give two sets of test data to use with your algorithm in part (a) and explain why you chose
each set.
Reason ......................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
Reason ......................................................................................................................................
...................................................................................................................................................
...................................................................................................................................................
[4]
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]
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:
68, 46, 50, 86, 65, 50, 40, 30, –1
[5]
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]
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]
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]
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]
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 Trace table for input value 191
X T1 T2 OUTPUT X T1 T2 OUTPUT
[4]
...................................................................................................................................................
...............................................................................................................................................[2]
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]
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]
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.
Trace table set 1 5, 2, 4, 3, 1, 5
A B C D E F Total Check Output
[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]
3 The flowchart inputs the size of a number of car engines; a value of –1 stops the input.
This information is output: average engine size and number of engines with size > 1.5
START
Engine ← 0
Count ← 0
Number ← 0
INPUT Size
No
STOP
is Size Yes
Count ← Count + 1
> 1.5 ?
No
Number ← Number + 1
1.8, 2.0, 1.0, 1.3, 1.0, 2.5, 2.0, 1.3, 1.8, 1.3, –1
[6]
2 Jatinder uses Internet banking.
This pseudocode checks her PIN.
c ← 0
INPUT PIN
x ← PIN
REPEAT
x ← x/10
c ← c + 1
UNTIL x < 1
IF c <> 5
THEN
PRINT “error in PIN entered”
ELSE
PRINT “PIN OK”
ENDIF
(a) What value of c and what message would be output if the following PINs were entered?
5 1 0 2 0 Value of c:
Message:
5120 Value of c:
Message: [2]
[1]
5 A floor turtle uses these instructions.
Instruction Meaning
Start Finish
Complete the set of instructions to draw the shape (shown in bold lines).
PENDOWN
LEFT 90
REPEAT
[5]