Write a recursive function called Deviation which passes array A and Dev as arrays with size...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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} 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}
Expert Answer:
Answer rating: 100% (QA)
Heres the implementation of the required functions in C include using namespace std double average i... View the full answer
Related Book For
Introduction To Computing And Programming In Python A Multimedia Approach
ISBN: 9780134025544
4th Edition
Authors: Mark J. Guzdial, Barbara Ericson
Posted Date:
Students also viewed these programming questions
-
In governmental accounting, what is the difference between an acquisition and a merger?
-
In a statistical study what is the difference between an individual and a variable?
-
What is the difference between an element and a compound?
-
Evaluate the limit or state that it does not exist. lim (x,y) (1,-3) In(3x + y)
-
How can personal selling be used to build long-term customer relationships?
-
Choose and discuss one issue concerning privacy or misuse of technology that can arise in probation contexts. Please attempt to choose an issue not already under discussion by another classmate, but...
-
Millions of high school graduates decide annually to enroll in a college or university. Many factors can influence a students choice of where to enroll. List the five steps of the decision-making...
-
1. What methods did Smart USA use to test market the Smart Fortwo car among prospective customers? 2. What trends are influencing the market potential of the Smart Fortwo car? 3. How does Smart USA...
-
A5.21 A multithreaded web server wishes to keep track of the number of requests it services (known as hits). Consider the two following strategies to prevent a race condition on the variable hits....
-
Suppose that there are p = 4 quality characteristics, and in correlation form all four variables have variance unity and that all pairwise correlation coefficients are 0.9. The in-control value of...
-
For cost reduction purpose and when the management asks the supervisor to contribute, the successful supervisor needs to be managerially competent True False
-
In the graph, the initially the aggregate supply curve is SAS, and the aggregate demand curve is ADO Some events change aggregate demand from AD, to AD. Describe two events that could have created...
-
An input signal x (t) = u(t-1)-u(t-3) is applied to an LTI system h (t) = 8(t-2) to give the output y (t). a) (2) Sketch x(t) and h (t). Show important values. b) (2) Use convolution integral to...
-
If Will takes out a loan at 4 . 3 % interest compounded semiannually and pays it off with a payment of $ 1 6 , 7 8 0 . 4 6 after 6 years, what is his loan amount?
-
8) Define n n ||A|| = |arj| i=1 j=1 Show that this is a matrix norm (that is, a norm on the linear space of all n x n matrices). Show that it is not subordinate to any vector norm. Does it conform to...
-
During 2024, its first year of operations, Baginski Steel Corporation reported a net operating loss of $450,000 for financial reporting and tax purposes. During 2025, Baginski reported income of...
-
Jing and Jack have filed for divorce and are dividing their assets. When they married five years ago, Jing had a house valued at $450,000 with a $200,000 mortgage and an RRSP with a market value of...
-
ABC company leased new advanced computer equipment to STU Ltd on 1 January 2019.STULtd has to pay annual rental of $290,000 starting at 1 January 2019. It is a four years lease with ultimate rental...
-
What is the output from the following? >>> a = 3 >>> b = 4 >>> x = a * b >>> print x
-
Write a function that will input two sounds. Create a new sound with one half of the first sound, then add the two sounds together for the length of the two sounds, and then add the second half of...
-
Write a function that treats horizontal thirds of the picture differently. Make the top third of an input picture brighter, then the middle third decrease blue and green by 30%, then the bottom third...
-
How did the Fed hit its target for the federal funds rate in the pre-2008 scarce-reserves regime?
-
Draw a demand and supply graph for the federal funds market to show the demand and supply of reserves in the current ample-reserves regime. How can the Fed increase the federal funds rate? Show the...
-
What is the zero lower bound in monetary policy? What tools can the Fed use if it wants to implement an expansionary monetary policy at the zero lower bound?
Study smarter with the SolutionInn App