stats.cpp 581 Bytes
Newer Older
1 2 3 4 5
#include "stats.h"

Stats::Stats()
{
  nb = 0 ;
6
  data = 0 ;
7 8 9 10 11 12 13
}

void Stats::setLabel(string _label)
{
  label = _label ;
}

14
void Stats::insert(int _data)
15 16
{
  nb++ ;
17
  data += _data ;
18 19
}

20
float Stats::getAverage()
21
{
22
  return (float) data / nb ;
23 24 25 26
}

ostream &operator<<(ostream &out, Stats &stats)
{
27 28
  out << "  ";
  
29
  if (stats.label.size())
30
    out << left << setw(17) << stats.label << "->" ;
31

32
  out << right << setw(9) << stats.nb ;
33
  out << "   " << setw(5) ;
34
  if (stats.nb)
35
    out << fixed << setprecision(1) << stats.getAverage() ;
36 37
  else
    out << "-" ;
38 39 40
  
  return out;
}