The standard deviation of a list of numbers is a measure of how much the numbers deviate from the average If the standard deviation is small, the numbers are clustered close to the average If the standard deviation is large, the numbers are scattered far from the average. The standard deviation, S, of a list of N numbers x_i is defined as follows: S = squareroot sigma^N_i = 1(x_i - x^bar)^2/N where x^bar is the average of the N numbers x_1, x_2, ... x_N. Define a function that takes a partially filled array of numbers as its argument and returns the standard deviation of the numbers in the partially filled array Since a partially filled array requires two arguments, the function will actually have two formal parameters an array parameter and a parameter of type int that gives the number of array positions used The numbers in the array will be of type double Embed your function in a suitable driver program Your driver program must test this function on an array of randomly generated double values in the range 0 to 1 and the number of elements in the array can range anywhere from 1 to 2000 The user will input the number of elements in the array To generate a random number of type double in the range 0 to 1, refer to your textbook, pages 101-102 Recall that in Lab Problem 3, you wrote a function to compute the standard deviation of 4 scores For this homework problem, your function should be able to compute the standard deviation of A numbers where N can be any value specified by the user in the range 1-2000.
#include <iostream>
#include <cmath>
using namespace std;
double std_Dev (double Nums[], int inSize, double &avg, double &sum, double&sum2);
int main ( ){
int inSize;
double avg = 0, sDev, sum = 0, sum2 = 0;
cout << \"How many Numbers would you like to find the standard deviation for (max 2000):\";
cin >> inSize;
double Nums[inSize];
cout << \"\ Input the numbers hit enter after each entry:\";
for ( int i = 0; i < inSize; i++ ){
cin >> Nums[i];
}
sDev = std_Dev(Nums, inSize, avg, sum, sum2);
cout << sum<<\" \"<<inSize<<\" \"<<avg<<\" \"<<sDev<<endl;
return 0;
}
std_Dev (double Nums[], int inSize, double &avg, double &sum, double &sum2){
for ( int i = 0; i < inSize; i++ ){
sum += Nums[i];
}
avg = sum / inSize;
for ( int i = 0; i < inSize; i++ ){
sum2 += pow( Nums[i] - avg, 2 );
}
double sDev;
sDev = sqrt( sum2 / ( inSize - 1 ) );
return sDev;
}