Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Problem A: Day (March 14) is Coming (20 points) Constants such as and e play an important role in science and engineering. Nowadays, we

C++ image text in transcribed
image text in transcribed
Problem A: Day (March 14) is Coming (20 points) Constants such as and e play an important role in science and engineering. Nowadays, we can find (approximate) values of important constants such as by using a calculator or a math library. But how did people calculate these constants prior to electronic caleu lators and computers? This problem asks you to implement one formula for calculating an approximation to Specifically, you will need to use the formula 6 arctan ( i /5)-4 arctan ( i /239) along with the arctangent series arctant.. This problem asks you to approximate using these formulas. To begin, first write a function double arctanApprox (double x, double tol) that uses the arctangent series above to calculate an estimate for arctan(x). This function should first estimate arctan(x) using just one term from the series, then using two terms. If these two estimates are strictly within the tolerance, then return the two-term estimate. If not, find an estimate using three terms, and if that is strictly within the tolerance of the two-term estimate, return the three- term estimate. Otherwise continue in this fashion, generating a new estimate containing one more term in the series than the previous estimate, stopping when the new and previous estimates are strictly within the tolerance, and then returning the new estimate. Once you have your arctangent function working, notice that you can get an approximation for by using the aretangent series to give approximations for loth 1.0 5.0 and 1.0//239.0 and then combining them as in the formula above. So write a main program that does the following: 1. Your program should first ask the user to input a tolerance. Validate that the input value is positive, if not, ask the user to input another value. Do this repeatedly until the user inputs a valid valne. 2. Your program should then approximate using the two equations above and your arctangent function. Specifically, it should call the arctangent function once for each arctangent term in the equation, and w th tolerance each time being one-twentieth of the user-input tolerance. So notice that the user-input tolerance and the tolerance value sent to the arctangent function are slightly different values 3. Your program should then output the approximation with 13 digits to the right of the decimal point. 4. The program should then ask if the user wishes to obtain another estimate. If the user answers 'y' or 'Y' then then the program should repeat the steps here. Otherwise it should terminate. Note that in doing this problem you should not use the arctangent functions from the cmath library; rather you must use the series above to approximate the arctangent. Here are a couple examples: (Formatting note, only one space is used or expected in all places in this example) Example 1: Input tolerance : Pi approximation: 3.1405970293261 Do you wish to approximate pi again? y Input tolerance: 001 Pi approximation: 3.1415917721832 Do you wish to approximate pi again? Example 2 Input tolerance: 42 Tolerance must be positive. Input tolerance: 42 Tolerance must be positive. Input tolerance: 00042 Pi approximation: 3.1415917721832 Do you vish to approximate pi again? Y Input tolerance: 1E-8 Pi approximation: 3.1415926536236 Do you wish to approximate pi again

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Iv Special Issue On Database Systems For Biomedical Applications Lncs 6990

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Christian Bohm ,Johann Eder ,Claudia Plant

2011th Edition

3642237398, 978-3642237393

Students also viewed these Databases questions

Question

5. Identify the essential functions of a job.

Answered: 1 week ago