Question
USING C++ with arrays and What is the probability that two students in your OOP class have the same birthday (same day and month)? The
USING C++ with arrays and
What is the probability that two students in your OOP class have the same birthday (same day and month)? The probability might be higher than what you think! This is a well-known paradox in probability theory.
. ! . | Did you know? The probability of two students in a class of size 30 to have the same birthday is around 70%. If the class size is 50, the probability is around 97%. |
You will write in this exercise a program to estimate how many random people on average you need to meet before meeting someone with the same birthday as someone you met before.
Assume that birthdays are represented as numbers from 0 to 365. For example: January 1 is 0, January 2 is 1, January 3 is 2, ... December 31 is 365.
A. Implement the function int random_trial() which keeps generating random birthdays (numbers between 0 and 365 inclusive) and stops when a birthday that has been generated before is generated for a second time. The function returns the number of birthdays that were generated.
. ! . | Hint: You can use a boolean array to keep track of which birthdays have not been seen before |
B. Write a program that calls random_trial() 10000 times and then prints the average of the results returned by the function.
Step 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