The previous stage supplied a safe way to find an actual catalog record. Now a loan operation can use that view to update the record in place. The completed catalog, lookup, label helper, and earlier probes are all retained.
Two small functions express the allowed transitions. Lending changes an available book from false to true. Returning changes a borrowed book from true to false. Both operations return a boolean status: true means the transition happened; false means the request was rejected.
Each helper already looks up its id and checks the current state. In book == nullptr || book->onLoan, logical OR short-circuits: when the pointer is null, the right-hand side is not evaluated. That order rejects a missing id without accessing a nonexistent book. The guards also reject lending an already-borrowed book or returning a book that is already available. Complete only the successful transition after these guards. Assign the new state, then return true. This pair is one operation: the success status must describe a mutation that actually occurred.
The probes create copies named lendingTrial and returnTrial. Copying this vector copies its Book values and strings, so changing a trial does not change catalog. Lending book 101 twice should succeed once and fail once. Returning book 102 twice should do the same. A missing-id request should fail without changing another record.
The printed state after each trial makes the effect visible; checking only a success message would not show whether the stored boolean changed. Keep all previous helpers unchanged. Only the two success paths need edits here. The trial copies let you check the changes without altering the original catalog that the shelf report will use.
Edit main.cpp; the supplied Console probes already call your code.
lendBook by setting onLoan to true and returning true. Expect Lending: true false false | on loan: true.returnBook by setting onLoan to false and returning true. Expect Returning: true false false | on loan: false.Use Run to inspect the Console, then Submit to check your work.