Practice ยท 1 of 3
A class with an invariant
Implement class BoundedCounter with a private int value_{0}; and private int max_;, a constructor BoundedCounter(int max) that stores max (assume positive), void increment() that increments unless doing so would exceed max, and int value() const / int max() const getters.
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Classes, constructors, invariants