You are on page 1of 10

T EST CODE 02115020

FORM TP 2015165 MAY/JUN E 201 5

CARIBBEAN EXAMINATIONS COUNCIL

CARIBBEAN ADVANCED PROFICIENCY EXAMINATION®

COMPUTER SCIENCE

FUNDAMENTALS OF COMPUTER SCIENCE

UNIT 1 - Paper 02

2 hours 30 minutes

( 15 MAY 2015 (a.m.))

READ THE FOLLOWING 'INSTRUCTIONS CAREFULLY.

I I.

2.
Thi s paper consists of T HR EE sect io ns.

EAC H secti on co ns ists of T WO questi ons.

3. A nswer ALL questi ons in the THREE secti ons.

-
i iiiii

---
-- DO NOT TURN THIS PAGE UNTIL YOU ARE TOLD TO DO SO.

- Co pyri ght © 2014 Caribbean Exa minati ons Counc il

---
! !!!!!

02 11 5020/CA PE 20 15
A ll rights rese rved.
- 2-

SECTION A

COMPUTER ARCHITECTURE AND ORGANIZATION

Answer BOTH questions.

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]

(f) Consider the following floating point representation:

1-bit sign, 3-bit exponent, 5-bit mantissa

Calculate the decimal representation of 00 II 0 I 0 II. Show ALL working. [3 marks]

Total 25 marks

GO ON TO THE NEXT PAGE


021 15020/CAPE 20 15
-3-

2. (a) Describe TWO main functions ofthe CPU. Include in your description a definition ofthe
CPU. [6 marks]

(b) The following questions are related to the fetch-decode-execute cycle :

(i) State the purpose ofthe ' fetch ' operation. [1 mark]

(ii) State the purpose of the ' decode ' and ' execute ' operations. [2 marks]

(iii) Define the term ' instruction set' . [1 mark]

(c) The following questions are related to memory.

(i) How does ROM differ from RAM? [4 marks]

(ii) Your friend is interested in purchasing a new computer. He is considering the


following options:

Option I: Purchasing a large amount of cache and a small amount of RAM .

Option 2: Purchasing a large amount of RAM and a small amount of cache.

Advise your friend by explaining ONE advantage and ONE disadvantage of EACH
option . · [4 marks]

(d) There are several registers found in the CPU .

(i) What is the collective purpose of these registers? [1 mark]

(ii) Name THREE registers found in the CPU and for EACH , describe its function .
[6 marks]

Total 25 marks

GO ON TO THE NEXT PAGE


02115020/CAPE 2015
-4-

SECTION B

PROBLEM SOLVING WITH COMPUTERS

Answer BOTH questions.

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

(i) Which of the algorithms above illustrates unbounded iteration? [1 mark]

(ii) Which ofthe algorithms above illustrates bounded iteration? [1 mark]

(iii) Explain how the loop in Algorithm 1 is expected to terminate. [2 marks]

(iv) Explain how the loop in Algorithm 2 is expected to terminate . [2 marks]

GO ON TO THE NEXT PAGE


-5-

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

1. print " Odd Number Cube "

2 0 print '' ========== =====''

3 0 j = 1

4. while j < 121

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

GO ON TO THE NEXT PAGE


02115020/CAPE 2015
-6-

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.

You should carefully note the followin g:

wri teSym( n) prints n '$'from the current cursor position.


Exa mple : writeSym( 2) would print
$$

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)

writeln ( ' #')

j = j - 3

endwhil e

writeln( ' * ' )

for k = 1 to (j + 5) do

write( ' @' )

writeln ()

[12 marks]

GO ON TO THE NEXT PAG E


02115020/CAPE 2015
-7-

(b) Co nstruct a fl owchart to represent the follow ing algorithm .

start

print ' Enter a :'

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

print ' Enter 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

Answer BOTH questions.

5. (a) The translation process comprises several stages.

(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

Input file: testgrades.txt

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]

( ii) Imperati ve (proced ura l) [2 marks]

(iii) Scriptin g [2 marks]

(b) What output is produced by the following C program ?

#in c lude <stdio . h >

in t main () {int x , i 2, j 10 , final 1;

while ( i <= j * 2)
i j - 3;

f or (x = j ; x >= 0 ; x = x - 2)

printf ( " x is %d j is %d i is %d \ n ", x , j , i) ;

j -- ;

i++ ;

final fin a 1 + ( i - 1) * (j - 2 ) ;

// for

printf( " New i %d " 1 i ) ;

i i + 3;

}// while

printf ( " \ nFinal Output : %d \ n ", final) ;

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.

Profit is calculated as shown below.

Profit = (Selling Price x Quantity) - (Cost Price x Quantity)


[3 marks]

Total 25 marks

END OF TEST

IF YOU FINISH BEFORE TIME IS CALLED, CHECK YOUR WORK ON THIS TEST.

02115020/CAPE 20 15

You might also like