December 1998
AP207: ADVANCED PROGRAMMING TECHNIQUES

QUESTION 2

Total Marks: 20 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 2

 

(a) Identify the differences between call-by-value and call-by-reference parameter passing.

 

[2]
(b) This question is concerned with the implementation of routines that analyses a simple examination "pass mark" database. The database can contain at most ClassSize records. The various database types you should use in your routines are shown below.

Const ClassSize     = 20;
Type  MarkRange    = 0..100;
      DatabaseType = Array [1..ClassSize] of
                     MarkRange;

 

(i) Define a function averageMark that takes two arguments: a pass mark database; and an integer n (you can assume that n sign.GIF (56 bytes) ClassSize) that identifies that the first n elements in the database contain student marks. The result from the function should be a Real that represents the average mark of the first n elements.

 

[5]
(ii) Define a procedure markBand that takes as its arguments a database of marks and an integer n (you can assume that n sign.GIF (56 bytes)ClassSize) that identifies the number of pass marks in the database, and returns two results: the lower mark of a candidate in the examination; and the highest mark (remember to define a procedure and not a function).

 

[6]
(iii) The designer of the database would like to know may many "no-shows" there were for an examination. The designer decides to use the DatabaseType representation of a database, and uses a pass mark of zero to represent a no-show in the examination. Explain why this solution is problematic, and describe the effect on the two functions averageMark and markBand.

 

[3]
(iv) Define a representation for the DatabaseType that provides a satisfactory solution to the no-show problem.

 

[1]
(v) Using your new definition of DatabaseType, define a function candidates that takes as its arguments a database of marks, and returns the number of students who attempted the examination. [3]