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
An array called correct contains the correct values for eight measurements. The
array experiment contains the values obtained by students for the same
measurements. The array result contains the marks awarded for their attempts. If
an experimental result is within 1% of the correct value the score is 8, if the result is
within 10% then it scores 4, otherwise 0.
1
200.0
2
50.0
correct
0
100.0
0
100.5
1
215.0
2
80.0
experiment
0
8
1
4
2
0
result
a)
Write code to calculate the values in array result assuming the arrays correct
and experiment exist and contain values
(8 marks)
b)
Convert the code you have written for part a) into a function (or procedure)
called marking which has 4 parameters high, tight, low, loose. High and low
are the scores awarded (c.f. 8, 4) and tight and loose are the percentage
differences allowed (c.f. 1%, 10%)
(8 marks)
c)
Write a function to find the sum of the values in the result array, expressing it
as a percentage of the maximum score possible.
(6 marks)
Turn over]
d)
A2.
Write a program using your answers to b) and c) which reads 8 values into
the array correct from one file, 8 values into the array experiment from
another file and computes the percentage of the maximum score.
(8 marks)
A University department wants to award a prize to the most improved student. This
means the student who improved their average mark the most in the second year
compared with the first.
Students take 12 courses each year and the marks are percentages, rounded to
integer. The actual data is available in two text files called year1 and year2. Each
line in a file corresponds to one student and lists their 12 results. There are 50
students in the class and the students are in the same order in both files. You can
assume no two students have the same name.
The programming task is to read both files and calculate the year1 and year2
average for each student and hence print out the position of the most improved
student. This will be a number - for example 10 would mean that the student listed
10th in the files is the most improved.
(30 marks)
A3.
Consider the following function that has been created as part of a sorting program
void bubble(int n){
int i;
for(i=1;i<n;i++){
if(v[i-1]>v[i]){
v[i-1]=v[i];
v[i]=v[i-1];
}
}
}
a)
If the array v has been initialised as follows, trace the function call bubble(8)
v
0
9
1
7
2
5
3
3
4
2
5
4
6
6
7
8
(16 marks)
b)
The student who wrote this function was trying to create a component of a
sorting program. What has gone wrong? Correct the mistake that you have
pointed out.
(6 marks)
c)
A4.
Consider the following program and answer the questions that follow
int a;
int b(int c){
int d, e=0;
if(c<0)c=-c;
for(d=0;d<=c;d++)
e=e+d*d;
return(e);
}
void main(){
a=b(100);
}
In the program above find and copy out all the (different)
a) local variables
b) function identifiers
c) arithmetic operators
d) integer constants
e) type identifiers
f) punctuation characters
g) reserved words
h) relational operators
(9 x 2 marks)
Notes: In parts (a-h) only copy out what is asked for - do not include any of the
surrounding context. If an item occurs more than once in the program then it is only
necessary to write it down once.
From the program above, find and copy out one example of
i) a logical/boolean expression
j) an iterative statement
k) a conditional statement
l) a function call
(4 x 3 marks)
SECTION B
Answer FIVE questions out of EIGHT in Answer Book B. Each question carries 12 marks.
B5.
a)
0
1
1
1
2
1
3
0
4
1
The result of calling the function decimal with the array above is 29
(6 marks)
b)
Write a test program to test your function which reads in digits into the array,
calls your function and outputs the result.
(6 marks)
Turn over]
B6.
By writing two functions called fibonacci and fibonacci_r show how the calculation
known as the fibonacci sequence may be computed by an non-recursive method and
a recursive method.
[ Definition: fibonacci(n)
is 1 if n=0,
is 1 if n=1,
is the sum of fibonacci for n-1 and fibonacci for n-2 if n>1 ]
(2 x 6 marks)
B7.
b)
Rewrite the following conditional without using the logical operators 'and' (&&),
'or' (||), 'not' (!)
if( !p || q ) x=1; else x=0;
c)
Write the code to perform a left cyclic shift of the values in array v below
index
v (original)
v (after shift)
0
'S'
'M'
1
'M'
'I'
2
'I'
'L'
3
'L'
'E'
4
'E'
'S'
(3 x 4 marks)
B8.
a)
b)
c)
Could the original 'bad' code run successfully without the change you made in
b)? Why?
(2 marks)
d)
e)
Apart from what you did in b), suggest one more improvement to the code
(2 marks)
B9.
unit tests
b)
integration testing
(6 marks)
(6 marks)
Give reasons for your answers.
B10.
B11.
a)
b)
For EACH algorithm that you named in a), briefly describe how the algorithm
works
(2 x 5 marks)
(Note: no code is required)
B12.
a)
b)
c)
Turn over]
* END OF EXAM *