Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a recursive function called Deviation which passes array A and Dev as arrays with size n and average, a floating point, as two
Write a recursive function called Deviation which passes array A and Dev as arrays with size n and average, a floating point, as two other parameters. The function calculates the deviation (not standard deviation), that is the difference between an element and average, for each element and stores the deviation in array Dev[]. Both negative and positive differences are acceptable. Use the average function below in 5 to calculate average and pass it as input for the last parameter. The function declaration (or signature) is: void Deviation (int A[], double Dev[], int n, double average) To help the function Deviation function use or pass the average value, write a function called average which passes an array A, the size n, the size which is constant and the accumulating sum which is already set to 0 to begin with. The function uses tail recursion approach to calculate the average as floating-point and returns it. You must typecast the calculation into floating-point when calculating. The function declaration is: double average (int A[], int n, const int size, int sum = 0) Recursive algorithm carries full weight for this while iterative algorithm carries NO weight. The iterative function declaration passes only two parameters, the array A and its size n. Implement this function temporarily, only to support the operation of function in activity 4 but no marks will be awarded. To get marks, implement the recursive method. Average function using recursive algorithm can be done successfully as tail recursion. In the main function, use the same array names as those of part A with different types where A stores integers and B stores floating-point numbers. Using the functions, determine the deviations of each element from the mean, then display the differences from array B. A = {7, 2, 3, 8, 4} B = {0}
Step by Step Solution
★★★★★
3.55 Rating (152 Votes )
There are 3 Steps involved in it
Step: 1
Heres the implementation of the required functions in C include using namespace std double average i...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started