[英]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. 我不确定如何将函数averageRating(...)的返回值用于下一个函数preferenceFactor(...)进行除法。 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")
}
Can't you use averageRating() as an argument in preferanceFactor(), so that the preferanceFactor has 2 arguments? 您不能使用averageRating()作为preferanceFactor()中的参数,以便preferanceFactor有2个参数吗?
virtual double preferanceFactor(double avrRating, double genAvrRating);
and then when calling prefFact you pass in the averageRating(x,y) as first arg? 然后在调用prefFact时,将averageRating(x,y)作为第一个arg传入? Is that acceptable?
可以接受吗?
Or you can just pass 3 arguments (2 just as averageRating arguments, and 3rd is genAvRate. 或者,您可以只传递3个参数(其中2个作为averageRating参数,而3rd是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? 然后在prefFact函数中,为第一个两个参数调用averageRating()?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.