Tally Class with a unique_ptr Member
mediumQuestion 709Write a class named Tally that keeps its running total in an int on the heap, owned by a private std::unique_ptr<int> member. Give it:
- Tally(int start) — allocates the heap int with make_unique and stores start in it.
- void add(int n) — adds n to the owned total.
- int value() const — returns the owned total.
Do NOT write a destructor, do NOT write new or delete, and do NOT write a main function — the tests provide one. The test reads a starting total and a step, then prints the total three times: as built, after one add, and after a second add.
For the input 5 3 the program prints exactly the output shown in Expected Output.
Expected output
start: 5 after one: 8 after two: 11
= newline. The output ends with a newline, so print one after the last line.
Hints4 available
Sign in to use hintsTopics
Pointers
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.