GCO4020/CSC428 - Advanced Object Oriented Techniques In C++
Week 1
Array be extended to three or more "dimensions"?
If so, outline how. If not, explain why not?
There is a sample solution for Exercise 1.
n, d and D are integers and that D is
equal to 2 raised to the power of d.
n>>d is identical to n/D
for both positive two's-complement integers.
n&((1<<d)-1) is identical to
n%D for positive two's-complement integers.
There is a sample solution for Exercise 2.
Verify the reasoning used to justify the use of:
reallocate(array.myNextFree+modBucketSize >> divBucketSize);
in the Array copy constructor, by:
Array class could provide a means of
pre-allocating space without having to use a helper class like
Array::Size.
There is a sample solution for Exercise 4.
Array destructor uses operator delete[]
instead of operator delete. Explain what difference
this makes?
virtual, which implies
a restriction on how class Array may be used.
Describe that restriction and explain how it comes about.
There is a sample solution for Exercise 5.
Array::Contains member function so
that it is able to return the index of the first matching
element (rather than the index+1) and yet can still signal
failure in some useful manner (hint: consider how the checked
public access members achieve this).
Array::Contains member function so
that it is able to search for an index based on
any (in)equality criterion (that is, less
than, greater than, equals, not equals, etc.).
There is a sample solution for Exercise 6.
Array::Append(const Array& array) could have been
written slightly more compactly like this:
reallocate(myNextFree+array.myNextFree+modBucketSize>>divBucketSize);
for (int i=0; i<array.myNextFree; i++)
{
access(myNextFree++) = array.access(i);
}
return *this;
Explain why that might not be a good idea.
There is a sample solution for Exercise 7.
Array::Reset() nor Array::RemoveLast(...)
delete any buckets that becomes unused as a result of
their actions. Rewrite them so that they do.
Array::Reset() and
Array::RemoveLast(...) could be re-implemented so as to
improve their maintainability.
There is a sample solution for Exercise 8.
if (!(a1.access(i) == a2.access(i))) { return false; }
if (a1.access(i) != a2.access(i)) { return false; }
<) be defined on the stored element
type. Hence, as it is currently defined, we could not create,
for example, a map<int, Array<int> >.
Implement an operator< for comparing two
Arrays.
There is a sample solution for Exercise 9.
Last updated: Fri Feb 18 11:16:58 2000