-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsample.cpp
More file actions
106 lines (86 loc) · 1.57 KB
/
sample.cpp
File metadata and controls
106 lines (86 loc) · 1.57 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// sample.cc
// Patrik Carlsson,ets97pca@student.hk-r.se
// TTS402 Simulering
// # Time-stamp: <2004-09-17 14:35:12 pca>
//
// Version Datum Sig
//------------------------------
// 1.0 980902 Pca
// 1.1 980909 Pca
//
#include <iostream>
#include "sample.h"
using namespace std;
SAMPLE::SAMPLE()
{
Variance=0;
Mean=0;
VariableSqrSum=0;
VariableSum=0;
nrElem=0;
max=0;
min=1999999999;
}
SAMPLE::~SAMPLE()
{
//Exit
}
void SAMPLE::PutSample(double value)
{
nrElem++;
VariableSum+=value;
VariableSqrSum+=value*value;
if(value>max){
max=value;
}
if(value<min){
min=value;
}
#ifdef REPLICATION_LOGG
cout << "SAMPLE: " << nrElem << " Value: " << value << endl;
#endif
}
// INLINE declared in sample.hh
//Calculate the MEAN value.
double SAMPLE::GetSampleMean(void)
{
// cout << "Variable sum = " << VariableSum << "nrElem = " << nrElem << endl;
Mean=VariableSum/nrElem;
return Mean;
}
//Calculate the VARIANCE value.
double SAMPLE::GetSampleVar(void)
{
Mean=VariableSum/nrElem;
if(nrElem==(double)(1))
return(-1);
Variance=(VariableSqrSum-2*Mean*VariableSum+Mean*Mean*nrElem);
Variance=Variance/(nrElem-1);
return Variance;
}
//Reset counters and similar stuff.
void SAMPLE::Reset(void)
{
#ifdef REPLICATION_LOGG
cout << "!!!!!!!!!!RESETS SAMPLE TOOL!!!!!!!!!!" << endl;
#endif
nrElem=0;
Mean=0;
Variance=0;
VariableSqrSum=0;
VariableSum=0;
return;
}
double SAMPLE::GetSampleMax(void)
{
return max;
}
double SAMPLE::GetSampleMin(void)
{
return min;
}
int serv ()
{
cout <<"hello world\n";
return 0;
}