C++:使用一个函数的输出作为带有函数原型的头文件中另一个函数的参数

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

本文关键字:函数 原型 文件 参数 另一个 输出 C++ 一个      更新时间:2023-10-16

我不确定如何使用函数averating(…)的返回值作为下一个函数preferenceFactor(…)来进行除法。如有任何帮助,不胜感激。

/**
 *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")
 }

不能使用averating()作为preferanceFactor()的参数,以便preferanceFactor有2个参数吗?

virtual double preferanceFactor(double avrRating, double genAvrRating);

,然后当调用prefFact时,你传递的平均值(x,y)作为第一个参数?这可以接受吗?

或者你可以只传递3个参数(2个作为平均参数,第三个是genAvRate。

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

,然后在prefFact函数u调用平均()前两个参数?