Someone Please help with this. I want to make a class Statistics and read from an external file and find the mean and standard deviation and below is what i have so far. any suggestions?

``````#include <cstdlib>
#include <iostream>
#include <cmath>
#include <fstream>

using namespace std;
class Statistics{
double x;
int n;
double sum;
double sum2;

public:

Statistics(double _x, int n);
~Statistics();
Statistics Accumulate(double a);
Statistics mean(Statistics& m);
Statistics sigma(Statistics& s);
void Print() const;

};

int main(){

const int n=200;
double sum = 0.0;
double sum2 = 0.0;
double data;

ifstream in("file.txt");
for(int i=0; i < n ; i++){
in >> data;
sum+=data;
sum2+=data*data;
}
in.close();

double mean   = sum/n;
double sigma = sqrt( (sum2 - sum*mean)/(n-1));
Statistics a(data, 200);
a.Print();

system("PAUSE");
return EXIT_SUCCESS;
}

Statistics::Statistics(double _x, int n ):x(_x){}

Statistics::~Statistics(){
cout<<"Statistics destructor called"<<endl;
}
Statistics::Statistics mean(Statistics& m){
double sum = 0.0;
x.m+=sum;
return sum;
}
Statistics::Accumulate(double a) const{
x.a=(sum2-sum*mean)/(n-1);
return a;
}
Statistics::Statistics sigma(double s){
x.s= sqrt( (sum2 - sum*mean)/(n-1));
return s;

void Statistics::Print(){

cout << " N     = " << n <<endl;
cout << " Mean  = " << m <<endl;
cout << " Sigma = " << s<<endl ;
}``````

Edited by __avd: Added [code] tags.

2
Contributors
1