Question: For C++: Declare default_random_engine and uniform_int_distribution global variables to simulate coin flipping Write a void function that simulates flipping a coin n times where n
For C++:
Declare default_random_engine and uniform_int_distribution global variables to simulate coin flipping
Write a void function that simulates flipping a coin n times where n is a value parameter. The function returns, by means of a return statement the longest sequence of consecutive heads that appears.
Use the following algorithm to write the function:
max length = 0
length = 0
for k = 1 to n
flip coin
if coin is heads then
add 1 to length
else
if length > max length then
assign length to max length
assign 0 to length
end if
end if
end for
.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
