Program Reliability
I am working on a component reliability program for class but I am having a problem getting my program to run. Can you take a look at this please?
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
|
/*--------------------------------------------------------------------------------------------------------*/
/* Write a program that simulates the design shown in Figure 5.13 using a component reliability of: */
/* .08 for component 1 */
/* .85 for component 2 */
/* .95 for component 3 */
/* Print the estimate of the reliability using 5,000 simulations. The analytical reliability is .794 */
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
// Functional prototypes.
double rand_float(double a, double b, double c);
int main()
{
// Declare objects.
unsigned int seed;
int n;
double component_reliability, a_parallel, parallel_success(0), num1, num2, num3;
//Get information from simulation.
cout << "Enter the indvidual component reliability: \n";
cin >> component_reliability;
cout >> "Enter the number of trials: \n";
cin >> n;
cout << "Enter unsigned integer seed: \n";
cin >> seed;
srand(seed);
cout << endl;
// Generate analytical reliability.
a_parallel = 3*component_reliability,3) - 3*power(component_reliability,2) +
pow(component_reliability,3);
// Determine simulation reliability estimates.
for (int k=1; k<=n; k++)
{
num1 = rand_float(0.1);
num2 = rand_float(0.1);
num3 = rand_float(0.1);
if (((num1<=component_reliability) &&
((num2<=component_reliability)) &&
(num3<=component_reliability))
{
parallel_success++;
}
}
// Print results.
cout << "Analytical Reliability \n";
cout << "Parallel: " << a_parallel << endl;
cout << "Simulation Reliability " << n << " trials \n";
cout << " Parallel: " << (double)parallel_success/n << endl;
// Wait to close the program.
system ("PAUSE");
return 0;
}
/*----------------------------------------------------------------------------------------------------------*/
/* This function generates a random double value between a and b. */
double rand_float(double a, double b)
{
return ((double)rand()/RAND_MAX*(b-a) + a;
}
/*----------------------------------------------------------------------------------------------------------*/
|
Topic archived. No new replies allowed.