You are on page 1of 1

Object Oriented Programming

Fall 09
Assignment 2

Define a class EvenCounter to implement an integer even counter. This class should have
only one private data member of type int* (i-e int *count). Even integer Counter would
be incremented by 2 on every increment operation. Similarly decrement would also be of
2 every time. Overload following operators for this Counter.
Arithmetic operators:
++ (pre and post increment operators)
- - (pre and post decrement operators)
+ (Addition)
- (Subtraction)
* (Multiplication)
/ (Division)
= (Assignment)
Assignment operator with arithmetic operators mentioned above (i-e += , - = , *= , /=)
Relational operators:
<
>
<=
>=
==
!=

Insertion(<<) and Extraction(>>) operators. [Bonus part]

Sample functionality of EvenCounter

void main( ) {
EvenCounter c1 (10);
c1.Display( ); //10
EvenCounter c2;
c2++;
c2.Display( ); //2
c2 += c1;
c2.Display( ); //12
c1.Display( ); //10
EvenCounter c3 = ++c1;
c3.Display( ); //12
c1.Display( ); //12
}
[Note: This code of main method is just provided as sample. Do not consider that you
have to provide this functionality only]

Object Oriented Programming Fall-09 Assignment 2 Page 1 of 1

You might also like