Unit 8 Assessment Answers
Unit 8 Assessment Answers
Assessment test
Unit 8 Logic and languages
Answers
1. (a) Give the names of the following logic gates:
(b) Complete the following truth table for the circuit shown.
INPUT A
R T
INPUT B
S
INPUT C
A B C R S T
0 0 0 1 0 0
0 0 1 1 1 1
0 1 0 0 0 0
0 1 1 0 0 0
1 0 0 1 0 1
1 0 1 1 1 1
1 1 0 0 0 1
1 1 1 0 0 1
Assessment test
Unit 8 Logic and languages
then
print("valid product type entered")
else
print("product type invalid")
endif
if productID.length != 6 then
validID = False
productID = input("ProductID invalid - Please re-
enter: ")
else
validID = True
endif
C until validID
Accept C being:
until validlID == True
Assessment test
Unit 8 Logic and languages
3. The following is an incomplete algorithm for checking that a user has entered the correct
password. The password entered is to be checked against the password “ABCdef123”
The user is given 3 attempts to get the password correct before being logged out.
passwordOK = False
attemptsAllowed = 3
attempts = 0
while attempts <= attemptsAllowed and NOT passwordOK
password = input("Please enter password: ")
if password == "ABCdef123" then
passwordOK = True
else
print("Password incorrect")
attempts = attempts + 1
endif
endwhile
if passwordOK then
print("Welcome back")
else
print("Logged out")
endif
Complete the algorithm.
input and assign to variable (password) (1)
if with condition to match (or not match) password (1)
change passwordOK to True (1)
error message output if password incorrect (1)
else with change of attempts (1)
Assessment test
Unit 8 Logic and languages
x y x != y
36 30 True
6 True
24 True
18 True
12 True
6 False
(b) State the value that will be returned by the following function call:
calc(18,4)
Value returned: _____2____
(c) State the purpose of the program.
It finds the greatest common denominator of two positive integers – i.e. the largest
integer that will divide into both numbers without leaving a remainder.
Assessment test
Unit 8 Logic and languages
5. Emma is writing a subroutine to encrypt a string taken as a parameter. Only letters and
spaces can be encrypted. Each letter in the text is replaced by the letter three places further
down the alphabet. A is replaced by D, b by e, … Y by B, z by c. Spaces are not changed.
The program does not accept numbers or punctuation.
Emma is undertaking incremental testing and wishes to test the subroutine. Complete
the test plan below by stating, for each input, the expected outcome, the type of test
and a reason for the test. The first row has been completed for you.
Type of test (valid,
Expected
Input invalid, borderline, Reason for test
outcome
erroneous)
6. (a) Complete the table below to indicate whether each of the following
statements are True or False.
True or False?
(b) Give three reasons why a programmer might choose to use a high-level language
rather than a low-level language to write a program.
A high-level language is easier to learn.
Programs can be written faster in a high-level language.
It is easier to understand and debug a high-level language.
The code can be (written once then) compiled for different types of CPU.
Assessment test
Unit 8 Logic and languages
(c) Give two reasons why a programmer might choose to use a low-level language rather
than a high-level language to code a program.
A program written in a low-level language can be written to be very efficient / execute
very quickly (1).
The code can be written to occupy less RAM than the machine code produced by
translating a high-level language (1).
Statements in a low-level language can be used to control and manipulate specific
hardware components (1).
7. The pseudocode below shows an algorithm that is supposed to calculate the average of a
set of scores held in the array scores. The program contains two logic errors.
1 totalScore = 0
2 Array score[5]
3 score = [25, 17, -5, 28, 30]
4 for i = 0 to score.length
5 totalScore = totalScore + score[i]
6 next i
7 averageScore = totalScore / score.length - 1
Identify the two lines with logic errors in the above pseudocode, and write correct
versions of each so that the program will work as intended.
Lines 4 and 7 contain logic errors, corrected below
1 totalScore = 0
2 Array score[5]
3 score = [25, 17, -5, 28, 30]
4 for i = 0 to score.length - 1
5 totalScore = totalScore + score[i]
6 next i
7 averageScore = totalScore / score.length - 1
[Total 60 Marks]