← Back to Pointers
Question 709
Tally Class with a unique_ptr Member
Tally Class with a unique_ptr Member
Write a class namedTallythat keeps its running total in aninton the heap, owned by a privatestd::unique_ptr<int>member. Give it: -Tally(int start)— allocates the heap int withmake_uniqueand storesstartin it. -void add(int n)— addsnto the owned total. -int value() const— returns the owned total. Do NOT write a destructor, do NOT writenewordelete, and do NOT write amainfunction — the tests provide one. The test reads a starting total and a step, then prints the total three times: as built, after oneadd, and after a secondadd. For the input5 3the 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 — 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.