174k views
4 votes
Write a printAllBooks function to display the contents of your library. This function should:

Have two parameters in this order:
array books: array of Bookobjects.
int: number of books in the array (Note: this value might be less than the capacity of 50 books)
This function does notreturn anything
If the number of books is 0 or less than 0, print "No books are stored"
Otherwise, print "Here is a list of books" and then each book in a new line

1 Answer

0 votes

Answer:

void printAllBooks(Book [] listOfBooks, int numberOfBooks){

bool flag = false;

if(numberOfBooks == 0){

cout<< "No books are stored";

} else{

cout<< "Here is a list of the books \\";

for (int i =0; i < numberOfBooks; ++i){

cout<< listOfBooks[i];

}

}

}

Step-by-step explanation:

The void keyword in the "printAllBooks" function is used for a function that has no return statement. The function accepts two parameters, "listOfBooks" which is the array of book objects, and "numberOfBooks" which is the size of the array of objects. The function uses a for loop statement to print out the book in the array if the numberOfBooks variable is greater than zero.

User Mark Mercurio
by
4.5k points