CJCoding With Joseph
15free / daySign inCreate account

Countdown Range Class

Create a class Countdown with:
1. A constructor Countdown(int n) that stores n.
2. A public nested class Iterator that holds an int cur and provides exactly these members:
   - a constructor Iterator(int value);
   - int operator*() const returning cur;
   - Iterator& operator++() that DECREMENTS cur by 1 and returns *this;
   - bool operator!=(const Iterator& other) const returning true when the two cur values differ.
3. Iterator begin() const returning an Iterator whose cur is n.
4. Iterator end() const returning an Iterator whose cur is 0.

Your class prints nothing itself — the hidden test does all the printing. The first test runs for (int x : Countdown(5)), printing each value followed by a space and then a newline, so the line is 5 4 3 2 1. The second test walks Countdown(3) with an explicit Countdown::Iterator loop, printing 3 2 1 on one line and then Sum: 6 on the next.

Do NOT write a main function.

Expected Output:

5 4 3 2 1
3 2 1
Sum: 6

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
STL ContainersIterators
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.