Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ programming ut of In addition to the cost pre-defined function, which is found in the 'cmath' library, the cosine of an angle x (given
C++ programming
ut of In addition to the cost pre-defined function, which is found in the 'cmath' library, the cosine of an angle "x" (given in radians), can be estimated using the following series (-1)k cos(x) (2k)! ko The series can be written as: 22% + x2 cos(x) = 1 - + 2! 4! 6! 8! Write a C++ program that reads a list of angles (in degrees) and the values of Kik represents the number of terms in the above series) from an input file called (angles.txt). The program should only accept angles between 0 and 180. When invatid angle is read from the file, an error message should be displayed (see the given sample output) The program should include the following user-defined fuctions: 1. Function is called fact, which is used to compute the the factorial to be used in the above series 1. Function 2 is called series_sum, which is used to compute the estimated cosine as given by the above series and calculate the Erter Marion (difference between cos(x) given by cmath and the estimated cos(x) based on the given series and send the program outputs to another fie called fresults.txt) as shown below. Hints the same given data in the input file (angles.txt) to check your code. The program should include the following user-defined functions 1. Function is called fact, which is used to compute the the tactorial to be used in the above series. 1. Function 2 is called series_sum, which is used to compute the estimated cosine as given by the above series and calculate the Error Marion Idifference between cose given by emath and the estimated cosbd based on the given series) and send the program outputs to another called results.txt) as shown below HintUse the same given data in the input file (angles.txt) to check your code. Do not use materials that we did not teach you such as struct, pointers, and 2-d arrays angles.txt 4 5 190 108 25 33 se 86 3 3 4 results.txt 190 100 25 33 50 86 COSx> Estimated Value Error Margin ** angle is out of the range ** -0.173871 -0.173873 1.64296e-006 0.906284 0.906284 3.255e-008 0.83863 8.83863 2.99544e-687 0.642701 0.642693 8.28016e-606 0.0695623 8.0695781 1.57461e-005 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