COIT12140 – Object Oriented Programming - Webfuse

carenextSoftware and s/w Development

Nov 18, 2013 (3 years and 6 months ago)

56 views

COIT12140


Object Oriented Programming

Exercises Week 4


1.

Why do we overload functions?


2.

What are the differences between overloading a class function as a member
function or as a friend function?


3.

Why should the overloaded assignment operator check for se
lf assignment?


4.

Why should the overloaded assignment operator return an object by reference?


5.

What would happen if the overloaded assignment operator returned an object by
value?


6.

For the following function definitions and invocations, indicate which funct
ion
is called by each function call. (Some calls are invalid)


void f(int);

void f(char, int =0);

void f (float,int);

void f (int,double);


void g()

{


f(‘a’);


f(1, ‘a’);


f(1,3.4);


f(3.4);


f(‘A’, 3.4);

}

7.

For a List class of an arra
y of integers, that uses dynamic memory, what
member functions would you include? What operators would you overload?


8.


Develop the Time24 class. It has 2 integer data members, one for the hour and
one for the minutes. Your class should contain the follow
ing member
functions (& any more you feel are necessary)



A parameterised constructor, that is also the default constructor,



A copy constructor,



A series of accessor & mutator functions,



An overloaded assignment operator,



Overloaded input and output operato
rs,



An overloaded operator(
-
) that finds the time between 2 time
objects,



Overloaded decrement operators, both prefix and postfix.



An overloaded logical == operator, that returns true if two times
are equal, false otherwise



Use the overloaded == operator t
o develop the overloaded !=
operator

Develop a small program to test your class and its functions