Question
C++ Create a User class, with a separate interface (User.h) and implementation (User.cpp), comprised of the following attributes: Data members (private): string: username int array:
C++
Create a User class, with a separate interface (User.h) and implementation (User.cpp), comprised of the following attributes:
Data members (private): | |
string: username | |
int array: ratings | Number of elements should be size |
int: numRatings | Number of books in the database |
Int: size | The capacity of the ratings array (50). Constant |
Member functions (public): | |
Default constructor | Sets username to an empty string, numRatings to 0, size to 50, and all the elements of ratings array to the value 0 |
Parameterized constructor | Takes a string, an array of integers, and one integer for initializing username, ratings, and numRatings, respectively. Make sure the value passed into the constructor for numRatings does not exceed the value of the data member size |
getUsername() | Returns username as a string |
setUsername(string) | (void) Assigns username the value of the input string |
getRatingAt(int) | Parameter: int index. Returns the rating stored at the specified index. If index is larger than the size of the ratings array, returns -1. |
setRatingAt(int,int) | Parameters: int index, int value. Sets the rating to value at the specified index, if index is within the bounds of the array and value is between 0 and 5. Returns a boolean, true if the rating is successfully updated and false otherwise. |
getNumRatings() | Returns numRatings |
setNumRatings(int) | (void) Assigns numRatings the value of the input int |
getSize() | Returns size |
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