The British Computer Society The Bcs Professional Examinations
The British Computer Society The Bcs Professional Examinations
SECTION A
Answer TWO questions out of FOUR.
You are advised to spend about 1 hour on Section A (30 minutes per question).
All questions carry equal marks.
The marks given in brackets are indicative of the weight given to each part of the question.
1.
A doctors patient records are stored for each complete year in a sequential file <patrec05>. Each patient record
contains the following items:
NHS number
(4 digits)
Name
(20 characters)
Category
(one from child, teenager, adult, pensioner)
Postcode of address
(8 characters)
Repeat medication needed
(Yes / No)
Number of visits to surgery
(integer)
Major illnesses code
(A or B)
Description
(20 characters)
a)
Write an appropriate description for these records in a suitable programming language. State which
language you are using.
(5 marks)
b)
A program is required to print a report which lists details of only the patients who live in a particular part of
the city, which is identified by the first four characters of the postcode, e.g. TS12, which is requested
interactively. The printed details are given under the headings below; that is,
NHS Number
1200
Name
Surgery Visits
JOE BLOGGS
32
At the end of the report the total number of patients for that part of the city is printed as well as the total number
of patient records on the file. The ratio of these is also printed as a percentage.
Write an algorithm for this program in pseudocode or structured English.
c)
(15 marks)
Develop a program for the report as described in b). Use the record description from part a) but do not copy
it out again and indicate where it belongs in your program code.
(10 marks)
Turn over]
2.
3.
a)
Dry run the algorithm below using the values a =16, d=3 and N=5.
Code
Line number
1
READ(a,d,N);
2
prod :=1;
3
a2j := a;
4
WHILE d > 0 DO
BEGIN
5
IF odd(d) THEN prod := prod*a2j MOD N;
6
d := d DIV 2;
7
a2j := SQR(a2j) MOD N
END;
8
WRITELN('result = ',prod:5)
9
END.
(15 marks)
b)
Write BRIEF notes on the use of variable identifiers and comments in the algorithm in part a).
c)
Re-write the algorithm as an integer FUNCTION called Fermat with three parameters representing a, d and
N. Incorporate in your re-written algorithm any improvements you noted in your answer to part b).
(11 marks)
a)
The array DATA has entries from index 20 to index 80 which are sorted in ascending order. The task is to
find the index position of the first repeated number which is above a certain chosen value. Write a function
called pos_rep in a programming language of your choice with a parameter min which will contain the lower
limit. The function should return the number zero if no qualifying value in DATA can be found.
(4 marks)
For example, when the DATA array contains the numbers as below then pos_rep(10) would have result 25
and pos_rep(2) would have result 21.
DATA
Index
Value
20
1
21
3
22
3
23
7
24
8
25
14
26
14
27
15
28
---
29
---(20 marks)
4.
b)
Trace the call of your coding of pos_rep with parameter 10 and with the array DATA initialised as in part a).
(10 marks)
a)
Choose either version A (written in C) or version B (written in Pascal) which perform identical operations
and then provide comments suitable for the following lines of code:
i)
line 1
ii) line 3
iii) line 4
iv) line 6
v) lines 8-10
(20 marks)
Version A
Version B
procedure a(var b, c : integer);
void a(int b, c)
1
begin
{
2
var d, e : integer
int d, e;
3
for d:=b step 1 to c-1 do
for(d=b; d<c; d++)
4
begin
{
5
if v[d]>v[d+1]
if(v[d]>v[d+1])
6
then begin
{
7
e:=v[d+1];
e=v[d+1];
8
v[d+1]:=v[d];
v[d+1]=v[d];
9
v[d]:=e
v[d]=e;
10
end
}
11
end
}
12
end
13 }
b)
It is desired to further modularise this code by making lines 8-10 into a separate subprogram (function or
procedure). Write out the subprogram and rewrite lines 8-10 to make use of your subprogram. (10 marks)
SECTION B
Answer FIVE questions out of EIGHT.
You are advised to spend about 1 hour on Section B (12 minutes per question)
All questions carry equal marks.
The marks given in brackets are indicative of the weight given to each part of the question.
5.
Write a program to merge two distinct lists into a single linked list. Both of the initial lists contain an integer and
the pointer and are both in ascending integer order. This order must be preserved in the merged list. The lists
have the same length. They are set up by the procedure setuplist(head) which returns a pointer to the head of the
list. You must not write this procedure but indicate where appropriate calls to it would be made in your code.
(12 marks)
6.
Write a program which takes as input any 4-digit year and which prints out who was then President of the United
States. Should the year precede 1933 or fall after 2005 an appropriate error message should be output. The
necessary data e.g. Clinton, 1993, 2001 may be stored on a previously written file or in DATA statements.
(12 marks)
7.
8.
a)
(3 marks)
b)
Use this in a program to compute to 10 decimal place accuracy. Print how many iterations are needed:
[ = 3.1415926535]
(9 marks)
While the area of an ellipse having major axis (a) and minor axis (b) is given exactly by the formula A = *a*b
there is no formula which gives the exact perimeter(S). The best approximation is given by Ramanjuans
formula:
S (a + b) [1 + 3t / (10 + sqrt(4 -3t))] where t is given by
t = (a - b)2 / (a + b)2
Other approximations are S ( a + b) and S 2**a*b.
Write a program to compute the area for a group of ellipses having major axis (a) and minor axes between bmin
and bmax, which are requested interactively. It also computes the perimeter by each of the three given formulae,
and finds the percentage difference of the other two from that given by the Ramanjuan formula.
(12 marks)
9.
When a user is entering data on an interactive form there are several interface elements that can be used for
different kinds of data. Summarise the elements, show what they look like on the interface and describe the
type(s) of data for which they are best used.
(12 marks)
Turn over]
10. a)
Suppose that marks are available for students as follows: Anne 40, Colin 55, Daniel 44, Frank 60, George
52, Harry 70, Jill 62, Kate 39, Lynne 74. This data is to be stored in a sequential file.
i)
Draw a diagram representing the sequential file.
ii) List in order all the keys that will be visited to lookup the marks for the student Harry.
(4 marks)
b)
Now suppose that the file is made into an indexed sequential file with a single level index. The index groups
are defined by initial letter of name, with 3 initial letters per group, i.e. A-C, D-F, G-I, etc.
i)
Draw a diagram representing the file and its index.
ii) List in order all the keys that will be visited to lookup the marks for the student Kate indicating which
keys are accessed in the index and which in the main file.
(8 marks)
12. a)
Account
Number
Age
Name
11223344
22334455
33445566
...
...
...
...
29
J.White
33
A.Black
45
N.Brown
...
...
...
...
...
...
...
...
Imagine slicing this data up into horizontal rows and using three arrays to hold the data. How might the
arrays be declared (in a programming language of your choice). How would the name and age details of a
person with a particular account number be obtained?
(6 marks)
b)
Account
no.
Age
Name
11223344
22334455
33445566
...
...
...
...
29
J.White
33
A.Black
45
N.Brown
...
...
...
...
...
...
...
...
Imagine slicing this data into vertical columns and using a database table to hold the data. Describe the design
of the table. How would the name and age details of a person with a particular account number be obtained?
(6 marks)