[go: up one dir, main page]

0% found this document useful (0 votes)
167 views7 pages

Unit 8 Assessment Answers

The document contains assessment answers for a Unit 8 test on Logic and Languages in Computer Science. It includes questions on logic gates, pseudocode algorithms for validating product types and passwords, a subroutine for calculating the greatest common denominator, and features of Integrated Development Environments (IDEs). Additionally, it addresses programming concepts such as validation checks, logic errors, and the advantages of high-level versus low-level programming languages.

Uploaded by

carson.lo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
167 views7 pages

Unit 8 Assessment Answers

The document contains assessment answers for a Unit 8 test on Logic and Languages in Computer Science. It includes questions on logic gates, pseudocode algorithms for validating product types and passwords, a subroutine for calculating the greatest common denominator, and features of Integrated Development Environments (IDEs). Additionally, it addresses programming concepts such as validation checks, logic errors, and the advantages of high-level versus low-level programming languages.

Uploaded by

carson.lo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

lOMoARcPSD|55175252

Unit 8 Assessment Answers

Computer Science (Norlington School and 6th Form)

Scan to open on Studocu

Studocu is not sponsored or endorsed by any college or university


Downloaded by Carson LO [10NH] (carson.lo@online.island.edu.hk)
lOMoARcPSD|55175252

Assessment test
Unit 8 Logic and languages

Answers
1. (a) Give the names of the following logic gates:

Name: ___NOT [1]

Name: __AND [1]

Name: __OR [1]

(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

(b) Give the Boolean expression equivalent to the logic diagram.


T = A OR (NOT B AND C)
A OR (1) (NOT B AND C) (1)
Brackets are required for second mark.

Downloaded by Carson LO [10NH] (carson.lo@online.island.edu.hk)


lOMoARcPSD|55175252

Assessment test
Unit 8 Logic and languages

2. A product type in a computer company is “HARDWARE”, “SOFTWARE” or “MANUAL”.


The following pseudocode algorithm is being written to validate user input.
productType = input("Please enter product type: ")

A if productType == "HARDWARE" OR productType == "SOFTWARE"


OR productType == "MANUAL"

then
print("valid product type entered")
else
print("product type invalid")
endif

(a) Complete the condition for the IF statement at A.


(b) The following incomplete algorithm performs an alternative validation check on a
product code.
(i) Insert the missing lines at B and C.
productID = input("Please enter ProductID: ")
validID = True
B do

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

(ii) What type of validation check is carried out by the algorithm?


Length check.
(iii) Name one other type of validation check that could be carried out on
the product code.
Format check / range check.

Downloaded by Carson LO [10NH] (carson.lo@online.island.edu.hk)


lOMoARcPSD|55175252

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)

Downloaded by Carson LO [10NH] (carson.lo@online.island.edu.hk)


lOMoARcPSD|55175252

Assessment test
Unit 8 Logic and languages

4. A subroutine is given below.


function calc(x, y)
while x != y
if x > y then
x = x – y
else
y = y – x
endif
endwhile
return x
endfunction

(a) The subroutine is called as follows:


calc(36,30)

Complete the trace table below for the function call.

x y x != y

36 30 True

6 True

24 True

18 True

12 True

6 False

State the value that will be returned by the function: ______6__________

(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.

Downloaded by Carson LO [10NH] (carson.lo@online.island.edu.hk)


lOMoARcPSD|55175252

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)

"HEY" KHB Valid tests uppercase letters

Error message numbers and punctuation are


"XYZ123@" Invalid
/ Throw an error not allowed

Error message / Numbers are not accepted by


123 Erroneous
Throw an error the subroutine.

Checks that x rotates around


"X" a Borderline
to a

6. (a) Complete the table below to indicate whether each of the following
statements are True or False.

True or False?

All programs have to be converted to machine code


True
before they can be executed
A compiler translates a high-level language into machine
True
code
An interpreter converts a low-level language into
False
machine code

High-level languages are “machine-independent” True

(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.

Downloaded by Carson LO [10NH] (carson.lo@online.island.edu.hk)


lOMoARcPSD|55175252

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

8. Programmers usually use an IDE (Integrated Development Environment) to develop their


programming code.
Some features offered by IDEs include breakpoints, stepping through code and watching
variables.
(a) Describe how an IDE can be used to debug programs that have logical
errors in them.
Breakpoints can be set in the code which pause it (1) at a point before where the
logical error is suspected to be (1).
Variables can then be watched to see how they change as the program is run (1).
The programmer can step through the code running one line at a time (1).
(b) Explain two other features offered by IDEs.
Editor – to create and edit the code.
Error diagnostics – to give advice on syntax errors.
Run-time environment – to run the code and catch errors.
Translators – to translate/run the code.
Syntax highlighting – to highlight different parts of the code different colours.
Code autocompletion – automatically completes part of the code for the programmer
or any other common feature of an IDE, with an explanation.

[Total 60 Marks]

Downloaded by Carson LO [10NH] (carson.lo@online.island.edu.hk)

You might also like