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 ;
}

Please use code tags when posting code.

What is the problem? Please provide a sample input, the current output, and the expected output. I also suggest decoupling your file input from your algorithm. Hard code some values and make sure the statistics code works first before introducing another challenge of the file input.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.