Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Q5: Remove book and delete database (20 points) File: Main.cpp (10 points) // Q5

ID: 3707821 • Letter: Q

Question

Q5: Remove book and delete database (20 points) File: Main.cpp (10 points) // Q5a: Implement removeBook() to remove the node that matches name, noOfbooks, andd Library number. Please select one option: a: Add a new book to the database r: Remove a book from the database : Change the available number of books d: Display all books in the database s: Sort the list of books in the database e: Exit and save the database in DB.txt Please enter the book's name: intro to java Please enter the number of books available: 4 Please select the library number: Noble Library ? Hayden Library Book removed from the database 6 l Page CSE220 Programming for Computer Engineering Project 06 File: Main.cpp (10 points) // Q5b: Implement deleteDatabase() to remove all nodes in the list. Make sure no memory leak will occur // This function is already called when exiting the program. You do not need to call it any where else.

Explanation / Answer

void removeBook(string name, int noOfbooks, Library libnumber){

if(list == NULL){
cout << "DB is empty"; //If root is null, then database is empty
}

Container *temp = list; // Assigning root to temp element

while(temp != NULL && temp->next != NULL){ //Last ele is not null
if (temp->next->book->name.compare(name) == 0 && temp->next->book->noOfbooks == noOfbooks && libnumber == temp->next->book->libnumber){
//If all three matches with the next entry
temp->next = temp->next->next; //Deleted the matching entry
}
temp = temp -> next; //Moving to the next node
}
}

void deleteDatabase(){
   if(list == NULL){
cout << "DB is empty"; //If root is null, then database is empty
}

Container *temp = list, *temp; // Assigning root to temp element

while(temp != NULL){
temp1 = temp -> next; // Stroring next node
free(temp); //Freeing the current node
temp = temp1; //Making a copy of next node
}

list = NULL; //Making head as NULL
}

Above code has inline comments.

It is designed based on display database.

It will work as you expected.

Comment with full code if you face any issues.