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;
             Statistics(double _x, int n);
             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;
	double mean   = sum/n;
	double sigma = sqrt( (sum2 - sum*mean)/(n-1)); 
    Statistics a(data, 200);

    return EXIT_SUCCESS;

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

cout<<"Statistics destructor called"<<endl;
Statistics::Statistics mean(Statistics& m){
     double sum = 0.0;
     return sum;
Statistics::Accumulate(double a) const{
     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 6 Years Ago by __avd: Added [code] tags.

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.

This article has been dead for over six months. Start a new discussion instead.