Answered step by step
Verified Expert Solution
Question
1 Approved Answer
THE CODING IS ALMOST ALREADY DONE. I have this exercise/challenge that Im doing and I am having some trouble figuring it out. it is almost
THE CODING IS ALMOST ALREADY DONE. I have this exercise/challenge that Im doing and I am having some trouble figuring it out. it is almost done and just needs to be filled in.
Instructions: a similar problem has been answer in this link:
https://www.chegg.com/homework-help/questions-and-answers/approximate-value-pi-calculated-using-series-given-4-1-1-3-1-5-1-7-1-9--1-2n-1-write-c-pro-q52322318
Here is the instructions written and the code that needs to be filled in. Thank you for your help.
An approximate value of pi can be calculated using the series given below: 4 [ 1 - 1/3 + 1/5 - 1/7 + 1/9 + ... + ((-1)")/(2n + 1) ] Write a C++ program to calculate the value of Pi using this series in two distinct ways, through n iterations and approximation on n significant digits (within a change of 0.X1 decimal value, where X represents a certain amount of zeros). For example, 5 iterations would be to run the above equation for n = 0, 1, 2, 3, and 4. For the approximation within a change of 0.X1 decimal places means that the value of Pi doesn't change for more than 0.X1. For example, let say we want an approximation of 7 significant digits. That means that we will stop our loop iteration of calculating Pi (using the above equation) when the value of Pi from one iteration to the next only changes by 1 x 10 (0.0000001). So how will the program be structured now that we understand the objective? Below is a detailed description of each function. Main should display a message saying this program calculates the number Pi. After your program will prompt the user if they want to calculate Pi through iteration or approximation through the characters 'l' and 'A'. Your program should adjust if the user inputs in lower/upper case characters. Also, if the user inputs something other than I' or 'A', it will make a loop until the user gets it right. Depending on what method the user decides to calculate Pi, you'll prompt for the number of iterations or decimal value of approximation and call the respective function to calculate Pi. Iterate will take as argument the number of items to iterate through the equation calculating Pi. It will have no return value. Once it calculates Pi, it will call the function DisplayPi passing the digit significance of 5 (always) and the value of Pi it calculated to display on the screen. DecimalApprox will take as argument the digit of significance needed to approximate Pi to the decimal value. It will have no return value. You'll do an infinite loop of the Pi equation until the new value and old value of Pi only differ by 1 x 10" (0.X1). You can stop an infinite loop by using a break statement. Once you calculated the Pi value through approximation, you'll call the DisplayPi function passing the number digit significance the user entered (n) and the Pi value calculated. Display Pi will take as argument the significant digit and the value of Pi. It will return nothing. Make sure to set the environment to set the appropriate significant figures to display the calculated Pi to your monitor. Sample Runs #1 (Notice the 7 significant digits in the output that goes with the user input): $ ./PiCalculation This program calculates the number Pi. Would you like to calculate it through I>teration or A>pproximation: a How many decimals of approximation?: 7 The value of Pi is: 3.1415927 #2 (Always 5 significant digits in the display output): $ ./PiCalculation This program calculates the number Pi. Would you like to calculate it through I>teration or A>pproximation: I How many iterations?: 250 The value of Pi is: 3.13759 #3: $ /PiCalculation This program calculates the number Pi. Would you like to calculate it through I>teration or A>pproximation: x Incorrect Selection. Try again... Would you like to calculate it through I>teration or A>pproximation: y Incorrect Selection. Try again... Would you like to calculate it through I>teration or A>pproximation: z Incorrect Selection. Try again... Would you like to calculate it through I>teration or A>pproximation: A How many decimals of approximation?: 3 The value of Pi is: 3.142 15 // ====== =================================================== 16 17 #include
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started