CJCoding With Joseph
15free / daySign inCreate account

Tally Class with a unique_ptr Member

Write 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 — print one after the last line.

Hints4 available
Topics:
Pointers
📥 Auto-Input:
5 3\n
This input is automatically fed to your program's stdin
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.