-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTally.cpp
56 lines (49 loc) · 1.24 KB
/
Tally.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
@file Tally.cpp
@brief contains functions for the Tally class
@author Luke Eure
@date January 8 2016
*/
#include "Tally.h"
/*
@brief constructor for Tally class
*/
Tally::Tally() {}
/*
@brief deconstructor
*/
Tally::~Tally() {}
/*
@brief sets the tally and _tally_squared equal to zero
*/
void Tally::clear() {
_tally_count = 0;
_tally_squared = 0;
}
/*
@brief gets the current tally count
@return a double: the number stored in the tally
*/
double Tally::getCount() {
return _tally_count;
}
/*
@brief returns the standard deviation from the amount held in the tally
@param n the number of sampled data points
@return the standard deviation from the amount held in the tally
*/
double Tally::getStandardDeviation(int n) {
double standardDev =
_tally_squared/n - (_tally_count / n) * (_tally_count / n);
return standardDev;
}
/*
@brief overload for += that allows an amount to be added to the tally. Its
square is added to _tally_squared
@param tally_addition an amount to be added
*/
Tally Tally::operator+=(double tally_addition) {
_tally_count += tally_addition;
_tally_squared += tally_addition * tally_addition;
return *this;
}