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
|
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
double rand_float(double a, double b); double c;
int main()
{
unsigned int seed;
int n;
double component_reliability, component_reliability1, component_reliability2, component_reliability3,
a_parallel, parallel_success(0), num1, num2, num3;
cout << "Enter the indvidual component reliability1: \n";
cin >> component_reliability1;
cout << "Enter the indvidual component reliability2: \n";
cin >> component_reliability2;
cout << "Enter the indvidual component reliability3: \n";
cin >> component_reliability3;
cout << "Enter the number of trials: \n";
cin >> n;
cout << "Enter unsigned integer seed: \n";
cin >> seed;
srand(seed);
cout << endl;
a_parallel = (component_reliability1) * (1 - ((1 - component_reliability2) *
(1 - component_reliability3)));
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++;
}
}
cout << "Analytical Reliability \n";
cout << "Parallel: " << a_parallel << endl;
cout << "Simulation Reliability " << n << " trials \n";
cout << " Parallel: " << (double)parallel_success/n << endl;
system ("PAUSE");
return 0;
}
double rand_float(double a, double b)
{
return ((double)rand()/RAND_MAX*(b-a) + a);
}
|