← Back to STL Containers
Question 570
Countdown Range Class
Countdown Range Class
Create a classCountdownwith: 1. A constructorCountdown(int n)that storesn. 2. A public nested classIteratorthat holds an intcurand provides exactly these members: - a constructorIterator(int value); -int operator*() constreturningcur; -Iterator& operator++()that DECREMENTScurby 1 and returns*this; -bool operator!=(const Iterator& other) constreturning true when the twocurvalues differ. 3.Iterator begin() constreturning anIteratorwhosecurisn. 4.Iterator end() constreturning anIteratorwhosecuris 0. Your class prints nothing itself — the hidden test does all the printing. The first test runsfor (int x : Countdown(5)), printing each value followed by a space and then a newline, so the line is5 4 3 2 1. The second test walksCountdown(3)with an explicitCountdown::Iteratorloop, printing3 2 1on one line and thenSum: 6on 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
Sign in to use hintsTopics:
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.