December
1998 QUESTION 2 Total Marks: 20 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS
|
(a) | Identify the differences between call-by-value and call-by-reference parameter passing. | [2] |
Difference between
call-by-value and call-by-reference:
|
||
(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;
|
|
(i) Define a function averageMark that takes two arguments: a pass mark
database; and an integer n (you can assume that n |
[5] | |
A sample defintion of
the average mark function is shown below: Function averageMark(database: DatabaseType; n: Integer):
Real; and the following marking scheme should be used;
do not deduct marks for trivial syntactic errors when marking the above points.
|
||
(ii) Define a procedure markBand that takes as its arguments a database
of marks and an integer n (you can
assume that n |
[6] | |
A sample definition of
the mark-band function is shown below: Procedure markBand(database: DatabaseType; n: Integer;Var
low: Integer; Var high: Integer); and the following marking scheme should be used:
do not deduct marks for trivial syntactic errors when marking the above points.
|
||
(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] | |
No shows:
|
||
(iv) Define a representation for the DatabaseType that provides a satisfactory solution to the no-show problem. | [1] | |
The students may have
used a record type as the database element Type MarkRecord = RECORD Alternatively, they may have altered MarkRange from -1 to 100, and used -1 as the representation of a non-show (also award 1 mark).
|
||
(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] | |
Given a suitable
replacement for the type above, then award 1 mark for the function definition, one mark
for the for-loop used in the function candidate, one mark for the conditional increment of a counter
depending upon whether the student sat the examination.
|