Problem

Re-do or do for the first time Programming Project 5.8 in Chapter 5. This project asks you...

Re-do or do for the first time Programming Project 5.8 in Chapter 5. This project asks you to approximate through simulation the probability that two or more people in the same room have the same birthday, for two to fifty people in the room.

However, instead of creating a solution that uses arrays, write a solution that uses a map. Over many trials (say, 5000), randomly assign birthdays (i.e., the numbers 1 through 365, assuming each number has an equal probability) to everyone in the room. Use a map to map from the birthday (1–365) to a count of how many times that birthday occurs. Initially, each birthday should map to a count of 0. As the birthdays are randomly generated, increment the corresponding counter in the map. If a duplicate birthday is detected, then increment a counter for that trial. Over all trials this counter should indicate how many of those trials had a duplicate birthday. Divide the counter by the number of trials to get an estimated probability that two or more people share the same birthday for a given room size.

Your output should look the same as the output for Programming Project 5.8 in Chapter 5.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 19