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

Background The standard deviation (STDDEV) of a list of numbers is a measure of

ID: 3630277 • Letter: B

Question

Background
The standard deviation (STDDEV) of a list of numbers is a measure of how much the numbers
deviate from the average. For example, if the STDDEV is small, the numbers are bunched close to
the average, whereas, if the STDDEV is large, the numbers are scattered far from the average. We define the STDDEV, S, as follows.


Problem

Compute the STDDEV of a set of numbers that are stored in a partially-filled, static bag, then display the result on the standard output with an appropriate annotation


Input

A text file containing space-delimited integers

Output

1. The input values with an appropriate annotation


2. The STDDEV of the input values with an appropriate annotation

Class requirements


1. Use the static bag

2. Overload operator [ ] for the bag class. It will be very handy when computing STDDE

3. Overload operator << for the bag class

Driver

1.Greet the user.

2. Read the data values from a file whose name is input at the command line.

3. Store the values in a static bag.

4. Compute the STDDEV of the values

.5. Display the space delimited values, then display the STDDEV of the values with an annotation



Explanation / Answer

#include<iostream>

#include<fstream>

#include<cmath>

using namespace std;

double Average(double x[],int n);

double standard_Deviation(double x[], double average,int n);

void main()

{

ifstream inputFile;

ofstream outputFile;

double x[100];

double mean,sdeviation;

int i,n;

inputFile.open("input.txt");

if(!inputFile)

cout<<"Error: ";

else

{

inputFile >> n;

}

inputFile.close();

cout<<"Enter values:"<<endl;

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

cin>>x[i];

mean=Average(x,n);

sdeviation=standard_Deviation(x,mean,n);

outputFile.open("Output.txt",ios::out);

cout<<"Now data writing to file ";

outputFile <<mean;

outputFile <<sdeviation;

outputFile.close();

cout<<"Done";

system("pause");

}

double Average(double x[],int n)

{

double m=0;

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

m=m+x[i];

return m/n;

}

double standard_Deviation(double x[],double mean,int n)

{

double sd=0;

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

sd=sd+pow((x[i]-mean),2);

sd=sqrt(sd/n);

return sd;

}