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 Hint: You can use the split() function that was used during recitation Note: Although user can specify the name of the file to read from, assume the default filename to be ratings.txt
Expected output:
cynthia...
diane...
joan...
barbara...
(etc.)
C++ Only. Here are the text files for books.txt and ratings.txt, as well as the split function, respectively:
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 Meg Cabot,The Princess Diaries Orson Scott Card,Ender's Game Tom Clancy,The Hunt for Red October Suzanne Collins,The Hunger Games F. Scott Fitzgerald,The Great Gatsby John Flanagan,Ranger's Apprentice Series Cornelia Funke,Inkheart William Gibson,Neuromancer William Golding,Lord of the Flies William Goldman,The Princess Bride James Gurney,Dinotopia: A Land Apart from Time Will Hobbs,Far North Alice Hoffman,Practical Magic Aldous Huxley,Brave New World Guy Gavriel Kay,The Summer Tree Daniel Keyes,Flowers For Algernon Patrice Kindl,Owl in Love Masashi Kishimoto,Naruto Tite Kubo,Bleach (graphic novel) Elizabeth Laird,Kiss the Dust Harper Lee,To Kill a Mockingbird C S Lewis,The Lion the Witch and the Wardrobe Robert Ludlum,The Bourne Series Yann Martel,Life of Pi Lurlene McDaniel,Breathless Stephenie Meyer,Twilight Series Garth Nix,Sabriel George Orwell,Nineteen Eighty-Four (1984) Christopher Paolini,Eragon Gary Paulsen,Hatchet Jodi Picoult,My Sister's Keeper Philip Pullman,The Golden Compass J.K. Rowling,Harry Potter Series Louis Sachar,Holes Shueisha,Shonen Jump Series Neil Shusterman,The Shadow Club Jeff Smith,Bone Series Art Spiegelman,Maus: A Survivor's Tale Amy Tan,The Joy Luck Club J R R Tolkien,The Lord of the Rings
cynthia,4 3 1 0 3 0 5 1 5 2 2 2 1 4 4 2 0 1 1 2 3 2 1 1 3 4 1 2 1 3 0 0 3 1 1 3 2 3 1 2 3 4 5 5 0 1 3 2 2 4 diane,3 1 1 0 2 2 3 1 0 1 4 3 1 2 1 1 5 2 4 0 3 2 1 5 4 5 0 2 3 3 5 2 2 1 4 5 2 4 5 2 3 3 5 5 4 1 3 4 2 3 joan,3 1 2 0 2 2 4 3 0 2 2 4 5 2 2 1 4 1 1 3 2 1 3 1 4 1 3 1 5 1 3 5 5 1 3 2 2 5 2 2 0 4 5 0 4 1 2 3 4 2 barbara,4 5 2 0 0 0 0 2 2 1 1 3 3 5 3 3 0 1 1 4 1 2 1 0 2 4 0 1 2 3 3 2 0 3 3 1 4 0 4 5 1 5 5 0 5 1 1 5 5 2 doris,5 3 3 1 0 4 1 1 3 3 4 5 3 3 1 0 0 2 5 5 1 1 0 2 4 3 3 2 2 0 1 4 2 1 0 0 5 1 5 5 2 4 5 0 2 0 3 5 3 0 margaret,2 5 3 1 2 4 0 1 4 5 1 2 5 1 2 0 5 2 1 5 1 1 2 2 2 5 2 4 5 1 5 5 2 1 0 1 2 0 3 0 2 5 3 4 2 2 4 4 5 0 jerry,0 0 3 0 0 1 3 1 3 4 4 5 2 2 1 0 4 1 0 4 4 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 5 4 0 3 1 0 0 1 1 0 2 2 1 5 1 1 4 5 2 4 3 5 5 3 4 1 3 2 2 0 5
int split (string str, char c, string array[], int size) { if (str.length() == 0) { return 0; } string word = ""; int count = 0; str = str + c; for (int i = 0; i < str.length(); i++) { if (str[i] == c) { if (word.length() == 0) continue; array[count++] = word; word = ""; } else { word = word + str[i]; } } return count; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started