Ask Question
11 March, 18:27

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.

+2
Answers (1)
  1. 11 March, 20:10
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers