Countdown Range Class
hardQuestion 570Create 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, so print one after the last line.
Your output
Run your code to see the output here...