Professional Documents
Culture Documents
COMPUTER SCIENCE
UNIT 1 - Paper 02
2 hours 30 minutes
I I.
2.
Thi s paper consists of T HR EE sect io ns.
-
i iiiii
---
-- DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO.
---
! !!!!!
02 11 5020/CA PE 20 15
A ll rights rese rved.
- 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 ifthe 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]
(b) Expl ain what is meant by the term ' demultiplexer ' . [2 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 I A 53. Show ALL working.
[3 marks]
(e) Find the 8 bit two 's complement of - 21. Show ALL working. [2 marks]
Total 25 marks
2. (a) Describe TWO main functions ofthe CPU. Include in your description a definition ofthe
CPU. [6 marks]
(i) State the purpose ofthe ' fetch ' operation. [1 mark]
(ii) State the purpose of the ' decode ' and ' execute ' operations. [2 marks]
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 algorithm s labelled Algorithm 1 and Algorithm 2 and answer the
question s that follow.
Algorithm 1
FOR y
= 1 TO 20 DO
PRINT y
END FOR
Algorithm 2
READ z
SUM1 = 0
WHILE z > - 1 DO
SUM 1 = SUM1 + z
READ z
END WH I LE
(c) The following algorithm is designed to print a tab le of cubes of all the odd positive integers
between 7 (inc lu sive) and 121 (inclusive). However, there are errors in the algorithm.
3 0 j = 1
5. j * j * j = cube
6. print j , cube
7. j = j - 1
8. end while
By referring to the specific line number, identify and correct FOUR errors in the algorithm,
so that it would achieve its objective. [8 marks]
(d) Write an algorithm that uses iteration to find the sum of all multiples of8 and all multiples
of II 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 yo ur answer
booklet exactly as it would be generated by the algorithm.
write ( lis_t -1) continues output of list -1 on the current line, from the c urrent
cursor position .
wri teln () te rminates output on the current line. Subsequent output beg ins on a
new line
wri teln (list -1) continues output of list -1 on the current line from the current
cursor position but any subsequent output beg ins on a new line.
SIZE = 12
j = S IZE - 4
while j >= 2 do
writeSym(j + 2)
j = j - 3
endwhil e
for k = 1 to (j + 5) do
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
GO ON TO TH E NEX T PA GE
02 11 5020/CA PE 201 5
-9-
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]
(c) Every term Mr James creates a file containing student IDs and the final mark for each
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.
The file is formatted as follows , where 12238 represents a student ID and 50 represents
the student mark.
12238 50
2345A 89
4567X 76
4432K 65
5434C
Write a C program which would read in the contents ofthe file , testgrades.txt, and output
the number of students gaining the grades A, B, C and F and the highest mark gained . The
grade categories are as follows:
A = 80 to I 00
B = 70 to 79
,..
I 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
- I 0-
6. (a) Briefly describe EAC H of the following types of programmin g lang uages:
( i) Declarative [2 marks]
while ( i <= j * 2)
i j - 3;
f or (x = j ; x >= 0 ; x = x - 2)
j -- ;
i++ ;
final fin a 1 + ( i - 1) * (j - 2 ) ;
// for
i i + 3;
}// while
return 0 ;
} // main
[9 marks]
GO ON TO TH E N EXT PAG E
02115020/CA PE 20 15
- II -
(c) A vendor needs to use a C application to store data about some fruits that he se lls. Eac h
fruit has an ID (integer), a cost price (floating point), a selling price (floating point) and a
quantity in stock (integer).
(i) Write a declaration for a C structfruitRec 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 a nd mango , are already loaded with data.
Write C code to exchange the cost price and selling price values ofpine and mango.
[2 marks]
(v) Assume that twofruitRec structs a, bare already loaded with data. Write C code
to print the total expected profit to be made from the sale of the two fruits.
Total 25 marks
END OF TEST
IF YOU FINISH BEFORE TIME IS CALLED, CHECK YOUR WORK ON THIS TEST.
02115020/CAPE 20 15