Question: create a function calcAvgRating that returns the average (mean) rating for a particular book. This function should: Accept five arguments in this order: string: book

create a function calcAvgRating that returns the average (mean) rating for a particular book. This function should:

Accept five arguments in this order:

string: book title for which you want the average rating

string array: titles

2D int array: list of ratings for each user (same comment here)

int: number of users in the arrays

int: number of books accounted for in the 2D array

Return the average rating of the specified book as a double

If the program has not read ratings.txt or books.txt, it must read it first before executing this function. In this case, return -1 after printing the following message:

cout << bookTitle << " does not exist in the database" << endl;

If instead the database is initialized but the book is not found, return -1 after printing the following message:

cout << bookTitle << " does not exist in the database" << endl;

Highly recommend: Write a helper function that searches the titles array for a particular book and returns its index.

Note: If the user has not reviewed the book it should not be added while calculating the average.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!