Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Create a User class, with a separate interface (readrating.h) and implementation (readrating.cpp), comprised of the following attributes: We will now update the readRatings from

C++

Create a User class, with a separate interface (readrating.h) and implementation (readrating.cpp), comprised of the following attributes:

We will now update the readRatings from last week to use an array of User objects instead of having a usernames array and a ratings array. The functionality stays the same as the one from last week.

Write a function readRatings that loads the 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

This function should:

  • Accept five arguments in this order:

    • string filename: the name of the file to be read

    • array users: array of User objects

    • int numUsersStored number of users currently stored in the arrays

    • int usersArrSize: capacity of the users arrays. The default value for this data member is 100.

    • int maxCol: maximum number of columns. The default value for this data member is 50.

  • Use ifstream and getline to read data from the file, making an instance of a User object for each line, and placing it in the users array.

  • Hint: You can use the split() - function from Problem 3 in Homework 6, with comma (,) as the delimiter. When you copy your code in the Answer Box on Moodle Coderunner, make sure you copy Users class, readBooks() function, and split() function.

  • 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 numUsersStored is greater than or equal to the usersArrSize, return -2

    • The priority of the return code -2 is higher than -1, i.e., in cases when numUsersStored is equal to the size and the file cannot be opened, the function should return -2

    • When numUsersStored is smaller than the size of users array, keep the existing elements in users 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 users array.

    • Empty lines should not be added to the arrays.

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

Step: 3

blur-text-image

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

More Books

Students also viewed these Databases questions

Question

Organize and support your main points

Answered: 1 week ago

Question

Move smoothly from point to point

Answered: 1 week ago

Question

Outlining Your Speech?

Answered: 1 week ago