Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write code in C++. Need help and explanation for the runSimulation part. Can only use breaks in switch statements. Background The birthday paradox is a

Write code in C++.

Need help and explanation for the runSimulation part.

Can only use breaks in switch statements.

image text in transcribedimage text in transcribed

Background The birthday paradox is a probability theory that states when ignoring leap years and birth years, and assuming a uniform distribution, there is a greater than 50% chance that two people share the same birthday in a group as small as 23 people. For further information, see the following links: Wikipedia & YouTube. No late submissions are allowed Problem You will run a simulation to demonstrate the birthday paradox for group sizes ranging from 2 to 50 Requirements Name your file examl.cpp . Place the following declaration in the global space: const int MAX_CAP- 50; . Use the following function prototype: double runSimulation(int size); . The program takes no input from the user For each group size, run a simulation and use the results to calculate the odds of two people sharing the same birthday o For example, the first group has a size of 2 o Generate two random birthdays using the ordinal day of the year * Jan. 1 is day 1, Jan. 2 is day 2, ..., Feb. 1 is day 32, ., Dec. 31 is day 365 o See if there is a match o Generate new birthdays and see if there is a match 4999 more times (for a total of 5000 runs) o Divide the total number of matches found across the 5000 runs by the number of runs; this is the probability that two people in that group will share the same birthday in a group of 2 Repeat for group size of 3, 4, 5,... , 50 o . Print a message to the screen showing the odds of a same birthday for each group A [truncated] sample run of your program shall look like this: For 2 people, odds of two birthdays is ~0.3%. For 3 people, odds of two birthdays is ~0.68% For 4 people, odds of two birthdays is ~1.64%

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago