Ask Question
17 October, 08:04

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.

+1
Answers (1)
  1. 17 October, 11:14
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers