April
1999 QUESTION 3 Total Marks: 20 Marks |
Click here to access other
questions
Click to access
|
(a) | Compare and contrast a function and a
procedure.
|
[4] |
(b) | Identify the differences between call-by-value
and call-by-reference parameter passing.
|
[2] |
(c) | This question is concerned with the
implementation of routines that examine a simple product database. The database can
contain at most MaxProductRange
records, and each record contains details of the amount of product in stock. The various
database types you should use in your routines are shown below. Const MaxProductRange = 200;
|
|
(i) Define a procedure, StockLevels, that takes as its arguments a
database of product information and an integer n (you may assume that n
£ MaxProductRange). This procedure should identify
the number of product ranges held in the database, and return two results: the product
number of the product which has the lowest stock level, and the product number of the
product which has the highest stock level. (Remember to define a procedure and
not a function.)
|
[6] | |
(ii) The designer of the database would like to
know how many of the products are discontinued. The designer decides to use the DatabaseType representation of a database, and
uses a stock level of zero to represent a discontinued product line. Explain why this
solution is problematic, and describe the effect on the function StockLevels.
|
[3] | |
(iii) Define a replacement for the DatabaseType that provides a satisfactory
solution to the discontinued item problem.
|
[2] | |
(iv) Using your new definition of DatabaseType, define a function CurrentProducts that takes as its arguments a database of stock levels, and returns the number of product ranges that are currently not discontinued. | [3] |