Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that simulates the design shown in Figure 6.18, using a componen

ID: 3532956 • Letter: W

Question

Write a program that simulates the design shown in Figure 6.18, using a component
reliability of 0.8 for components 1 and 2, and 0.95 for components 3 and 4. Print
the estimate of the reliability, using 5,000 simulations. (The analytical reliability of
this system is 0.9649.)


This is what I have so far:


#include <cstdlib>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include<cmath>
#include<time.h>

using namespace std;


double rand_double(double a, double b) {
    return ((double)rand()/RAND_MAX)*(b-a) + a;
}

int main()
{

    double c1,c2,c3, c4;
    int success = 0;
    int total = 5000;



    for(int i = 0; i < total; i++)
    {
        c1 = rand_double(0,1);
        c2 = rand_double(0,1);
        c3 = rand_double(0,1);
        c4 = rand_double (0,1);
        if( c1 < 0.8 || c2 < 0.8 || c3 < 0.95 || c4 < 0.95)
        {
            success++;   
        }
    }
    cout << "By simulation, reliability is " << (double)success/total << endl;
   
   
system("PAUSE");
return 0;
}


Explanation / Answer

Your if criteria is wrong. What you are checking is: the system works if all of the component works. But in this case reliability criteria would be slightly different. You need to incorporate the followings:

1. System works if all 4 work (as you have done) OR

2. If 1 and 2 work (we do not care about 3 and 4 at this point) OR

3. If 3 and 4 work (we do not care about 1 and 2 at this point)


Also, make a change in function rand_double. The denominator should be RAND_MAX + 1.0. (its a minor error) but make sure to incorporate the other three

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote