Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Top of Form The cosine of an angle can be computed from the following infinite series: Your task is to make a program that will

Top of Form

The cosine of an angle can be computed from the following infinite series:

image text in transcribed

Your task is to make a program that will calculate Cos x in the manner described above. To do this, you will need to make use of a number of functions and a menu system.

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:

n! = n*(n-1)*(n-2) * * 1

Ex: 5! = 5 * 4 * 3 * 2 * 1

Power:

Yes, there is already a power function defined in . However, this time around you need to write your own version 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.

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 Librarys function. The code to use the default library function is simply: cos(x);

Run:

When running the program, please run them with the following 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.

Cos x-1 (x*2/2!) +(x 4/4!) - (x6/6!)(x^n!) (-1)"12n

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

Database Design And SQL For DB2

Authors: James Cooper

1st Edition

1583473572, 978-1583473573

More Books

Students also viewed these Databases questions

Question

6. Have you used solid reasoning in your argument?

Answered: 1 week ago