Using C write a group of functions to find the Standard Devi

Using C++ write a group of functions to find the Standard Deviation for a set of ungrouped population data. The Standard Deviation is the square root of the variance, The formula for the standard deviation is in your text. This function should call a separate function that finds the average. Another function should be called to find the Variance. Use the examination scores from an earlier exercise that appears in Part 1.

Solution

// C++ code

#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <set>
#include <vector>
#include <map>
#include <algorithm>
#include <utility>
#include <ctime>
#include <limits.h>

using namespace std;

float calculateAverage(float data[], int size)
{
   float mean;
   float sum = 0.0;
   for(int i = 0; i < size; ++i)
{
sum = sum + data[i];
}

mean = sum/size;

return mean;  
}

float calculateVariance(float data[], int size)
{
   float variance = 0.0;
   float mean = calculateAverage(data,size);
   for(int i = 0; i < size; ++i)
variance = variance + pow(data[i] - mean, 2);

return variance/size;
}

float calculateSD(float data[], int size)
{
float variance;
variance = calculateVariance(data,size);

return sqrt(variance);
}

int main()
{
   int size;
   cout << \"Enter data size: \";
   cin >> size;

int i;
float data[size];

cout << \"Enter \" << size << \" elements: \";
for(i = 0; i < size; ++i)
cin >> data[i];

cout << endl << \"Standard Deviation = \" << calculateSD(data,size) << endl;

return 0;
}


/*
output:

Enter data size: 10
Enter 10 elements: 1 2 3 4 5 6 7 8 9 10

Standard Deviation = 2.87228

*/

Using C++ write a group of functions to find the Standard Deviation for a set of ungrouped population data. The Standard Deviation is the square root of the var
Using C++ write a group of functions to find the Standard Deviation for a set of ungrouped population data. The Standard Deviation is the square root of the var

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site