Algorithm design and problem-solving – IGCSE Computer Science (0478)
200 questions · page 6 of 14
Question text
5
An algorithm has been written in pseudocode to check if a new password is in a list of previously
used passwords OldList[]
If the password is not found, the new password will be stored at the end of the list to replace
"XXXX" already stored there.
01
OUTPUT "Enter your new password "
02
INPUT NewPassword
1
03
Posn
FALSE
04
Found
05
REPEAT
06
IF Password = OldList[Posn]
07
THEN
TRUE
08
Found
Posn + 1
09
ELSE Posn
10
ENDIF
11
UNTIL Found AND OldList[Posn] = "XXXX"
12
IF Found
13
THEN
14
OUTPUT "Password has been used before"
15
ELSE
16
INPUT "New password accepted"
NewPassword
17
OldList[Posn]
18
ENDIF
(a) Identify the three errors in the pseudocode and suggest corrections.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
[3]
(b) Complete this flowchart for the corrected algorithm:
START
STOP
[6]
Question text
8
This is an algorithm to find if a batch of parts has been manufactured successfully.
START
0
Accept
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
Accept
Reject
PartOK
Error
OUTPUT
[5]
(b) Describe how the algorithm should be changed to accept ‘Y’ or ‘y’ for a successfully
manufactured part.
…
…
…
…
…
… [3]
Question text
1
(a) Four descriptions of stages in the program development life cycle are shown.
Draw one line to link each description to its most appropriate program development life cycle
stage.
Not all program development life cycle stages will be used.
Program development life cycle description
Program development life cycle stage
analysis
develop an algorithm to solve the problem
by using structure diagrams, flowcharts or
pseudocode
coding
detect and fix the errors in the program
design
identify the problem and its requirements
evaluation
write and implement the instructions to
solve the problem
testing
[4]
(b) Identify three of the component parts after a problem has been decomposed.
1 …
…
2 …
…
3 …
…
[3]
Question text
3
(a) Describe what is meant by data validation.
…
…
…
… [2]
(b) A validation check is used to make sure that any value that is input is an integer between 30
and 200 inclusive.
Give one example of each type of test data to check that the validation check is working as
intended. Each example of test data must be different.
Give a reason for each of your choices of test data.
Normal test data …
Reason …
…
Abnormal test data …
Reason …
…
Extreme test data …
Reason …
…
[6]
Question text
5
An algorithm has been written in pseudocode to allow some numbers to be input. All the positive
numbers that are input are totalled and this total is output at the end.
An input of 0 stops the algorithm.
←
1
01
Exit
02
WHILE Exit <> 0 DO
03
INPUT Number
04
IF Number < 0
05
THEN
←
Total + Number
06
Total
07
ELSE
08
IF Number = 0
09
THEN
←
1
10
Exit
11
ENDIF
12
ENDIF
13
ENDIF
14
OUTPUT "The total value of your numbers is ", Number
(a) Identify the four errors in the pseudocode and suggest a correction for each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
[4]
(b) Describe how you could change the corrected algorithm to record and output how many
positive numbers have been included in the final total.
You do not need to rewrite the algorithm.
…
…
…
…
…
…
…
… [4]
Question text
1
Tick (✓) one box to identify the first stage of the program development life cycle.
A
Analysis
B
Coding
C
Design
D
Testing
[1]
Question text
3
Identify three different ways that the design of a solution to a problem can be presented.
1 …
…
2 …
…
3 …
…
[3]
Question text
4
A program needs to make sure the value input for a measurement meets the following rules:
•
the value is a positive number
•
a value is always input
•
the value is less than 1000.
(a) Describe the validation checks that the programmer would need to use.
…
…
…
…
…
… [3]
(b) The program needs editing to include a double entry check for the value input.
(i)
State why this check needs to be included.
…
… [1]
(ii)
The input value needs to be stored in the variable Measurement
Write pseudocode to perform the double entry check until a successful input is made.
…
…
…
…
…
…
…
… [3]
Question text
5
Circle five file-handling operations.
calculate
close
count
create
input
open
output
print
read
sort
search
test
total
write
[5]
Question text
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:
X[1]
X[2]
X[3]
X[4]
X[5]
10
1
5
7
11
Complete the trace table by using the data given in the array.
F
C
X[1]
X[2]
X[3]
X[4]
X[5]
T
10
1
5
7
11
[5]
(b) Describe what the algorithm represented by the flowchart is doing.
…
…
…
… [2]
Question text
4
(a) Explain why verification checks are used when data is input.
…
…
…
… [2]
(b) Give two types of verification check and state how each one can be used.
Verification check 1 …
Use …
…
Verification check 2 …
Use …
…
[4]
Question text
5
(a) Four descriptions of validation checks are shown.
Draw one line to link each description to the most appropriate check.
Not all checks will be used.
Description
Check
check digit
to check that the data entered is an integer
format check
to check that some data has been entered
length check
to check that the data entered has an appropriate
number of characters
presence check
to check that an identification number contains
type check
no errors
[4]
(b) Write an algorithm in pseudocode to make sure that an input for the variable Length is
between 15 and 35 inclusive. The code must iterate until a valid input has been made and the
code must include appropriate messages.
…
…
…
…
…
…
…
… [3]
Question text
6
An algorithm has been written in pseudocode to allow 100 positive numbers to be input. The total
and the average of the numbers are output.
100
01
Counter
0
02
Total
03
WHILE Counter > 100 DO
04
INPUT Number
05
IF Number > 0
06
THEN
Total + Counter
07
Total
Counter + 1
08
Counter
09
ENDCASE
10
ENDWHILE
11
OUTPUT "The total value of your numbers is ", Total
12
OUTPUT "The average value of your numbers is ", Total / 100
(a) Identify the four errors in the pseudocode and suggest corrections.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
[4]
(b) Describe the changes you should make to the corrected algorithm so that a count-controlled
loop is used to allow 100 positive numbers to be input.
You do not need to rewrite the algorithm.
…
…
…
…
…
…
…
…
…
… [5]
Question text
7
The flowchart represents an algorithm.
An input of –1 will terminate the algorithm.
START
Total
0
INPUT
Value
IS
Yes
Value =
–1 ?
No
OUTPUT
OUTPUT
Total
"Rejected"
Five1
Value DIV 5
STOP
Value / 5
Five2
IS
No
Five1 =
Five2 ?
Yes
Value DIV 10
Ten1
Value / 10
Ten2
IS
No
Ten1 =
Ten2 ?
Yes
Total + Value
Total
(a) Complete the trace table for the input data:
5, 50, 52, 555, 57, 500, –1, 5500, 55
Total
Value
Five1
Five2
Ten1
Ten2
OUTPUT
[6]
(b) Describe the purpose of the algorithm.
…
…
…
… [2]
Question text
3
Describe the purpose of test data. Include an example of a type of test data in your answer.
Description …
…
…
…
Example …
…
[3]