Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(C++) Please reserve the main function for calling other functions. Write a function readRatings that loads user ratings by reading the ratings.txt file. The first

(C++) Please reserve the main function for calling other functions. 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:

image text in transcribed

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.

Use the split() - function from below, with comma (,) as the delimiter.

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.

Split Function:

int split (string str, char character) { if (str.length() == 0) { return 0; } string word = ""; int j = 0; str = str + character; for (int i = 0; i

books.txt:

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 Jay Asher,Thirteen Reasons Why Isaac Asimov,Foundation Series Ann Brashares,The Sisterhood of the Travelling Pants Libba Bray,A Great and Terrible Beauty Dan Brown,The Da Vinci Code

...

~LIST KEEPS GOING FOR 50 BOOKS~

ratings.txt ritchie, 3,3,3 stroustrup, 0,4,5 gosling, 2,2,3 rossum, 5,5,5 0) Did not read Hell no - hate it!! Don't like it. Meh - neither hot nor cold Liked it! Mind blown - Loved it! 2 4 ratings.txt ritchie, 3,3,3 stroustrup, 0,4,5 gosling, 2,2,3 rossum, 5,5,5 0) Did not read Hell no - hate it!! Don't like it. Meh - neither hot nor cold Liked it! Mind blown - Loved it! 2 4

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Development Of Knowledge Framework For Affective Content Analysis

Authors: Swarnangini Sinha

1st Edition

B0CQJ13WZ1, 979-8223977490

More Books

Students also viewed these Databases questions