Question: Would someone be able to break this C++ code down line by line and tell me what each line means? void printBooksByAuthor(std::string titles[], std::string authors[],
Would someone be able to break this C++ code down line by line and tell me what each line means?
void printBooksByAuthor(std::string titles[], std::string authors[], int numBooks, std::string author) {
if (numBooks == 0) { std::cout << "No books are stored" << std::endl; return; }
bool bIsBookFound = false; std::string* foundBooks = new std::string[numBooks]; int cnt = 0; for (int i = 0;i < numBooks;i++) { if (authors[i] == author) { foundBooks[cnt] = titles[i]; cnt++; bIsBookFound = true; } }
if(bIsBookFound) { std::cout << "Here is a list of books by " << author << std::endl; for (int i = 0;i < cnt;i++) std::cout << foundBooks[i] << std::endl; } else { std::cout << "There are no books by " << author; }
delete[] foundBooks; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
