Question: Part II -Pi Calculation implementation. (15 pts) If you watch the Discovery or Sci-Fi channel you will find dozens of alien conspiracy shows that reference

Part II -Pi Calculation implementation. (15 pts)

If you watch the Discovery or Sci-Fi channel you will find dozens of alien conspiracy shows that

reference Pi as something so advanced that it must be alien. The number

is a mathematical

constant, the ratio of a circle's circumference to its diameter, commonly approximated as

3.14159. So you could graph the value or calculate an approximate value using the series given

below:

Pi = 4 * (1/1 1/3 + 1/5 1/7 + 1/9 ... (alternating + -) (1/n))

So notice that the numerator is always one or -1. If you started the

numerator at -1, then multiply each term by -1, you would have 1, -

1,1,-1 etc.

Then notice that the denominator goes from 1,3,5,7,9 etc. So this is

counting by 2s starting at one. For loops are good when you know how

many times it will go through the loop. So a for loop might be

something like:

for (long i=1; i

where i is the term that changes by 2 starting at 1 (not zero)

Remember, not every for loop starts at one, and not every for loop ends in i++!

we are using longs, so we can have very long numbers. Likewise, PI

should be a double (not a float) to have a very large decimal accuracy

Write a c++ program to calculate the approximate value of pi using this series. The program takes an

input n that determines the number of values we are going to use in this series. Then output the

approximation of the value of pi. The more values in the series, the more accurate the data. Note 5

terms isnt nearly enough. You will try it with numbers read in from a file. to see the accuracy increase.

Use a for loop for the calculation and a while loop that allows the user to repeat this calculation for new

values n until the user says they want to end the program.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!