Question: Write a class User that has the following private data members: a string name that uniquely identifies a user an array ratings that can hold

Write a class User that has the following private data members:

a string name that uniquely identifies a user

an array ratings that can hold 100 integers. Ratings must be one of the values in the chart below.

an integer numRatings for the number of ratings in the ratings array. This will correspond with the total number of books.

Write a class User that has the following private data members: a

Write a public constructor for the class that takes as parameters a name, an array of integers userRatings, and an integer numberRatings, and creates a new user object. Each rating in the userRatings array should be copied into the user's ratings array starting at ratings[0].

I should be able to create a new user by doing the following:

int user1Ratings[] = {0, 1, 3, -1, 0, -5, -3}; User user1 = User("Vipra", user1Ratings, 7);

Write a default constructor for the class that takes no parameters and creates a new user object with a name "NONE", an array ratings of 0s, and a numRatings of 0.

Write a getter and setter for name, named getName, setName respectively.

Write a getter and setter for numRatings named getNumRatings, setNumRatings respectively.

For the data member ratings you will need to write your methods a bit differently since it is not possible to return an entire array. Write the following functions:

getRatingAt which takes a single integer parameter for the index and returns the rating at that index. If the index is greater than or equal to numRatings return -1000.

setRatingAt a function which takes two parameters in this order:

the position at which to add the rating

the rating

This function should set the rating at the position to the new rating.

If the position is greater than or equal to numRatings keep the existing rating and return -1000.

We want to prevent users from entering ratings that aren't -5, -3, 0, 1, 3, or 5. If setRatingAt is called with an invalid rating, print "Invalid Input!" and return -1. Otherwise, print "Success!" and return 0 to indicate success.

Given the example above, I should be able to get ratings of book at index 2 for user1:

cout

OUTPUT:

3

and set ratings for the user:

string name that uniquely identifies a user an array ratings that can

OUTPUT:

hold 100 integers. Ratings must be one of the values in the

Code from previous question:

class Book{ private: string title,author;

public: Book(){ title = author = "NONE"; } Book(string t, string a){ title = t; author = a; } void setTitle(string t){ title = t; } string getTitle(){ return title; } void setAuthor(string s){ author = s; } string getAuthor(){ return author; } };

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!