CJCoding With Joseph
15free / daySign inCreate account

HoldQueue -= Shifts the Rest Left

Book and most of HoldQueue are written for you: the queue keeps the ADDRESSES of books in a const Book** array it owns, operator+= already appends an address, and the destructor releases the array only. Write HoldQueue& operator-=(const Book& book):

- search the array for the address of book; if it is not there, do nothing
- if it is found at index idx, move every address after idx one slot to the left and reduce the count by one
- return *this

You may keep the existing array and just lower the count, or allocate a smaller array (nullptr when the count reaches 0) and release the old one; both must pass the leak check. Never delete a book.

The driver reads n books (at least two) and adds them all, then removes the second book, removes a book that was never queued, removes the first book, printing the queue after each step, and finally removes everything that is left and prints once more.

For the input:
``
3
101 3 The Hobbit
102 1 Dune
103 2 Emma
``

the exact output is what is shown in Expected Output.

Free the memory you allocate — this question checks for memory leaks.

Do NOT write a main function.

Expected Output:

Holds (2)
#101 The Hobbit x3
#103 Emma x2
Holds (2)
#101 The Hobbit x3
#103 Emma x2
Holds (1)
#103 Emma x2
Holds (0)

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
PointersOperator Overloading
📥 Auto-Input:
3\n101 3 The Hobbit\n102 1 Dune\n103 2 Emma\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.