Search code examples
c++function-prototypes

C++: using one function's output as a parameter for another one in the header file with function prototypes


I am not sure how I can use the return value of the function averageRating(...) for the next function, preferenceFactor(...) to do the division. Any help is greatly appreciated.

/**
 *Calculates the average rating of movies for a particular genre by the user 'u'
 *Calculated by: (#of movies rated in one genre)/(sum of all the ratings)
 *
 *@param movies is the number of movies in one genre
 *@param sumRatings is sum of the ratings by the user 
 *@return the average rating
 */
 virtual double averageRating(int numberOfMovies, double sumOfRatings) {
    return (numberOfMovies/sumOfRatings);
 }

 /**
  *Calculates the user's "preference factor".
  *Calculated by: (averageRating/generalAverageRating)
  *
  *@param sumOfRatings average rating for the same movie by all users
  *@return the user's preference factor
  */
 virtual double preferenceFactor(double generalAverageRating) {
  return ("averageRating's output(?) divided by generalAverageRating")
 }

Solution

  • Can't you use averageRating() as an argument in preferanceFactor(), so that the preferanceFactor has 2 arguments?

    virtual double preferanceFactor(double avrRating, double genAvrRating);
    

    and then when calling prefFact you pass in the averageRating(x,y) as first arg? Is that acceptable?

    Or you can just pass 3 arguments (2 just as averageRating arguments, and 3rd is genAvRate.

    virtual double preferenceFactor(int numberOfMovies, double sumOfRatings, double generalAverageRating) {
        return averageRating(numberOfMovies, sumOfRatings)/generalAverageRating;
    }
    

    and then in the prefFact funct u call averageRating() for 1st two args?