December
1998 QUESTION 1 (Compulsory) Total Marks: 20 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS
|
(a) | State, and briefly describe, the final stage of the Booch design methodolgy | [2] |
Implementation
or reiterate the design (1 mark). Example descriptions: Reiterating the design can help
solve problems with the program (1 mark); or help to fine tune earlier decisions (1 mark). Award (1 mark) for any suitable description.
|
||
(b) | In C++, a virtual function permits dynamic binding. Explain what is meant by dynamic binding and how it differs from static binding. | [2] |
Dynamic
binding is the association of a name to a function at run-time (1 mark). Static binding
associates names to functions at compile-time (1 mark).
|
||
(c) | Explain the use of the this pointer in C++. | [2] |
The this pointer is an implicit first argument to a
method (1 mark) that is used to properly access the members of an object (1 mark).
|
||
(d) | Explain the difference between deep and shallow (or memberwise) copying of objects in C++. | [3] |
A shallow
copy is used as the default to copy objects passed by value to a function (1 mark) where
pointers in both copies to the same memory location (1 mark). A deep copy copies the data
pointed to by a pointer to newly allocated memory (1 mark). Alternatively, (1 mark) for the correct reproduction of the diagram from the study guide, if it demonstrates a full understanding.
|
||
(e) | For either Java or Smalltalk, list two language features that are different from those found in C++. | [2] |
For Java, any two of:
less complicated syntax (1 mark); run-time security mechanism (1 mark); support for
multi-threading (1 mark). For Smalltalk, any two of: a pure object-oriented programming language (1 mark); uses late binding (1 mark); ease of development environment (1 mark). Award 1 mark for any alternative correct language feature.
|
||
(f) | (i) Explain the difference between passing arguments to a function by value and by reference. | [2] |
In call by value, the
function receives a copy of the data item (1 mark). In call by reference, the function
receives a pointer (or reference) to the actual data item (1 mark).
|
||
(ii) Write a function that takes an array of integers and its integer length, and reverses the order of the integers in the array. | [7] | |
int reverse(int a[], int n) { | [1] | |
for (int i = 0; i < (n/2); i++) { | [2] | |
int m; | [1] | |
m = a[i]; | [1] | |
a[i] = a[n-i-1]; | [1] | |
a[n-i-1] = m; | [1] | |
} | ||
} (1 mark) for a correct signature; (1 mark) for using the loop and (1 mark) for correct guard; (1 mark) for local variable; (1 mark) for assigning either the first or last item to local variable; (1 mark) for each correct swap. Do not penalise repeated errors. |