This repository was archived by the owner on Jan 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch.cpp
More file actions
155 lines (114 loc) · 3.23 KB
/
Copy pathbatch.cpp
File metadata and controls
155 lines (114 loc) · 3.23 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*----------------------------------------------------------------------------+
| Author: Jerome Richards |
| |
| Assignment: Project 10 |
| File: batch.cpp |
| |
| Instructor: Dr. Roger deBry |
| Class: CNS-1350 Section X01 |
| |
| Date Written: April 03, 2005 |
| |
| Description: CBatch class implementation |
+----------------------------------------------------------------------------*/
#include <iostream>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <vector>
#include <cassert>
#include "batch.h"
using namespace std;
CBatch::CBatch()
{
itsMean = 0.0;
itsSTD = 0.0;
lErrors = false;
itsPR.clear();
}
CBatch::~CBatch()
{
vector< CProductionRun* >::iterator iPR;
vector< CProductionRun* >::iterator iPRLast;
iPR = getBegin();
iPRLast = getEnd();
while( iPR != iPRLast )
{
delete *iPR;
iPR++;
}
itsPR.clear();
}
void CBatch::addProdRun( CProductionRun* theProdRun )
{
assert( theProdRun != NULL );
itsPR.push_back( theProdRun );
}
void CBatch::calcMean()
{
vector< CProductionRun* >::iterator iPR;
vector< CProductionRun* >::iterator iPRLast;
int count = (int) itsPR.size();
itsMean = 0.0;
iPR = getBegin();
iPRLast = getEnd();
while( iPR != iPRLast )
{
itsMean += (*iPR)->getLife();
iPR++;
}
if( count > 1 )
itsMean = itsMean / count;
}
void CBatch::calcSTD()
{
vector< CProductionRun* >::iterator iPR;
vector< CProductionRun* >::iterator iPRLast;
int count = (int) itsPR.size();
double tmp;
itsSTD = 0.0;
iPR = getBegin();
iPRLast = getEnd();
while( iPR != iPRLast )
{
tmp = pow( (*iPR)->getLife() - itsMean, 2 );
itsSTD += tmp;
iPR++;
}
if( count > 1 )
itsSTD = sqrt( itsSTD / (count-1) );
}
void CBatch::analyzeBatch()
{
vector< CProductionRun* >::iterator iPR;
vector< CProductionRun* >::iterator iPRLast;
iPR = getBegin();
iPRLast = getEnd();
while( iPR != iPRLast )
{
iPR = find_if( iPR, iPRLast, checkRun );
if( iPR != iPRLast )
{
lErrors = true;
iPR++;
}
}
if( lErrors )
cout << "Run additional tests!\n";
}
bool checkRun( CProductionRun* thePR )
{
double minimum = 0.0;
bool lError = false;
CBatch* aBatch = NULL;
assert( thePR != NULL );
aBatch = thePR->getBatch();
assert( aBatch != NULL );
minimum = aBatch->itsMean - aBatch->itsSTD;
if( thePR->getLife() < minimum )
{
cout << "Test batch " << thePR->getRun() << " does not meet minimum lifetime.\n";
lError = true;
}
return lError;
}