Project 1a: Birthday ParadoxYou will write a simple program to verify the Birthday Paradox. The Birthday Paradox states that if you randomly select 23 people, the probability of two people having the same birthday is around 50%. If you randomly select 70 people, the probability is around 99%. You will write a simple program to verify the birthday paradox. This program should be invoked as follows: shell% ./paradox -i inputfile -o outputfile The above line means the users typed in the name of the program
1 10 20 30 40 50 70 164 229 Your goal: to build a program called
0.00 0.12 0.42 0.69 0.90 0.96 1.00 1.00 1.00 Some DetailsYou estimate the probability that N random people have the same birthday in the following manner. You run a number of trials: in each trial, you generate N random birthdays, and check if any two birthdays are the same; such a trial is called a positive trial. The probability is calculated as the number of positive trials divided by the total number of trials.
In each trial, you should use
In Hints In your paradox program, you can use different methods to read and write to
files. One way would be to use You should accept two arguments for the program: an input file
( To exit, call If you don't know how to use these functions, use the man pages. For
example, typing Assumptions and ErrorsFile length: There will be less than 1000 numbers in the input file. Invalid files: If the user specifies an input or output file that you
cannot open (for whatever reason), the program should EXACTLY print: Too few or many arguments passed to program: If the user runs paradox
without any arguments, or in some other way passes incorrect flags and such to
paradox, print Important: On any error code, you should print the error to the screen
using
General AdviceStart small, and get things working incrementally. For example, first get a program that simply reads in the input file, one line at a time, and prints out what it reads in. Then, slowly add features and test them as you go. Testing is critical. One great programmer I once knew said you have to write 5-10 lines of test code for every line of code you produce; testing your code to make sure it works is crucial. Write tests to see if your code handles all the cases you think it should. Be as comprehensive as you can be. Of course, when grading your projects, we will be. Thus, it is better if you find your bugs first, before we do. Keep old versions around. Keep copies of older versions of your program
around, as you may introduce bugs and not be able to easily undo them. A
simple way to do this is to keep copies around, by explicitly making copies of
the file at various points during development. For example, let's say you get
a simple version of Keep your source code in a private directory. An easy way to do this is
to log into your account and first change directories into |