April
1999 QUESTION 3 Total Marks: 20 Marks |
Click here to access other
questions
Click to access
|
(a) | One form of Polymorphism in C++ is operator overloading. | |
(i) Explain, using an appropriate example, the term operator overloading. | [3] | |
(ii) Consider the polymorphic expression 5 ==
5.0 in C++. What form of polymorphism is this an example of? Explain your answer.
|
[2] | |
Consider the declaration of the class String below. You are to write overloaded
operator functions for strings. class String
{
|
||
(b) | Give an implementation of the overloaded
operator < that takes two strings by reference and returns 1 if the first is less than the second, or 0 otherwise.
|
[2] |
(c) | Give the implementation of the overloaded
operator == that takes two strings by reference and returns 1 if they are equal, or 0
otherwise.
|
[6] |
(d) | Give an implementation of the function cmp that takes two strings by reference and returns -1 if the first is less than the second, 0 if they are equal, or 1 is the first is greater than the second. | [4] |