-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSS.cpp
More file actions
77 lines (55 loc) · 1.5 KB
/
SS.cpp
File metadata and controls
77 lines (55 loc) · 1.5 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "SS.h"
statTest::statTest(Generator * _generator, int _sampleCount):Test(_generator, _sampleCount), mean(0.0), variance(0.0), stdDeviation(0.0), coefVariation(0.0)
{
}
statTest::~statTest()
{
}
double statTest::countMean()
{
mean = 0.0;
for (int i = 0; i < sampleCount; i++)
mean += samples[i];
mean /= sampleCount;
return mean;
}
double statTest::countVariance()
{
variance = 0.0;
countMean();
for (int i = 0; i < sampleCount; i++)
variance += pow((samples[i] - mean), 2);
variance /= (sampleCount - 1);
return variance;
}
double statTest::countDeviation()
{
countVariance();
stdDeviation = sqrt(variance);
return stdDeviation;
}
double statTest::countVariation()
{
countDeviation();
coefVariation = stdDeviation / mean;
return coefVariation;
}
void statTest::displayResult(ostream & output)
{
output << "Basic statistic measure test!" << endl << "Sample: " << endl;
for (int i = 0; i < sampleCount; i++)
{
output << samples[i] << "\t";
if ((i % 10 == 0) && (i > 0))
{
output << endl;
}
}
output << endl << "Mean: \t" << mean << endl << "Variance: \t" << variance << endl << "Standard deviation:\t" << stdDeviation << endl << "Coefficient of variation: \t" << coefVariation << endl << endl;
}
void statTest::runTest(ostream & output)
{
drawSamples();
countVariation();
displayResult(output);
}