Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ Problem. Any tips are appreciated. Write a program that estimates the probability P that if N people are in a room, at least two
C++ Problem. Any tips are appreciated.
Write a program that estimates the probability P that if N people are in a room, at least two people in that room will have the same birthday. By the same birthday, we mean the same day and the same month in a (non-leap) year like 2021. The 'birthday paradox' is described as follows: for relatively small values of N, there is a surprising high probability that two people in the same room happen to share the same birthday. Write a program to implement the 'birthday paradox'. Your program will use simulation to approximate the value of P for the given value of N as follows: Your program should read in N, which is the number of people in the room, and it should read T, which is the number of trials. Run a trial or experiment (of determining whether at least 2 people in the room have the same birthday) T times and then count the number of those trials C where at least two people in the room do have indeed the same birthday. Output the value N and the value C/T which will be an estimate for P. Repeat for several values of N printing their corresponding estimated value P, in fact, choose and print a reasonable range of values for N with their estimated probabilities P. By a range we mean that you read N and compute the next A values and output N and C/T for values N to N + A for some delta A) Note: the larger the value of T, the more accurate C/T will be for the probability P. Make T, which is the number of trials, to be at least 4000 (use a named constant in your code, not a magic number). of interest in the birthday paradox is finding the smallest value of N such that Pis 0.5. That is, for such a value of N there is a 50/50 chance that two people have the same birthday in the room. Before you run the experiment, guess what the value of N should be (just for fun - you don't need to include your original guess in your results). Run your program and see. The value of N that you are looking for should be less than 30. Write a program that estimates the probability P that if N people are in a room, at least two people in that room will have the same birthday. By the same birthday, we mean the same day and the same month in a (non-leap) year like 2021. The 'birthday paradox' is described as follows: for relatively small values of N, there is a surprising high probability that two people in the same room happen to share the same birthday. Write a program to implement the 'birthday paradox'. Your program will use simulation to approximate the value of P for the given value of N as follows: Your program should read in N, which is the number of people in the room, and it should read T, which is the number of trials. Run a trial or experiment (of determining whether at least 2 people in the room have the same birthday) T times and then count the number of those trials C where at least two people in the room do have indeed the same birthday. Output the value N and the value C/T which will be an estimate for P. Repeat for several values of N printing their corresponding estimated value P, in fact, choose and print a reasonable range of values for N with their estimated probabilities P. By a range we mean that you read N and compute the next A values and output N and C/T for values N to N + A for some delta A) Note: the larger the value of T, the more accurate C/T will be for the probability P. Make T, which is the number of trials, to be at least 4000 (use a named constant in your code, not a magic number). of interest in the birthday paradox is finding the smallest value of N such that Pis 0.5. That is, for such a value of N there is a 50/50 chance that two people have the same birthday in the room. Before you run the experiment, guess what the value of N should be (just for fun - you don't need to include your original guess in your results). Run your program and see. The value of N that you are looking for should be less than 30Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started