Ask Question
7 September, 15:46

Write the definition of a function named averager that receives a double parameter and return- - as a double - - the average value that it has been passed so far. So, if you make these calls to averager, averager (5.0), averager (15.0), averager (4.3), the values returned will be (respectively) : 5.0, 10.0, 8.1. Hint: use a static local variable to track the average of all the numbers been called.

+3
Answers (1)
  1. 7 September, 15:54
    0
    Following are the definition of function

    double averager (const double &x) / / function definition

    {

    static double z = 0.0; / / variable declaration

    static size_t c = 0;

    c=c+1; / / increment of c by 1

    z = z + x; / / adding value

    return z / c; / / return average

    }

    Explanation:

    Following are the description of statement

    Create a function averager of double type that holds a parameter "x" of the double type. In this function we declared a variable "z" of a static double type that value is initialized by 0. The static variable is used to retain value. Declared a variable "c" of size_t type that holds a value 0. After that increment the value of c by 1. adding the value of "z" variable to the "x" and storing the result into the z variable. Finally return the average value
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write the definition of a function named averager that receives a double parameter and return- - as a double - - the average value that it ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers