In c++, Define a class
counterType
to implement a counter. Your class must have a private data member counter
of type int
. Define a constructor that accepts a parameter of type int
and initializes the counter
data member. Add functions to:
- Set
counter
to the integer value specified by the user. - Initialize
counter
to 0. - Return the value of counter with a function named
getCounter
. - Increment and decrement counter by one.
- Print the value of counter using the
print
function.- Example output:
Counter = 0
.
- Example output:
The value of counter must be nonnegative.
Task 1: Included the private member variable counter
Task 2:
counterType
‘s getCounter
returns the value of counter
Task 3: counterType
‘s incrementCounter
increments the value of counter
Task 4: counterType
‘s decrementCounter
decrements the value of counter
Task 5: counterType
‘s print
prints the value of counter
Requirements: