Professional Documents
Culture Documents
COMPUTER SCIENCE
UNIT 1 – Paper 02
2 hours 30 minutes
02115020/CAPE 2015
-2-
SECTION A
1. (a) Your friend Samuel Carter would like you to design a security alarm system for his house.
The security alarm should sound if the alarm switch is enabled (turned on) and a window
or door is opened. For example, if the alarm switch is enabled and a window is opened,
the alarm should sound.
(i) Write down the truth table (that is, list all possible input bit patterns and their
corresponding outputs) for this scenario. [8 marks]
(ii) Using only primary logic gates, design and draw the associated circuit.
[4 marks]
(c) Draw a clearly labelled block diagram of a 3-to-8 line decoder. [3 marks]
(d) Find the decimal equivalent of the hexadecimal number 1A53. Show ALL working.
[3 marks]
(e) Find the 8 bit two’s complement of –21. Show ALL working. [2 marks]
Total 25 marks
2.
CPU. [6 marks]
(ii) State the purpose of the ‘decode’ and ‘execute’ operations. [2 marks]
[1 mark]
Advise your friend by explaining ONE advantage and ONE disadvantage of EACH
option. [4 marks]
(ii) Name THREE registers found in the CPU and for EACH, describe its function.
[6 marks]
Total 25 marks
SECTION B
3. (a) Explain what happens during the ‘implementation and review’ phase of the problem-solving
process. [4 marks]
(b) Examine the following algorithms labelled Algorithm 1 and Algorithm 2 and answer the
questions that follow.
Algorithm 1
FOR Y = 1 TO 20 DO
PRINT Y
END FOR
Algorithm 2
READ Z
SUM1 = 0
WHILE Z > -1 DO
SUM1 = SUM1 + Z
READ Z
END WHILE
(c) The following algorithm is designed to print a table of cubes of all the odd positive integers
between 7 (inclusive) and 121 (inclusive). However, there are errors in the algorithm.
3. j = 1
5. j * j * j = cube
6. print j, cube
7. j = j - 1
8. end while
of 11 between m (inclusive) and n (exclusive) where m and n are two positive integers
entered via the keyboard. Assume that n > m. [7 marks]
Total 25 marks
4. (a) Trace through the execution of the following algorithm and draw the output in your answer
booklet exactly as it would be generated by the algorithm.
write(list-1) continues output of list-1 on the current line, from the current
cursor position.
writeln(list-1) continues output of list-1 on the current line from the current
cursor position but any subsequent output begins on a new line.
SIZE = 12
j = SIZE – 4
while j >= 2 do
writeSym(j + 2)
writeln(‘#’)
j = j – 3
endwhile
writeln(‘*’)
for k = 1 to (j + 5) do
write(‘@’)
writeln()
[12 marks]
start
read a
Set total to 1
while a > –1 do
a = 2 * a;
if a < 20 then
a = a – 1
else a = a + 1
endif
total = total + a
read a
endwhile
print total
stop
[13 marks]
Total 25 marks
SECTION C
PROGRAMMING
(i) Describe the purpose of the lexical analysis stage of this translation process.
[3 marks]
(ii) Comment on the existence of error detection in this lexical analysis stage.
[1 mark]
(b) What is modular programming and how does it encourage good programming practices?
[2 marks]
student in his Biology class. This term, Mr James would like to automatically determine
the number of students gaining grades A, B, C and F, as well as the highest mark gained.
He has asked you to write a C program to do this.
1223B 50
2345A 89
4567X 76
4432K 65
5434C ...
testgrades.txt
A = 80 to 100
B = 70 to 79
C = 60 to 69
F < = 59 [10 marks]
(d) A palindrome is a sequence of characters which give the same word when read in both
directions. For example, madam.
Write a C program which accepts a string from a user and determines whether the string
is a palindrome or not. Assume that all letters are lower case. [9 marks]
Total 25 marks
GO ON TO THE NEXT PAGE
02115020/CAPE 2015
-9-
6.
#include <stdio.h>
while (i <= j * 2) {
i = j - 3;
for (x = j; x >= 0; x = x - 2) {
j--;
i++;
} //for
i = i + 3;
}//while
return 0;
}//main
[9 marks]
(c) A vendor needs to use a C application to store data about some fruits that he sells. Each
(i) Write a declaration for a C struct fruitRec that can store the record for a fruit.
[2 marks]
(ii) Declare TWO variables, apple and pear, that have the record structure declared
in (c) (i) above. [1 mark]
(iii) Write C code to put data into the apple struct of (c) (ii) above. You can use any
values you like. [2 marks]
(iv) Assume that two fruitRec structs, pine and mango, are already loaded with data.
Write C code to exchange the cost price and selling price values of pine and mango.
[2 marks]
(v) Assume that two fruitRec structs a, b are already loaded with data. Write C code
Total 25 marks
END OF TEST
IF YOU FINISH BEFORE TIME IS CALLED, CHECK YOUR WORK ON THIS TEST.
02115020/CAPE 2015