-
Notifications
You must be signed in to change notification settings - Fork 0
/
facmain.cpp
46 lines (40 loc) · 1.09 KB
/
facmain.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
//
// main() function for the factory simulation
//
// The code you write for hw4 must use this main()
// to run the program.
//
// usage: ./a.out number-of-assembly-lines rate1 [rate2 ...] < list_of_packages
//
// Each rate is given as number of units per time unit ("minute").
// The rates can contain fractional parts.
//
// history:
// 2013-10-31 modified for multi-line version
// 2013-10-11 original version of this file
//
#include <cstdlib> // for atof()
#include "factory.h"
using namespace std;
int main(int ac, char *av[])
{
double *rates;
int num_workers;
int result;
int i;
if ( ac < 3 ){
cerr << "usage: " << av[0] << ": num_workers rate1 [rate2 ...]\n";
exit(1);
}
num_workers = atoi(av[1]); // get number of workers
if ( ac-2 != num_workers ){ // deduct 1 for cmd, 1 for count
cerr << av[0] << ": incorrect number of rates\n";
exit(1);
}
rates = new double[num_workers];
for(i=2; i<ac; i++)
rates[i-2] = atof(av[i]);
Factory fac(num_workers, rates);
result = fac.run();
return result;
}