Here’s my new homework assignment right now. Again any help is appreciated, especially since I have to study for 3 midterms this week and I’m worried I won’t have any time to work on this. Welcome to college life I suppose lol. :sad:
Of course it goes without saying that I’m going to be putting in a decent amount of work in this as well. Can’t expect the pros here to do all the work for me. Thanks in advance.
[details=Spoiler]Due Friday 11/4
Question
Suppose that you have a party and invite 30 people. What do you think is the probability that two of these people have the same birthday?
Answering this Question using Simulation
For this lab, you are to write a program that uses simulation to answer this question. The program should simulate a party by selecting birthdays randomly, and then checking to see if two of the birthdays are the same. The probability that two people have the same birthday can be determined by simulating a large number of such parties, and keeping track of how many times there are two people with the same birthday.
Make your program flexible by allowing the user to specify the number of trials to run (i.e., the number of parties to simulate) as well as the number of people to invite. Use the time function to seed the random number generator.
Hints
· Write a function with prototype int party(int n) that will simulate one party with n guests. The function will return 1 if any two of the guests have the same birthday (i.e., born on the same day of the year, not necessarily in the same year) and returns 0 otherwise. To be more precise, the function party should return 1 if any two birthdays are the same, regardless of whether any other guests have the same birthday. For example, if two pairs of guests have the same birthday, the function returns 1. If three guests have the same birthday, the function returns 1. And so forth. The only time the function returns 0 is if all the birthdays are different.
· In the function party, use the function rand to generate the random birthdays. (A birthday may simply be a number between 1 and 365. You can ignore leap years).
· Call srand once at the beginning of main. (Do not call srand in the function party. If you do, and pass it the same seed every time, your function will simulate the same party every time it is called.)
· In the function party, use an int array to record birthdays that have been assigned. Give some thought to how large the array should be, and how you will record birthdays. There is more than one reasonable way to do this.
· Aside: If you understand probability theory, you might be able to answer this question analytically. For many other questions of this sort, however, simulation is the only practical way to find an answer.
Report
Submit a report at the beginning of your lab session. Your report should include a printout of your source code and the dialog for three sample runs, as follows:
o Invite 30 people and simulate 10,000 parties
o Invite 30 people and simulate 1,000,000 parties
o Invite 40 people and simulate 100,000 parties
Print the probability of two guests having the same birthday as a percentage, with two digits to the right of the decimal point. The dialog for the first sample run should look like the following (the percentage given is not correct):
Enter the number of guests: 30
Enter the number of parties: 10000
The probability that two guests have the same birthday is 12.34%[/details]