Compsci Topic 7 Assessment Test
Compsci Topic 7 Assessment Test
A logical process for solving a problem. It is usually written in pseudo code or in flow charts.
(b) The function RANDOM_INT(number1, number2) will find a random integer number
between number1 and number2. For example, RANDOM_INT(1,3) would give a random
number from the numbers 1, 2 or 3.
The following program simulates throwing two dice. What is the output from the
following program if:
Start
die1 ←
RANDOM_INT(1,6)
die2 ←
RANDOM_INT(1,6)
score ←
die1 + die 2
No
die1 = die2?
Yes
score ← score * 2
OUTPUT
score
Stop
1
Assessment test
Unit 8 Algorithm design and problem solving
Output is 20
(c) Rewrite the flowchart as a pseudo-code algorithm, making the following alterations:
A player’s score is added to their total score after each throw. If the user throws
a ‘double’, their score for that throw is doubled, and they throw the dice again.
Their turn ends if die1 and die2 have different values after a throw. Output the total
score at the end of a turn.
TotalScore = 0
On = True
If Die1=Die2 Then
Score = Score*2
Endif
If Die1<>Die2
On = False
Endif
(d) State the output if the user ‘throws’ 3 times, getting 4 and 4, 3 and 3, 6 and 1
on the three throws.
35
2
Assessment test
Unit 8 Algorithm design and problem solving
While Found=false
If Numbers == num then
Found=true
Endif
Endwhile
3
Assessment test
Unit 8 Algorithm design and problem solving
15 6 43 21 8 17 11 3
(a) How many passes through the list will be required to sort the numbers into
ascending sequence using the bubble sort algorithm?
7
(b) Show how the numbers change after each comparison is made during the first pass,
and the position of the numbers after the first pass is complete. The first row is
completed for you.
6 15 43 21 8 17 11 3
6 15 21 43 8 17 11 3
6 15 21 8 43 17 11 3
6 15 21 8 17 43 11 3
6 15 21 8 17 11 43 3
6 15 21 8 17 11 3 43
4
Assessment test
Unit 8 Algorithm design and problem solving
If clock = 0 then
Output (“midnight”)
Endif
If clock =2 then
Output (“2 am”)
Endif
If clock = 12 then
Output (“midday”)
Endif
If clock = 23 then
Output (“11pm”)
Endif
(b) As part of the testing stage of the program development life cycle, a series of tests
will be carried out. One type of test data will be boundary data. Explain, with an
appropriate example for this algorithm, the meaning of boundary data.
It is the data at each end of the range. One example would be 0.
5
Assessment test
Unit 8 Algorithm design and problem solving
5. Below is an incomplete algorithm which is intended to check the username and password
entered by a user.
1 passwordOK False
2 count 0
3 WHILE count < 3 AND NOT passwordOK
(a) Lines 3, 6, 10 and 13 are missing from the algorithm above. Using four of the lines
of code below, complete this algorithm.
count count + 1
IF password = "AXcd35" THEN
IF password <> "AXcd35" THEN
WHILE count < 3 AND NOT passwordOK
WHILE count < 3 OR NOT passwordOK
IF passwordOK THEN
passwordOK False
6
Assessment test
Unit 8 Algorithm design and problem solving
(c) Explain one other validation that could be made of a new password.
Type check to make sure all data is numerical. If it is a string or special character , data will
be rejected
6. Complete the trace table below to determine the output from the following algorithm:
total ← 0
n ← 1
WHILE n < 6
IF n MOD 2 = 0
total ← total + n
ENDIF
n ← n + 1
ENDWHILE
OUTPUT total
0 1 1 Yes
2 2 0 Yes
2 3 1 Yes
6 4 0 Yes
6 5 3 Yes
12 6 0 No 12
7. The product development lifecycle has four stages: analysis, design, coding and testing.
One task that happens in the design stage is decomposition.
Give three other tasks that may happen in the design stage.
Abstraction
Pattern recognition
Algorithms
7
Assessment test
Unit 8 Algorithm design and problem solving
[Total 50 Marks]