Bcs Higher Education Qualifications BCS Level 4 Certificate in IT
Bcs Higher Education Qualifications BCS Level 4 Certificate in IT
Bcs Higher Education Qualifications BCS Level 4 Certificate in IT
The triangular table shown below shows a sequence of railway stations (such as A, B, C, D,
E, F) on one line and the distances in kilometres (km) between all of them. For example,
A
B
C
D
E
F
A
0
5
15
20
30
35
0
10
15
25
30
0
5
15
20
0
10
15
0
5
In this example, the distance between stations E and C is 15km and between C and F is
20km.
a)
Assuming a station name can be no longer than 40 characters, that each station
has a unique 3 character code identifier and there are a maximum of 200 stations,
define a suitable data structure to hold this information. The unique 3 character
code identifier is not the same as any station name.
(3 marks)
b)
Assume an integer array holds the distances between the first station and each of
the other stations. In this example, it would be the distance between A & A, A & B,
A & C, A & D, etc. and the first four values would be 0, 5, 15, and 20. Write a subprogram which
i)
ii)
takes as its parameters the data structure you defined in a), an integer array
holding the distances from the first station and each other station and an
integer which gives the number of stations and
prints out the triangular table of distances using the three character code
identifier. (NOTE You can assume the table will fit on the output medium.
You do not have to worry about lines wrapping around.)
(12 marks)
Turn over]
c)
ii)
has four parameters; namely two parameters which can be either two station
names, two unique 3 character codes or one station name and one unique 3
character code, one parameter representing the data structure you defined
in part a) and an integer parameter which gives the number of stations and
returns the distance between the two stations passed to the function.
If either of the station names or unique character codes does not exist, then the
function returns a negative value.
(15 marks)
A2.
A text file <intext> contains words separated by a space. The words contain only capital
letters [A..Z]. A sentence is terminated by a full stop.
The algorithm below is a first attempt to process the text to form an output file <outfile>.
Letters are replaced by their lower-case counterparts, except the first one in any sentence.
Other characters are copied to <outfile> unchanged.
Line
1
2
3
4
5
6
7
8
9
10
11
12
13
code
OPEN <intext> for reading, <outtext> for writing
first_char TRUE
WHILE NOT EOF(intext) DO
READ(intext, achar)
IF achar contains a capital letter AND NOT first_char THEN
BEGIN
convert contents of achar to a lower-case letter
first_char FALSE
END;
IF achar = stop THEN first_char TRUE
WRITE(outtext, achar)
ENDWHILE
WRITELN(finished)
a)
Write out the code for the test of achar contains a capital letter on line 5 and
convert contents of achar to lower-case letter on line 7.
(5 marks)
b)
Dry run the code with the five character sequence G. TH read from <intext>. Note
In the sequence there is a space character between the full stop and the T.
(20 marks)
c)
What conclusions do you draw from the dry run? Suggest ONE amendment.
(5 marks)
A3.
1
9
2
5
3
0
4
8
5
6
6
3
7
5
8
1
9
0
10 11
2
9
The function a in the code below is going to be executed with parameter b set to 10 and
parameter c set to 6. [You can choose to follow either version of the code]
a)
1
2
3
4
5
6
7
8
9
10
11
12
13
b)
Trace the call of the function a(10,6) and show clearly the results of the call.
(8 marks)
Version 1 (C)
Version 2 (Pascal)
FUNCTION a(b, c : INTEGER):INTEGER;
int a(int b, int c){
VAR d, e : INTEGER;
int d,e;
BEGIN
/* begin function */
e := -1;
e = -1;
d := 0;
d = 0;
WHILE d < b DO
while(d < b)
BEGIN
{
IF x[d] = c
if( x[d] == c )
THEN e := d
e = d;
d := d + 1;
d++;
END;
}
a := e
return( e )
END
}
Write a brief summary of what the function does.
(6 marks)
c)
Decide on better names for the identifiers (the function name, its parameters and
the variables) and rewrite the code [either version 1 or version 2] using your new
names and including suitable comments.
(10 marks)
d)
Turn over]
A4.
a)
Line
2
2
3
3
3
4
4
6
7
7
8
9
11
10
13
15
16
16
G: integer identifier
H: type identifier
I: function identifier
J: reserved word
K: comment
L: punctuation character
M: boolean (logical)
expression
N: formal parameter
O: actual parameter
P: local variable
Q: global variable
R: assignment statement
Copy and complete the following answer table. (You need only copy out either the
Text in version 1 or the Text in version 2 column.) Then for each highlighted part
in the programs above, decide what key it should have according to the table above.
(18 x 1 marks)
Text in version
Text in version 2
Key letters for highlighted code
1
v
v
;
;
int
integer
order
order
c2
c2
int
integer
x
x
>
>
=
:=
1
1
c1 == c2
c1 = c2
x=0
x := 0
else
else
/* ... */
/* ... */
'a'
'a'
v
v
w
w
b)
SECTION B
Answer FIVE questions out of EIGHT in Answer Book B. Each question carries 12 marks.
B5.
a)
Most programming languages provide a means of selecting one action from a group
based on the value held in a variable. However, this value cannot be of type REAL.
Explain why this is so.
(3 marks)
b)
Develop an algorithm which reads a four-digit integer Date in the form mmdd (mm =
month digits, dd = day digits) and assigns the appropriate season to a variable
Time_of_Year. For example, if the Date was 1123 (that is, 23rd November) then
AUTUMN would be assigned to Time_of_Year.
(9 marks)
Season
SPRING
SUMMER
AUTUMN
WINTER
B6.
Dates
21 March
21 June
21 September
21 December
to 20 June
to 20 September
to 20 December
to 20 March
inclusive
inclusive
inclusive
inclusive
A number is perfect if the sum of its factors including 1 equals the number. Thus 6 is
perfect as the factors of 6 (that is, 3, 2 and 1) when added together equal 6.
Write a program or pseudocode which prints out all the perfect numbers between 1 and an
input limit limit.
(12 marks)
B7.
The REAL function RANDOM() returns a value 0.0 < RANDOM() <=1.0.
a)
Write an expression which uses RANDOM() and gives an integer value between 1
and 6, as appropriate for a dice score.
(3 marks)
b)
Turn over]
B8.
99
head ptr
member-1
80
member-2
70
member-3
69
end-member
a)
The diagram above represents a linked list with a single pointer field. Show the
pointers if member-3 was removed from the list
(2 marks)
b)
Write code to read in an integer value and delete the first member to contain this
value. Note The input value may not be held in the list.
(10 marks)
B9.
One of the standard data structures used in programming is the queue with its distinctive
operations of join (add a new value to the back of the queue) and serve (remove a value
from the front of the queue). Using an array as the basic storage for the queue, write code
in a language of your choice to implement the operations join and serve.
(12 marks)
B10.
[Note: It is expected that one well-chosen sentence per part will be sufficient as an answer]
(6 x 2 marks)
B11.
When designing a web page to take information from a user there are various form
elements available. Name FOUR different form elements, giving an example of the kind of
information that each is best suited for and drawing what they look like on screen.
(4 x 3 marks)
B12.
Choose program version 1 or 2 below and then find occurrences of the following 6 errors.
For each error you should give the line number and an explanation of the error. In addition
you should state whether each error will be discovered at compile time or run-time.
a)
b)
c)
d)
e)
f)
line
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Version 2 (Pascal)
PROGRAM p;
VAR x, y : integer;
z : ARRAY[0..255] OF char;
BEGIN
w := 1;
x := 'w';
'w' := y;
x := z;
IF b > 1 b := b - 1 ;
x[0] := y;
x := 0;
WHILE x < 9 DO BEGIN
z[x-1] := x / y;
x := x + 1
END
END.
(6 x 2 marks)
Turn over]
** END OF EXAM **