← Back to Pointers
Question 730
HoldQueue -= Shifts the Rest Left
HoldQueue -= Shifts the Rest Left
Bookand most ofHoldQueueare written for you: the queue keeps the ADDRESSES of books in aconst Book**array it owns,operator+=already appends an address, and the destructor releases the array only. WriteHoldQueue& operator-=(const Book& book): - search the array for the address ofbook; if it is not there, do nothing - if it is found at indexidx, move every address afteridxone slot to the left and reduce the count by one - return*thisYou may keep the existing array and just lower the count, or allocate a smaller array (nullptrwhen the count reaches 0) and release the old one; both must pass the leak check. Neverdeletea book. The driver readsnbooks (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
Sign in to use hintsTopics:
PointersOperator Overloading
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.