The purpose of this lab is to create a program that performs a simple computation of the value $\pi$.
thumb The value of $\pi$ can be computed according to the following formula: $\frac{\pi}{4} = 1 - \frac{1}{3} + \frac{1}{5} - \frac{1}{7} + \frac{1}{9} - \ldots$ Write a C++ program to compute $\pi$. Because the formula is an infinite series, you wont be able to compute $\pi$ exactly. Compute it with enough terms to arrive at the value 3.19419. (This is an estimated value, reached at 19 terms). You don't need to use a loop, but just add in as many terms as you need by making the expression longer. You may need to modify and run your program several times until you get the correct answer.
You may think that you don't know how to complete this lab, but you actually do. Write down the steps you would take to compute $\pi$ with a pencil and paper, then translate this into computer instructions.
In this case there are no Inputs, other than running the program itself. The Output is the correct value of $\pi$ that you will be printing out.
If you get stuck:
http://aml.cs.byu.edu/~kseppi/cs142help.html
The TA's love to help, but you will gain much more in learning how to solve your problems on your own!
Some of you have already done some programming and need an additional challenge. Read ahead to find out how to use loops, then make your program calculate $\pi$ using as many terms (how many iterations the loop completes, NOT how many significant digits are listed when printed) as you ask it to. You will probably want to use a variable to tell your program how many terms you want to include.
If you are really curious about how computers actually do floating-point math you can take a look at the paper “What Every Computer Scientist Should Know About Floating-Point Arithmetic” by David Goldberg. you can find a link to it at http://dl.acm.org/citation.cfm?id=103163
When you have your program working, you will need to show it to a TA.
Put yourself in the help request queue to pass off: http://taohelpqueue.appspot.com/requesthelp/YPK364KMSA5U5QF55UCL8LQ3JHCS5C.
The TA will evaluate your code based on the following criteria:
Extra credit: Did you find out how to print out $\pi$ with as many iterations (of your loop, NOT calculating pie to a certain decimal place) as needed? (1 point)
WHEN YOU PASS OFF, you will need to submit your code. To do this follow the instructions below:
.
If you have trouble, ask a neighbor or a TA.
You can save the files to the desktop and then attach them to an email.
An example pass-off form is shown below for this lab. You will find printed pass-off forms in 1119 TMCB.