Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image 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 exam1.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 For example, the first group has a size of 2 Generate two random birthdays using the ordinal day of the year o o Jan. 1 is day 1, Jan. 2 is day 2,..., Feb. 1 is day 32, Dec. 31 is day 365 See if there is a match Generate new birthdays and see if there is a match 4999 more times (for a total of 5000 runs) 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 o o o o Repeat for group size of 3, 4, 5,. , 50 .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 -4.3% For 3 people, odds of two birthdays is-9.68% For 4 people, odds of two birthdays is ~1.64% For 22 people, odds of two birthdays is ~47.98% For 23 people, odds of two birthdays is-51.5% For 48 people, odds of two birthdays is ~95.82% For 49 people, odds of two birthdays is -96.16% For 50 people, odds of two birthdays is ~96.76% Hints Take the time to think about the problem before you write code You do NOT have to understand the math behind the birthday paradox in order to run a simulation . . You do not have to find all matches in a group, just a match .While your values won't match exactly (because random), your values should still be quite close to what is shown in the sample run o o o Use the values as a gauge of whether you are calculating correctly Especially for group sizes 22 & 23 You should expect see your first greater than 50% chance with group 23 .Utilizing a partially filled array will be necessary . Most of your legwork should take place in the runSimulation() function Reminders .Be sure that your program includes your name, ID, description, etc. as shown in the General Homework Requirements Handout .Use good style including indentation, comments, etc. Part of the grade will be for style and quality . Carefully test your program. .You are welcome to write your program at home. If you do, be sure to compile and test it in the lab before submitting it. 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 exam1.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 For example, the first group has a size of 2 Generate two random birthdays using the ordinal day of the year o o Jan. 1 is day 1, Jan. 2 is day 2,..., Feb. 1 is day 32, Dec. 31 is day 365 See if there is a match Generate new birthdays and see if there is a match 4999 more times (for a total of 5000 runs) 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 o o o o Repeat for group size of 3, 4, 5,. , 50 .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 -4.3% For 3 people, odds of two birthdays is-9.68% For 4 people, odds of two birthdays is ~1.64% For 22 people, odds of two birthdays is ~47.98% For 23 people, odds of two birthdays is-51.5% For 48 people, odds of two birthdays is ~95.82% For 49 people, odds of two birthdays is -96.16% For 50 people, odds of two birthdays is ~96.76% Hints Take the time to think about the problem before you write code You do NOT have to understand the math behind the birthday paradox in order to run a simulation . . You do not have to find all matches in a group, just a match .While your values won't match exactly (because random), your values should still be quite close to what is shown in the sample run o o o Use the values as a gauge of whether you are calculating correctly Especially for group sizes 22 & 23 You should expect see your first greater than 50% chance with group 23 .Utilizing a partially filled array will be necessary . Most of your legwork should take place in the runSimulation() function Reminders .Be sure that your program includes your name, ID, description, etc. as shown in the General Homework Requirements Handout .Use good style including indentation, comments, etc. Part of the grade will be for style and quality . Carefully test your program. .You are welcome to write your program at home. If you do, be sure to compile and test it in the lab before submitting it

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

More Books

Students also viewed these Databases questions

Question

Were the decisions based on appropriate facts?

Answered: 1 week ago

Question

Were the right people involved in the decision-making process?

Answered: 1 week ago