Practice · 1 of 3
A class with an invariant
CHALLENGE
Difficulty: intermediate+25 XP
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.
Press Submit to check your solution.
Back to lesson: Practice: Classes, constructors, invariants