Write a program that uses the random-number generator to simulate dropping a gla
ID: 3545589 • Letter: W
Question
Write a program that uses the random-number generator to simulate dropping a glass rod that breaks into three pieces. The purpose of the experiment is to estimate the probability that the pieces might form the sides of a triangle. If you use the line segment 0 to 1 (on the real number line) as a mathematical model of the glass rod, a random number generator (function) can be used to generate two numbers between 0 and 1 representing the coordinates of the breaks.
The triangle inequality (the sum of the lengths of two sides of a triangle are always greater than the length of the third side) may be used to test the length of each piece against the lengths of the other two pieces.
I got off to a good start with this program, but now I am hopelessly stuck. Any good ideas out there?
Explanation / Answer
#include #include #include #include #include #include #include using namespace std; float doBreak (float, float); float doProbability (float, float); const int SENTINEL = 21; //sentinal value int main() { float break1; float break2; float side1; float side2; float side3; float count; float tests; float triangle; float probability; const int SENTINEL = 21; count = 1; srand (time (NULL)); cout > tests; if (tests != SENTINEL) { do { doBreak(break1, break2); count++; }while (countRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.