Algorithm design and problem-solving – O Level Computer Science (2210)
137 questions · page 7 of 10
Question text
4
The pseudocode algorithm shown should allow numbers to be entered and should allow
50 numbers to be stored in an array.
←
0
Count
REPEAT
INPUT Values[Count]
←
Count + 1
Count
UNTIL Count = 0
(a) Explain why the algorithm will never end.
…
…
…
…
… [2]
(b) Re-write the original pseudocode so that it terminates correctly and also prevents numbers
below 100 from being stored in the array Values[ ]
…
…
…
…
…
…
…
…
…
… [4]
(c) Describe how you could change your pseudocode in part (b) so that it prevents numbers
below 100 and above 200 from being stored in the array Values[ ]
…
…
…
… [2]
Question text
5
The flowchart represents an algorithm.
The predefined function DIV gives the value of the result of integer division,
←
9 DIV 4 gives y a value of 2
for example, y
An input value of –1 ends the algorithm.
START
INPUT
Value
IS
Yes
Value =
-1 ?
No
Calc1
Value DIV 2
Calc2
Value DIV 3
IS
No
Calc1 =
Value / 2 ?
Yes
IS
No
Calc2 =
Value / 3 ?
Yes
OUTPUT
Value
END
(a) Complete the trace table for the input data:
50, 33, 18, 15, 30, –1, 45, 12, 90, 6
Value
Calc1
Calc2
OUTPUT
[4]
(b) Describe the purpose of the algorithm.
…
…
… [2]
Question text
2
An algorithm has been written in pseudocode to select a random number using the function
RandInt(n), which returns a whole number between 1 and the argument n. The algorithm then
allows the user to guess the number.
RandInt(100)
Number
1
TotalTry
REPEAT
PRINT "Enter your guess now, it must be a whole number"
INPUT Guess
IF TotalTry > Number
THEN
PRINT "Too large try again"
ENDIF
IF Guess > Number
THEN
PRINT "Too small try again"
ENDIF
Guess + 1
TotalTry
UNTIL Guess <> Number
TotalTry - 1
TotalTry
PRINT "Number of guesses ", TotalTry
Find the four errors in the pseudocode and suggest a correction to remove each error.
Error 1 …
Correction …
…
Error 2 …
Correction …
…
Error 3 …
Correction …
…
Error 4 …
Correction …
…
[4]
Question text
3
(a) The flowchart checks the lengths of a batch of 10 ropes. For the batch to be accepted 90% of
the lengths need to be between 24.9 and 25.1 metres.
START
Reject
0
Count
0
Yes
Is Count =
10 ?
No
No
Is Reject
Count
Count + 1
<= 1 ?
INPUT Length
Yes
OUTPUT "Batch
rejected"
Is Length <
Yes
25.1 AND
Length > 24.9 ?
No
Reject
Reject + 1
OUTPUT "Batch
accepted"
END
Complete the trace table for the input data:
24.88, 25.01, 24.98, 25.00, 25.05, 24.99, 24.97, 25.04, 25.19, 25.07
Reject
Count
Length
OUTPUT
[4]
(b) (i)
It has been decided to only reject batches of rope that contain ropes that are too short.
State the change required to the algorithm.
…
… [1]
(ii)
Explain how the algorithm to reject batches could be improved to make it more effective.
…
…
…
… [2]
Question text
4
Four validation checks and four descriptions are shown.
Draw a line to connect each validation check to the correct description.
Validation Check
Description
Checks that some data is entered.
Range check
Checks for a maximum number of characters
Presence check
in the data entered.
Checks that the characters entered are all
Length check
numbers.
Checks that the value entered is between an
Type check
upper value and a lower value.
[3]
Question text
5
A programmer writes a program to weigh baskets of fruit in grams, keeping a total of the weight
and counting the number of baskets. The total weight is stored in a variable Total and the number
of baskets is stored in a variable BasketCount.
Explain, including examples of programming statements, how totalling and counting could be used
in this program.
Totalling …
…
…
…
…
…
Counting …
…
…
…
…
…
[4]
Question text
3
Name the three types of loop structure used in pseudocode.
…
…
…
…
…
… [3]
Question text
4
The following pseudocode algorithm uses nested IF statements.
IF Response = 1
THEN
X + Y
X
ELSE
IF Response = 2
THEN
X – Y
X
ELSE
IF Response = 3
THEN
X * Y
X
ELSE
IF Response = 4
THEN
X / Y
X
ELSE
OUTPUT "No response"
ENDIF
ENDIF
ENDIF
ENDIF
(a) Name the type of statement demonstrated by the use of IF … THEN … ELSE … ENDIF
…
… [1]
(b) Re-write the pseudocode algorithm using a CASE statement.
…
…
…
…
…
…
…
…
…
… [4]
Question text
6
Draw four different flowchart symbols and describe how they are used in a program flowchart.
Flowchart symbol
Description of use
[4]
Question text
3
(a) Give an example of a conditional statement using pseudocode.
…
…
…
…
… [2]
(b) Describe the purpose of a conditional statement.
…
…
…
… [2]
Question 4 starts on page 10.
Question text
4
This section of program code may be used as a validation check.
1
PRINT "Input a value between 0 and 100 inclusive"
2
INPUT Value
3
WHILE Value < 0 OR Value > 100
4
PRINT "Invalid value, try again"
5
INPUT Value
6
ENDWHILE
7
PRINT "Accepted: ", Value
(a) Give a name for this type of validation check.
… [1]
(b) Describe what is happening in this validation check.
…
…
…
…
…
…
…
… [2]
(c) Complete the trace table for this program code using the test data: 200, 300, –1, 50, 60
Value
OUTPUT
[3]
(d) Draw a flowchart to represent this section of program code.
[5]
Question text
1
(a) All variables, constants and other identifiers must have meaningful names.
Describe the data structures you have used in Task 1 to record the items for sale. Include
some sample data for each data structure you have described.
…
…
…
…
…
…
…
…
…
…
… [5]
(b) Explain how your program for Task 1 ensures the item number is unique.
…
…
…
… [2]
(c) Write an algorithm for the part of Task 2 that allows the buyer to add a new bid, using
either pseudocode, programming statements or a flowchart. Assume that Task 1 has been
completed and that the item details have already been found.
…
…
…
…
…
…
…
…
…
Question text
2
(a) An algorithm has been written in pseudocode to input 100 numbers, select and print the
largest number and smallest number.
1
Count
INPUT Number
Number
High
Count
Low
REPEAT
INPUT Number
IF Number > High
THEN
Number
High
ENDIF
IF Number > Low
THEN
Number
Low
ENDIF
Count + 1
Count
UNTIL Count > 99
PRINT "Largest Number is ", Number
PRINT "Smallest Number is ", Low
Find 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) Show how you would change the corrected algorithm to total the numbers and print the total.
Use a variable Total.
…
…
…
…
…
…
…
… [4]
Question text
3
This flowchart inputs the marks gained in an examination. An input of –1 ends the routine.
START
Total
0
Count
0
Distinction
0
INPUT Mark
Yes
Is Mark = –1 ?
Total
Total + Mark
Count
Count + 1
No
OUTPUT "Number of
No
Is
Distinctions ", Distinction
Mark >=
OUTPUT "Average Mark "
80 ?
Total/Count
Yes
END
Distinction
Distinction + 1
Complete the trace table for the mark input data: 50, 70, 65, 30, 95, 50, 55, 85, 65, 35, –1, 45
OUTPUT
Total
Count
Distinction
Mark
[4]
Question text
5
Explain what is meant by validation and verification.
Give an example for each one.
Validation …
…
…
…
Example …
…
…
Verification …
…
…
…
Example …
…
…
[6]