Skip to main content

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

Back to lesson: Practice: Classes, constructors, invariants