Question: C++ ONLY Write a function readRatings that loads user ratings by reading the ratings.txt file. The first value of each line in ratings.txt is the
C++ ONLY
Write a function readRatings that loads user ratings by reading the ratings.txt file. The first value of each line in ratings.txt is the username. Each username is followed by a list of ratings of the user for each book in books.txt.
For example let us say there are in total 3 books. The ratings.txt file would be of the format:

Your function should:
-
Accept six arguments in this order:
-
string: the name of the file to be read
-
Array of string: users
-
2 dimensional int array: ratings - list of ratings for each user.The number of rows corresponds to the number of users, and the number of columns corresponds to the number of books.
-
int: numUsers number of users currently stored in the arrays
-
int: maxRows maximum number of rows of the ratings 2D array (convention: array[row][column]) [assume to be 100]
-
int: maxColumns maximum number of columns of the ratings 2D array [assume to be 50]
-
-
Use ifstream and getline to read data from the file, placing each username in the users array, and each set of ratings in a row of the ratings 2D array.
-
Hint: You can use the split() - function from problem 3, with comma (,) as the delimiter. When you copy your code in the answer box on Moodle Coderunner, make sure you put both the functions readRatings and split.
-
You can use stoi to convert each rating value (a string, as read from the text file) into an integer value.
-
The function should return the following values depending on cases:
-
Return the total number of users in the system, as an integer.
-
If the file cannot be opened, return -1
-
When numUsers is equal to the maximum number of rows in the ratings 2D array, return -2
-
When numUsers is smaller than the maximum number of rows in the ratings 2D array, keep the existing elements in users array and ratings array, then read data from file and add (append) the data to the arrays. The number of users stored in the arrays cannot exceed the size of the arrays.
-
Empty lines should not be added to the arrays.
-
Example 1: The users and ratings arrays are empty, so numUsers is 0.


Example 2: The authors and titles arrays are empty, so numBookStored is 0 and a bad file is given
Example 3: The users and ratings arrays are full, so readRatings returns -2.
Example 4: There is already 1 user in the users array, so the value of numUsers is 1. However, the array size is only two, so only the first line of the file is stored and the function returns the size of the array.

Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
