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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!