/*
    This file is defines the DataAnalysis class.
   
    I.e. it defines all the functions that is included in the class. 
*/

#include "dataanalysis.hpp"

// Constructor used to initialize data.    
DataAnalysis::DataAnalysis()
{
    xmax=0.0;
    xmin=0.0;
    sum=0.0;
    count=0.0;
}

// Destructor used to destroy class.
// We do not need to do anything.
DataAnalysis::~DataAnalysis()
{
}


// Methods of the class
void DataAnalysis::Add(double x)
{
   if (count==0) { xmin=x; xmax=x;}
   else if (x<xmin) xmin=x;
   else if (x>xmax) xmax=x;

   sum+=x;
   count++;
}

double DataAnalysis::Largest()
{
   return xmax;
}

double DataAnalysis::Smallest()
{
   return xmin;
}

// Implement this function:
/*
double DataAnalysis::double Average()
{
}
*/

//  double Variance();
//  void Reset();

// Rather complicated looking beast!
ostream& operator<<(ostream& os, const DataAnalysis &DA)
{
   os << "DataAnalysis object with " << DA.count << " data\n";

   if (DA.count>0)
      {
          os << "xmin=" << DA.xmin << "\n";
          os << "xmax=" << DA.xmax << "\n";
          os << "<x>="  << DA.sum/DA.count << "\n";
      }

   return os;
}

