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 pathlightBulbs.cpp
More file actions
214 lines (168 loc) · 7.59 KB
/
Copy pathlightBulbs.cpp
File metadata and controls
214 lines (168 loc) · 7.59 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*----------------------------------------------------------------------------+
| Author: Jerome Richards |
| |
| Assignment: Project 10 |
| File: lightBulbs.cpp |
| |
| Instructor: Dr. Roger deBry |
| Class: CNS-1350 Section X01 |
| |
| Date Written: April 03, 2005 |
| |
| Description: |
| |
| Test the use of containers, algorithms and interators from the STL |
| library |
+----------------------------------------------------------------------------*/
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <cassert>
using namespace std;
#include "batch.h"
#include "productionRun.h"
// Purpose : Display program author, course, and project info
void dispPrologue();
// Purpose : Open the file specified by the user
bool openDataFile( ifstream& inFile );
// Purpose : Read a production run record from the data file
bool readProdData( ifstream& inFile, CBatch* theBatch );
// Purpose : Display the production run data that was just read from the file
void dispRun( CProductionRun* thePR );
int main()
{
CBatch* aBatch = NULL;
ifstream inFile;
dispPrologue();
if( openDataFile( inFile ) )
{
aBatch = new CBatch;
assert( aBatch != NULL );
cout.setf( ios::right );
cout.setf( ios::showpoint );
cout.setf( ios::fixed );
cout.precision( 2 );
cout << "\n\nReading production run samples:\n\n";
cout << "Run # Bulb Lifetime\n";
cout << "----- -------------\n";
while( ! inFile.eof() )
readProdData( inFile, aBatch );
inFile.close();
cout << "\nEnd of production run data.\n\n";
aBatch->calcMean();
aBatch->calcSTD();
cout << "\nThe mean number of hours burned is " << aBatch->getMean() << " hours\n";
cout << "with a standard deviation of " << aBatch->getSTD() << " hours.\n\n";
aBatch->analyzeBatch();
assert( aBatch != NULL );
delete aBatch;
}
cout << "\n";
system( "pause" );
return 0;
}
/*----------------------------------------------------------------------------+
| Purpose: Display the data for one production run record |
| |
| Parameters: thePR is a pointer to a CProductionRun object |
| Returns: nothing |
| |
| Pre-conditions: thePR is a valid CProductionRun object |
| Post-conditions: none |
+----------------------------------------------------------------------------*/
void dispRun( CProductionRun* thePR )
{
const int RUN_WIDTH = 5;
const int LIFE_WIDTH = 10;
assert( thePR != NULL );
cout << setw( RUN_WIDTH ) << thePR->getRun() << " "
<< setw( LIFE_WIDTH ) << thePR->getLife() << '\n';
}
/*----------------------------------------------------------------------------+
| Purpose: Read a production run record from the data file and append |
| it to the batch as CProductionRun object |
| |
| Parameters: inFile is the ifstream object used to open the file |
| theBatch is a pointer to a CBatch class |
| |
| Returns: TRUE if a record was successfully read |
| |
| Pre-conditions: inFile is assumed to be a valid ifstream object and |
| theBatch is assumed to be a valid pointer to a CBatch |
| object |
| |
| Post-conditions: none |
+----------------------------------------------------------------------------*/
bool readProdData( ifstream& inFile, CBatch* theBatch )
{
bool lOkay = false;
CProductionRun* ptrPR;
int run;
string id;
double life;
assert( theBatch != NULL );
inFile >> run >> id >> life;
if( inFile.good() )
{
ptrPR = new CProductionRun( run, id, life, theBatch );
theBatch->addProdRun( ptrPR );
dispRun( ptrPR );
lOkay = true;
}
return lOkay;
}
/*----------------------------------------------------------------------------+
| Purpose: Open the file specified by the user |
| |
| Parameters: inFile is the ifstream object used to open the file with |
| |
| Returns: TRUE if the file was successfully opened |
| |
| Pre-conditions: none |
| Post-conditions: none |
+----------------------------------------------------------------------------*/
bool openDataFile( ifstream& inFile )
{
bool lOpen = false;
string fileName;
while( ! lOpen )
{
cout << "\nPlease enter a file name: ";
cin >> fileName;
if( fileName.length() == 0 )
{
cout << "\n\nPress ENTER to terminate the program.";
cin.get();
exit(1);
}
else
{
inFile.open( fileName.c_str() );
if( !( lOpen = inFile.good() ) )
{
cout << "\nFile not found ...\n";
inFile.clear();
}
}
}
return lOpen;
}
/*----------------------------------------------------------------------------+
| Purpose: Display file prologue |
| Parameters: none |
| Returns: nothing |
| |
| Pre-conditions: none |
| Post-conditions: none |
+----------------------------------------------------------------------------*/
void dispPrologue()
{
system( "cls" );
cout << " Name: Jerome Richards\n";
cout << " Course: CNS-1350 Section X01\n";
cout << "Instructor: Dr. Roger deBry\n";
cout << " Program: Project Ten\n";
cout << " File: lightBulbs (lightBulbs.exe)\n";
cout << "\n\n";
}