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

时间:2014-05-05 22:14:29

标签: c++ function-prototypes

我不知道如何使用函数averageRating(...)的返回值作为下一个函数,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")
 }

1 个答案:

答案 0 :(得分:0)

你不能在preferanceFactor()中使用averageRating()作为参数,那么preferanceFactor有2个参数吗?

virtual double preferanceFactor(double avrRating, double genAvrRating);

然后在调用prefFact时,你将averageRating(x,y)作为第一个arg传递?那可以接受吗?

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

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

然后在prefFact函数中,你为第一个两个args调用averageRating()?