CS (2)

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

7 Algorithm design and problem solving

6 The following algorithm, shown as a flowchart, checks the size of a consignment


of ten parcels. The dimensions of each parcel are input in centimetres.
START

Counter ¨ 0
Accept ¨ 0
Reject ¨ 0

INPUT
Length,
Breadth

Length > yes


30?

no

Breadth > yes


30?

no

Size ¨
Length * Breadth

Size > yes


600?

no

Accept ¨ Reject ¨
Accept +1 Reject +1

Counter ¨
Counter +1

no Counter
>= 10?

yes

OUTPUT
Accept,
Reject

STOP
296

318281_C07_CAM_IGCSE CO_SCI_257_298.indd 296 2/18/21 12:09 PM


Exam-style questions

a Use this data and the following trace table to dry run the algorithm:
15, 10, 20, 17, 32, 10, 30, 35, 30, 15, 30, 28, 25, 25, 20, 15, 40, 20, 12, 10
Counter Length Breadth Volume OUTPUT

[5]
b State the processes included in this algorithm. [3]
c Identify the rules required to accept a parcel. [3]
7 The following algorithm written in pseudocode adds up 10 positive
numbers and outputs the total. It contains several errors.

Counter ← 1
FOR Counter ← 1 TO 10
REPEAT
OUTPUT "Enter a positive whole number "
INPUT Number
UNTIL Number < 0
Total ← Total + Counter
Counter ← Counter + 1
OUTPUT Total
NEXT Number

a Identify all the errors in the algorithm. [5]


b Rewrite the algorithm so that it is effective and error free. [4]
c Set up a trace table and some test data to dry run your rewritten
algorithm.[4]
d Identify which items of your test data are normal, erroneous
and extreme. [3]
8 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.

297

318281_C07_CAM_IGCSE CO_SCI_257_298.indd 297 2/18/21 12:09 PM


7 Algorithm design and problem solving

INPUT Number1, Number2, Sign


WHILE Number <> 0
IF Sign = '+' THEN Answer ← Number1 + Number2 ENDIF
IF Sign = '-' THEN Answer ← Number1 - Number2 ENDIF
IF Sign = '*' THEN Answer ← Number1 * Number2 ENDIF
IF Sign = '/' THEN Answer ← Number1 / Number2 ENDIF
IF Sign <> '/' AND Sign <> '*' AND Sign <> '-' AND Sign <>
'+'
THEN Answer ← 0
ENDIF
IF Answer <> 0 THEN OUTPUT Answer ENDIF
INPUT Number1, Number2, Sign
ENDWHILE

a Complete the trace table for the input data:


5, 7, +, 6, 2, -, 4, 3, *, 7, 8, ?, 0, 0, /
Number1 Number2 Sign Answer OUTPUT

[3]
b Show how you could improve the algorithm written in pseudocode
by writing an alternative type of conditional statement in
pseudocode.[3]
Cambridge IGCSE Computer Science (0478) Paper 22 Q3, June 2018
9 A programmer has written a routine to store the name, email address and
password of a contributor to a website’s discussion group.
a The programmer has chosen to verify the name, email address and
password.
Explain why verification was chosen and describe how the
programmer would verify this data. [4]
b The programmer has also decided to validate the email address
and the password.
Describe validation checks that could be used. [2]
Cambridge IGCSE Computer Science (0478) Paper 22 Q4, June 2018

298

318281_C07_CAM_IGCSE CO_SCI_257_298.indd 298 23/02/21 5:23 PM

You might also like