简体   繁体   English

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

[英]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.

相关问题 C++,当您需要导入它们的定义时,在 header 文件中使用 function 原型有什么意义? - C++, What's the point of using function prototypes in a header file when you need to import their definitions anyways? 使用参数的getter之一来设置C ++函数中另一个参数的值? - Using one of the parameter's getter to set the value of another parameter in a C++ function? C ++函数原型? - C++ function prototypes? C ++函数原型 - C++ function prototypes 如何在一个文件中用C ++定义一个函数并在另一个文件中调用它? - How to define a function in C++ in one file and call it in another one? C ++:无法将泛型函数作为参数传递给另一个函数 - C++ : Can't pass generic function to another one as a parameter 将一个函数的输出作为输入分配给另一个 C++ - Assignin the output of a function as an input to another one c++ 在C ++中将一个函数的返回值用作另一个函数的参数 - using the return value of one function as an argument in another function in c++ C ++-在一个函数/文件中初始化变量然后在main()/另一个文件中使用变量的最佳方法是什么? - C++ - what's the best way to initialize a variable in one function/file and then use it in main()/another file? 功能文档重复在C ++头文件中的原型 - > Doxygen - Function documentation duplicated on prototypes in C++ header files -> Doxygen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM