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

Must be answered in C++. Write a function called stdev that accepts two paramete

ID: 3762845 • Letter: M

Question

Must be answered in C++.
Write a function called stdev that accepts two parameters and returns a double. There will be no cin/cout statements, just a pure calculation. The first parameter will be a const interger array, and the second parameter will be an integer for the size of the passed array. The function will calculate the standard deviation of all the integers within the array. Remember to use a running total to calculate the sum of all the elements in order to calculate the average, needed for the standard deviation formula.
const int size = 10, nums [size] = {1,2,3,4,5,6,7,8,9,10}; double sd = stdev(nums, size); Must be answered in C++.
Write a function called stdev that accepts two parameters and returns a double. There will be no cin/cout statements, just a pure calculation. The first parameter will be a const interger array, and the second parameter will be an integer for the size of the passed array. The function will calculate the standard deviation of all the integers within the array. Remember to use a running total to calculate the sum of all the elements in order to calculate the average, needed for the standard deviation formula.
const int size = 10, nums [size] = {1,2,3,4,5,6,7,8,9,10}; double sd = stdev(nums, size);
Write a function called stdev that accepts two parameters and returns a double. There will be no cin/cout statements, just a pure calculation. The first parameter will be a const interger array, and the second parameter will be an integer for the size of the passed array. The function will calculate the standard deviation of all the integers within the array. Remember to use a running total to calculate the sum of all the elements in order to calculate the average, needed for the standard deviation formula.
const int size = 10, nums [size] = {1,2,3,4,5,6,7,8,9,10}; double sd = stdev(nums, size); Write a function called stdev that accepts two parameters and returns a double. There will be no cin/cout statements, just a pure calculation. The first parameter will be a const interger array, and the second parameter will be an integer for the size of the passed array. The function will calculate the standard deviation of all the integers within the array. Remember to use a running total to calculate the sum of all the elements in order to calculate the average, needed for the standard deviation formula.
const int size = 10, nums [size] = {1,2,3,4,5,6,7,8,9,10}; double sd = stdev(nums, size);

Explanation / Answer

double stddev(const int *arr,const int size)

{

double mean=0.0, sum_deviation=0.0;

int i;

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

{

mean+=arr[i];

}

mean=mean/size;

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

sum_deviation+=(arr[i]-mean)*(arr[i]-mean);

  

return sqrt(sum_deviation/size);

}