Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Implement a handy statistical function. The function takes in an integer array o

ID: 3721342 • Letter: I

Question

Implement a handy statistical function. The function takes in an integer array of a certain size and then for the elements does the following: subtracts the average of all the elements from element 1, subtracts the average of all elements from element 2, …, subtracts the average of all elements from element n. The function has the following signature: void diffAverage(int inputArray[], int size) From our example of asciiArray, { 74, 79, 78, 80, 68, 79, 69 }, the integer average of all the elements is 75 [(74 + 79 + 78 + 80 + 68 + 79 + 69) / 7], and the function will change the array to: { -1, 4, 3, 5, -7, 4, -6 }

I need C++ coding

Thanks

Explanation / Answer

package Chegg;

public class ArrayAv {

/* The function takes in an integer array of a certain size and then

for the elements does the following: subtracts the average of all

the elements from element 1, subtracts the average of all elements from element 2, …,

subtracts the average of all elements from element n.*/

public static void diffAverage(int inputArray[], int size)

{

int sum=0;

int avg;

//find sum of all array

for(int i =0 ;i <size;i++)

{

sum = sum + inputArray[i];

}

avg=sum/size;

//subtracts the average of all elements from element

for(int i =0 ;i <size;i++)

{

inputArray[i]=inputArray[i]-avg;

}

}

//main method

public static void main(String[] args) {

int asciiArray[]= { 74, 79, 78, 80, 68, 79, 69 };

for(int i =0 ;i <asciiArray.length;i++)

{

System.out.print(asciiArray[i] + " ");

}

//calling diffAverage method

diffAverage(asciiArray,asciiArray.length);

System.out.println(" After diffAverage function");

for(int i =0 ;i <asciiArray.length;i++)

{

System.out.print(asciiArray[i] + " ");

}

}

}

----------------------------

output sample:-

74 79 78 80 68 79 69
After diffAverage function
-1 4 3 5 -7 4 -6

---------------------------------------------------------------------------------------------

If you have any query, please feel free to ask.

Thanks a lot.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote