HoldQueue -= Shifts the Rest Left
mediumQuestion 730Book 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 Emmathe 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, so print one after the last line.
Your output
Run your code to see the output here...