Algorithm design and problem-solving – O Level Computer Science (2210)
137 questions · page 8 of 10
Question text
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.
Test data set 1 …
Reason …
…
Test data set 2 …
Reason …
…
[4]
Question text
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
Yes
Is Depth >
"Water too
Height/2 ?
deep"
No
OUTPUT
Is Depth <
Yes
"Water too
Height/3 ?
shallow"
No
OK
False
OUTPUT "Too
Yes
Is Chlorine
much chlorine
>3 ?
add more water"
No
OUTPUT "Too
Yes
little chlorine
Is Chlorine
add more chlorine"
<1 ?
No
No
Is OK = True ?
Yes
OUTPUT "Pool OK
to use"
END
(a) Complete the trace tables for each set of input data.
Input data: 6, 2.5, 2
Height
Depth
Chlorine
OK
OUTPUT
Input data: 4, 3, 1.5
Height
Depth
Chlorine
OK
OUTPUT
Input data: 6, 3.5, 4
Height
Depth
Chlorine
OK
OUTPUT
[6]
(b) Identify a problem with the algorithm that the flowchart represents.
…
… [1]
Question text
3
Give an example of a pseudocode statement or statements to perform each of the following
functions.
A condition controlled loop …
…
…
A conditional statement …
…
…
Totalling …
…
…
[3]
Question text
5
The algorithm allows a number to be entered. It then calculates and outputs the next number in
the mathematical series.
1
Fib
0
Prev2
1
Prev1
INPUT Number
IF Number = 0
0
THEN Fib
ENDIF
WHILE Number > 2
Prev2 + Prev1
Fib
Prev1
Prev2
Fib
Prev1
Number - 1
Number
ENDWHILE
OUTPUT Fib
(a) Complete the trace table for the input data: 7
Fib
Prev2
Prev1
Number
OUTPUT
[4]
(b) Complete the trace table for the input data: 2
Fib
Prev2
Prev1
Number
OUTPUT
[2]
Question text
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.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
Question text
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.
1 TO 7
FOR Count
INPUT Number
Number
Digit(Count)
NEXT
(Digit(1)+Digit(3)+Digit(5)+Digit(7))*3+Digit(2)+Digit(4)+Digit(6)
Sum
IF MOD(Sum,10) <> 0
DIV(Sum,10)*10 + 10 - Sum
THEN Digit(8)
0
ELSE Digit(8)
ENDIF
OUTPUT "GTIN-8"
1 TO 8
FOR Count
OUTPUT Digit(Count)
NEXT
(a) Complete the trace table for the input data: 5, 7, 0, 1, 2, 3, 4
Digit(1) Digit(2) Digit(3) Digit(4) Digit(5) Digit(6) Digit(7) Digit(8)
Sum
OUTPUT
Complete the trace table for the input data: 4, 3, 1, 0, 2, 3, 1
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]
Question 4 starts on page 10.
Question text
4
A programmer has written a routine to check that prices are below $10.00. These values are used
as test data.
10.00
9.99
ten
Explain why each value was chosen.
10.00 …
…
…
9.99 …
…
…
ten …
…
…
[3]
Question text
5
Explain the difference between the programming concepts of counting and totalling.
Include an example of a programming statement for each concept in your explanation.
…
…
…
…
…
…
…
…
… [4]
Question text
6
A database table, PERFORMANCE, is used to keep a record of the performances at a local
theatre.
Show Number
Type
Title
Date
Sold Out
SN091
Comedy
An Evening at Home
01 Sept
Yes
SN102
Drama
Old Places
02 Oct
No
SN113
Jazz
Acoustic Evening
03 Nov
No
SN124
Classical
Mozart Evening
04 Dec
Yes
SN021
Classical
Bach Favourites
01 Feb
Yes
SN032
Jazz
30 Years of Jazz
02 Mar
Yes
SN043
Comedy
Street Night
03 Apr
No
SN054
Comedy
Hoot
04 May
No
(a) State the number of fields and records in the table.
Fields …
Records …
[2]
(b) Give two validation checks that could be performed on the Show Number field.
Validation check 1 …
…
Validation check 2 …
…
[2]
(c) Using the query-by-example grid, write a query to identify jazz performances that are not sold
out. Only display the date and the title.
Field:
Table:
Sort:
Show:
Criteria:
or:
[4]
Permission to reproduce items where third-party owned material protected by copyright is included has been sought and cleared where possible. Every
publisher will be pleased to make amends at the earliest possible opportunity.
To avoid the issue of disclosure of answer-related information to candidates, all copyright acknowledgements are reproduced online in the Cambridge International
Examinations Copyright Acknowledgements Booklet. This is produced for each series of examinations and is freely available to download at www.cie.org.uk after
the live examination series.
Cambridge International Examinations is part of the Cambridge Assessment Group. Cambridge Assessment is the brand name of University of Cambridge Local
Question text
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.
[6]
(b) Explain the changes you will make to your algorithm to also count the negative numbers.
…
…
…
… [2]
Question 3 starts on Page 8.
Question text
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.
INPUT
Number1, Number2, Sign
WHILE
Number1 <> 0
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 = '/' THEN Answer
IF
Sign <> '/' AND Sign <> '*' AND Sign <> '-'
AND Sign <> '+'
0
THEN Answer
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]
Question text
4
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.
Email address …
…
…
Password …
…
…
[2]
Question text
5
A program checks that the weight of a basket of fruit is over 1.00 kilograms and under
1.10 kilograms. Weights are recorded to an accuracy of two decimal places and any weight not in
this form has already been rejected.
Give three weights as test data and for each weight state a reason for choosing it. All your reasons
must be different.
Weight 1 …
Reason …
…
Weight 2 …
Reason …
…
Weight 3 …
Reason …
…
[3]
Question text
1
(a) All variables, constants and other identifiers should have meaningful names.
(i)
For one variable that you have used to record the information about a single boat in
Task 1, state the name, data type and its use.
Variable name …
Data type …
Use …
[3]
(ii)
State one constant and its value that you could have used for Task 1.
Constant name …
Value …
[2]
(b) Give two different validation checks you could have used for data entry in Task 1. For each
check explain why it could be used and provide a set of data for testing.
Validation check 1 …
…
Reason for choice …
…
Set of test data …
…
Validation check 2 …
…
Reason for choice …
…
Set of test data …
…
[6]
(c) Write an algorithm to complete Task 3, using either pseudocode, programming statements
or a flowchart. You may assume Task 2 has been completed.
…
…
…
…
…
…
…
Question text
2
Write an algorithm using either pseudocode or a flowchart, to:
•
input a positive integer
•
use this value to set up how many other numbers are to be input
•
input these numbers
•
calculate and output the total and the average of these numbers.
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
…
… [6]