Question: Write a function readRatings that performs a similar task on the user ratings file. Each username represented in ratings.txt is followed by list of integers--ratings
Write a function readRatings that performs a similar task on the user ratings file. Each username represented in ratings.txt is followed by list of integers--ratings of each book in books.txt. Rating Meaning
0 Did not read
1 Hell No - hate it!!
2 Dont like it.
3 Meh - neither hot nor cold
4 Liked it!
5 Mind Blown - Loved it!
Your function should:
Accept six arguments in this order: string: the name of the file to be read string array: usernames 2D int array: list of ratings for each user (first index specifies user) int : number of users currently stored in the arrays int: row capacity of the 2D array (convention: array[row][column]) [assume to be 100] int: column capacity of the 2D array [assume to be 50]
Use ifstream, stringstream, and getline to read and parse data from the file, placing usernames in the usernames array and book ratings in the ratings array (stoi will also be useful here) Print the username of each user as they are added to the system cout << username << "..." << endl;
Return the total number of users in the system, as an integer.
If the file cannot be opened, return -1
ratings.txt Example:
jennifer,4 4 1 5 0 1 3 2 3 3 1 0 5 4 1 3 0 1 1 4 3 0 3 3 2 4 1 4 5 2 5 2 3 0 1 0 3 2 4 4 4 1 4 5 3 1 4 3 0 4 keith,2 2 0 1 2 1 4 2 3 4 0 5 3 0 1 2 5 1 0 0 3 0 1 2 5 3 1 3 3 2 3 4 2 0 2 1 4 0 3 4 4 4 5 4 2 1 2 1 4 3 sandra,1 4 3 2 1 2 5 2 2 2 0 4 4 4 5 2 4 2 1 5 2 0 1 3 5 3 0 5 1 0 2 2 5 2 2 3 3 2 4 3 0 4 3 0 4 2 1 3 3 4 rebecca,4 2 2 1 0 2 5 1 4 2 0 4 2 1 1 3 0 3 2 4 1 0 1 5 3 2 2 1 2 2 2 3 3 2 0 1 2 3 5 2 3 0 1 5 2 3 4 5 1 1 benjamin,4 5 3 0 5 1 3 4 1 2 0 5 2 3 0 0 5 3 0 4 1 3 3 4 1 3 1 0 3 0 4 1 4 1 1 1 4 2 3 0 5 1 5 0 2 0 3 2 1 2 jacqueline,3 4 0 1 2 1 2 0 2 2 2 0 3 3 3 1 4 0 1 0 2 2 3 5 3 3 1 4 2 3 3 4 3 3 4 3 2 4 2 3 1 4 4 5 4 2 2 3 3 4
books.txt Example:
Douglas Adams,The Hitchhiker's Guide To The Galaxy Richard Adams,Watership Down Mitch Albom,The Five People You Meet in Heaven Laurie Halse Anderson,Speak Maya Angelou,I Know Why the Caged Bird Sings
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
