Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ I need help redoing some code We now update the getRating function from last week to use these arrays of User and Book objects

C++ I need help redoing some code

We now update the getRating function from last week to use these arrays of User and Book objects , to search for a particular users rating for a particular book title. Write a function that, given a users name and a books title, returns the rating that the user gave for that book.

  • Your function MUST be named getRating.

  • Your function should take 6 input arguments in the following order:

    • string: username

    • string: title of the book

    • Array of User objects: users

    • Array of Book objects: books

    • int: number of users currently stored in the users array

    • int: number of books currently stored the books array

  • The username and book title search should be case insensitive. Ben, ben and BEN are one and the same user.

  • If both the user name and the book title are found in the arrays, then the function should return the users rating value for that book title.

  • The function should return the following values depending on cases:

    • Return the rating value if both user and title are found

    • Return -3 if the user or the title are not found

USER.H

class User { private : string username; // make private vairbales const static int size = 50; // make it so vairbale does cange int ratings[size]; int numRatings; public : User (); User (string username, int ratings[], int numRatings); string getUsername(); void setUsername(string); int getRatingAt (int); bool setRatingAt (int, int); int getNumRatings(); void setNumRatings (int); int getSize (); };

USER.cpp

User::User() // calls the default constructor { username = ""; // makes a emputy string numRatings = 0; // makes numratings = 0 for (int i = 0; i < size; i++) { ratings [i] = 0; // makes the ratings array become 0 } }

User::User(string inputname, int inputratings[],int inputnumrating) // calls the function from Class User { username = inputname; numRatings = inputnumrating; for (int i = 0; i < size; i++) { ratings[i] = 0; } for (int i = 0; i < numRatings; i ++) { ratings[i] = inputratings[i]; // makes the rating array equal to inputratings array } }

string User::getUsername() // calls the function from Class User { return username; }

void User::setUsername(string inputname) // calls the function from Class User { username = inputname; }

int User::getRatingAt(int index) // calls the function from Class User { int rate = 0; if (index >= size) // if index is greather than or equal to size { return -1; } if (index < size) // if index is less than size { rate = ratings[index]; return rate; } }

bool User::setRatingAt(int index, int val) // calls the bool function from Class User { bool value; // bool value

if ((val >= 0 && val <= 5) && (index < size && index >= 0)) // make sure both statements are true { ratings[index] = val; value = true; } else { value = false; } return value; }

int User::getNumRatings() // calls the function from Class User { return numRatings; }

The other.cpp this needs to be edited

int getRating(string username, string titleBook, string users[], string titles[], int ratings[][50], int numusers, int numbooks) { int b; int l; for (int i = 0; i < numusers; i++) { if (users[i].length() == username.length()) // {

for (b = 0; b < username.length(); b++) { if (tolower(username[b]) != tolower(users[i][b])) { break; } } if (b == username.length()) { for (int a = 0; a < numbooks; a++) { if (titles[a].length() == titleBook.length()) {

for (l = 0; l < titleBook.length(); l++) { if (tolower(titleBook[l]) != tolower(titles[a][l])) { break; } } if (l == titleBook.length()) { return ratings[i][a]; } } } } } } return -3; // return -3 }

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

Visualizing Health And Healthcare Data Creating Clear And Compelling Visualizations To See How Youre Doing

Authors: Katherine Rowell ,Lindsay Betzendahl ,Cambria Brown

1st Edition

1119680883, 978-1119680888

More Books

Students also viewed these Databases questions

Question

What does it mean to isolate the technical core of a business?

Answered: 1 week ago