Sep 12 Certs D Report
Sep 12 Certs D Report
A1.
{please include question}
Indicative answer pointers
Trying to guide students into writing a complete program with 'subroutines'
Happy for arrays to be handled as globals
The marking algorithm is straightforward conditional arithmetic
a)
float diff;
int i;
for(i=0;i<8;i++){
diff = abs(experiment[i]-correct[i]) * 100 / correct[i];
if( diff<1 ) score[i]=8;
else if( diff<10 ) score[i]=4;
else score[i]=0;
}
b)
void marking(high,tight,low,loose){
float diff;
int i;
for(i=0;i<8;i++){
diff = abs(experiment[i]-correct[i]) * 100 / correct[i];
if( diff<tight ) score[i]=high;
else if( diff<loose ) score[i]=low;
else score[i]=0;
}
}
c)
float total(count,high){
int sum=0;
for(i=0;i<count;i++)
sum+=score[i];
return (sum*100)/(high*count);
}
d)
#include <stdio.h>
void main(){
FILE * fp;
fp=fopen(correct,r);
for(i=0;i<8;i++) scanf(%d,&correct[i]);
fp=fopen(experiment,r);
for(i=0;i<8;i++) scanf(%d,&experiment[i]);
marking(8,1,4,10);
printf(%f, total(8,8);
}
A2.
{please include question}
Indicative answer pointers
More marks were allocated for students who broke the problem down into subroutines
Read the year1 file line by line, calculating student average and storing in year1ave array
Ditto year2
Compare corresponding elements in across year1ave and year2ave to find the largest
increase from year1 to year2
#include <stdio.h>
void main(){
FILE * y1p, y2p;
int sum1, sum2;
int improved=0;
int improvement=0;
int i, m;
int mark;
float step;
y1p=fopen(year1,r);
y2p=fopen(year2,r);
for(i=0;i<50;i++){
sum1=0;
sum2=0;
for(m=0;m<12;i++){
fscanf(y1p,%d,&mark);
sum1+=mark;
fscanf(y2p,%d,&mark);
sum2+=mark;
}
step=sum2/12.0-sum1/12.0;
if(step>improvement){
improvement=step;
improved=i;
}
}
printf(%d,improved);
}
A3
{please include question}
Indicative answer pointers
a)
i=1
v[0]>v[1]
array v
i=2
v[1]>v[2]
array v
i=3
v[2]>v[3]
array v
i=4
v[3]>v[4]
array v
i=5
v[4]>v[5]
array v (unchanged)
i=6
v[5]>v[6]
i=7
v[6]>v[7]
b)
9>7
true
7>5
true
5>3
true
3>2
true
2>4
false
4>6
6>8
false
false
The 2 assignments after the "if" should perform a swap - but they don't
Declare temporary variable e.g. swap (add "int swap;" into the code), change the two
assignments to
swap=v[i-1];
v[i-1]=v[i];
v[i]=swap;
c)
Once the bubble function is fixed it will bubble the largest element of the array to the
end. The simplest way to achieve a full sort is to repeat the bubble, n times
void sort(int n){
int i;
for(i=0;i<n;i++)bubble(n);
}
There are various ways to make this more efficient - e.g.
i) escaping from the sort loop when no swaps took place in the last bubble
ii) decrease the span of the bubble by one element on each repeat
A4.
{please include question}
c<0
for(d=0;d<=c;d++)e=e+d*d;
if(c<0)c=-c;
b(100)
B5.
{please include question}
Indicative answer pointers
a)
int
int
binary[10];
decimal(int len){
int d=0;
for(i=0;i<len;i++){
d=d*2+binary[i];
}
return d;
}
b)
void main(){
int count=0, b;
printf("Input digits"); // 1 or 0, -1 to finish
b=scanf("%d",binary[i]);
while(b>=0){
binary[count]=b;
count++;
scanf("%d",binary[i]);
}
printf("Converted to decimal gives %d", decimal(count));
}
B6
{please include question}
Answer pointers
int fn2;
int fn1=1;
int fn=1;
if(n==0)return 1;
if(n==1)return 1;
for(i=2;i<=n;i++){
fn2=fn1;
fn1=fn;
fn=fn-1+fn-2;
}
return fn;
}
Examiners Guidance Notes
Again, few candidates attempted this question. Generally those who did misunderstood the
mathematics of the Fibonacci sequence and this was reflected in the code produced.
B7
{please include question}
Indicative answer pointers
a)
for(i=100;i>0;i--)f(i);
b)
if(p)
else
c)
char save=v[0];
for(i=0;i<4;i++)v[i]=v[i+1];
v[4]=save;
x=0;
if(q) x=1;
else x=0;
B8
{please include question}
Indicative answer pointers
a)
Programmer has not used white space to lay out the code tidily.
b)
int v[8];
int f(){
int i,j,k;
j=v[0];
for(i=0;i<8;i++)
if(v[i]<j)j=v[i];
k=v[7];
for(i=7;i>=0;i--)
if(v[i]>k)k=v[i];
return k-j
}
c)
Yes it would run successfully - the compiler does not take any notice of white space.
d)
Find the spread of v (the difference between the max & the min values).
e)
B9
{please include question}
Indicative answer pointers
The primary goal of unit testing is to take the smallest piece of testable software in the
application, isolate it from the remainder of the code, and determine whether it behaves
exactly as you expect. Each unit is tested separately before integrating them into modules to
test the interfaces between modules. Unit testing has proven its value in that a large
percentage of defects are identified during its use. White box logic tests would be suitable
for unit testing.
Integration testing is a logical extension of unit testing. In its simplest form, two units that
have already been tested are combined into a component and the interface between them is
tested. A component, in this sense, refers to an integrated aggregate of more than one unit.
In a realistic scenario, many units are combined into components, which are in turn
aggregated into even larger parts of the program. The idea is to test combinations of pieces
and eventually expand the process to test your modules with those of other groups.
Eventually all the modules making up a process are tested together. Beyond that, if the
program is composed of more than one process, they should be tested in pairs rather than
all at once.
Integration testing identifies problems that occur when units are combined. By using a test
plan that requires you to test each unit and ensure the viability of each before combining
units, you know that any errors discovered when combining units are likely related to the
interface between units. This method reduces the number of possibilities to a far simpler
level of analysis. Black box testing would be appropriate for integration testing.
B10.
{please include question}
Indicative answer pointers
a)
b)
c)
d)
e)
f)
g)
h)
i)
j)
k)
l)
Two popular methods of searching are Linear Search & Binary Chop
The binary system operates in base 2 whereas the hexadecimal system operates in
base 16
The acronyms ROM and RAM stand for Read-Only Memory & Random Access Memory
Computer memory is usually measured in units of GB(GigaBytes) while processor
speed is measured in MHz (MegaHertz)
In a program the parts introducing new identifiers are called Declarations and the parts
only intended to be read by the human reader are called Comments
Run time errors can be found in code by suing a Debugger which installs Breakpoints at
selected points
Two diagrammatic notations used in the design of programs are Flowcharts & UML
Diagrams
Whitespace is any selection of program text made up of Space, Tab & Newline
The alternative names for the data structures called LIFO and FIFO are Stack & Queue
The last two phases of the software development life cycle are Testing & Maintenance
Two ways to obtain a one-from-many selection from the user on a web form are DropDown Menu (ListBox) & Radio Buttons
An example of a procedural language is C and an example of an object-oriented
language is C++
B11.
{please include question}
Indicative answer pointers
a) Expect maybe Linear Search and Binary-Chop
b) Linear Search (looking for needle)
No special requirements of array
Start at one end and compare each element with needle
B12.
{please include question}
Indicative answer pointers
a)
b)
c)
v = rec.fld1;
b)
i)
rec.fld2=1;
rec.fld3=2.3e-4;
}
ii)
c)
v = rec.fld1