#include <iostream>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;
const int MAXSIZE = 1000;
/**
* computes the maximum and minimum values in the data set
* @param data - an array containing the measurements
* @param count - the number of measurements
* @param min - the minimum measurement
* @param max - the maximum measurement
*/
void minMax(const double data [ ], int count, double& min, double& max)
{
min = data[0];
for(count = 0; count<MAXSIZE;)
{
count++;
}
if (data[count] < min)
{
min = data[count];
}
max = data[0];
for(count=0; count<MAXSIZE;)
{
count++;
}
if(data[count] > max)
{
max = data[count];
}
double range = max - min;
cout<<"Min: " <<setprecision(4)<<setw(20)<<min;
cout<<"Max: " <<setprecision(4)<<setw(20)<<max;
cout<<"range: " <<setprecision(4)<<setw(18)<<range;
/**
* computes the sample mean
* @param data - an array containing the measurements
* @param count - the number of measurements
* @return the mean of the set of measurements
*/
double calcMean(const double data[ ], int count)
{
double sum = 0;
double mean;
int i;
for(i = 0; i < count; i++);
{
sum += data[i];
mean = sum/count;
}
return mean;
}
/**
* computes the sample variance
* @param data - an array containing the measurements
* @param count - the number of measurements
* @return the sample variance of the set of measurements
*/
double calcVariance(const double data[ ], int count)
{
double sum = 0;
double var = 0;
double mean;
int i;
for(i = 0; i < count; i++);
{
sum += data[i];
mean = sum/count;
var = pow(data[i]-mean,2);
}
return var;
}
int main()
{
double data[MAXSIZE];
double range, mean, variance, stand_dev;
string file;
int count;
cout<<"Enter the name of the data file>"<<endl;
cin>>file;
cout<<endl;
cout<<"Descriptive Statistics"<<endl;
cout<<"------------------------------"<<endl;
ifstream inputFile;
inputFile.open("sewage.data");
if(!inputFile)
{
cout<<"error opening File."<<endl;
}
while(count = 0,count < MAXSIZE && inputFile >> data[count])
{
count++;
}
cout<<"N: "<<setw(22);
cin>>count;
minMax(data, count, min, max);
cout<<"range: " <<setprecision(4)<<setw(18);
mean = calcMean(data, count);
cout<<"mean:"<<setprecision(4)<<setw<<(19)<<mean<<endl;
variance = calcVariance(data, count);
cout<<"variance:"<<setw(15)<<setprecision<<(4)<<variance<<endl;
stand_dev = sqrt(variance);
cout<<"Standard Deviation: "<<setw(6)<<setprecision(4)<<stand_dev<<endl;
inputFile.close();
return 0;
}