C++ lab material
How the output should look
Lab 6 - Functions: Taylor Series Objectives Make use of various "pass by value" functions to solve a single problem Apply programming to math (calculus) concepts The cosine of an angle can be computed from the following infinite series: Cos x 1-(x^2/2! ) + (x^4/4!)- Your task is to make a program t manner described above. To do this, you will need to make use of a number of functions and a menu system. hat will calculate Cos x in the Factorial: This should take in a double n. This should return the factorial of n as a double. (You cannot return anything but a double do to the fact that no other data type can hold numbers large enough to support a factorial greater than 20) The formula for factorial is Ex: 5!-5*4 3*2*1 Power Yes, there is already a power function defined in
However, this time around you need of this method. It should take in two numbers as parameters: a double b, representing the base, and an integer e, representing the power you wish to raise it to (exponent.) The method should return the answer as a double. to write your own version These variable names are not help illustrate the requirements. required, just used as examples to Function 1 Write a function that takes in an angle x. Inside the function, compute the cosine of the angle using the first five terms of this series defined above. Print or return the value computed Hint: For loops will allow for a set number of calculations Function 2 Start by reusing the code from function 1. However, instead of calculating just the first five terms, this time you will continue to Function 1: Write a function that takes in an angle x. Inside the function, compute the cosine of the angle using the first five terms of this series defined above. Print or return the value computed. Hint: For loops will allow for a set number of calculations Function 2 Start by reusing the code from function 1. However, instead of calculating just the first five terms, this time you will continue to calculate terms while a given term remains greater than 0.0001 Make sure you print out the final result, and the number of terms used to calculate this result. Hint: Use a while loop for this one. Menu You should set up a menu that will allow the user to pick either of the two functions above (methods for calculating the cos of x) In addition to having options for both of the above described ways of calculating cosine of x, you should include another case/option that will display the cosine of x according to the C++ default Library's function. The code to use the default library function is simply: cos() Run: When running the program, please values in the following order: Option 1, x = 0. Option 2, x-0. Option 3, x = 0 Option 1, x = 1, Option 2, x = 1. Option 3, x = 1 Option 1, x = 2. Option 2, x = 2, Option 3, x = 2. Option 1, x-3. Option 2, x-3. Option 3, x-3 Option 1, x = 4, Option 2, x = 4. Option 3, x = 4 Option 1, x -5. Option 2, x - 5. Option 3, x-5 Option 1, x = 6, Option 2, x-6, Option 3, x-6. run them with the following You will need to turn in your source code (.cpp file) in addition to your output file in a zipped folder. Please submit the zipped folder to D2L SW this Radian 0 Taylorl1 Taylor2 1 Math Function 1 Radian 1 Taylor l = 0.540302 Taylor2 = 0.540303 Math Function = 0.540302 Radian 2 Taylorl--0.416155 Taylor2--0.416147 Math Function0.416147 Radian 3 Taylor! =-0.991 049 Taylor2 0.989994 Math Function0.989992 Radian 4 Taylorl--0.685785 Taylor2--0.653644 Math Function0.653644 Radian 5 Taylor--0.162747 Taylor2- 0.283664 Math Function0.283662 Radian 6 Taylorl--2.80571 Taylor2 -0.960171 Math Function 0.96017