Assignment 06

Due: Monday, March 17, 2014 at noon 100 pts

Instructions: You know how to submit; do it in the usual way. However, this time you will submit multiple files for this programming project. The cssubmit script will work as usual, picking up all .cpp and .h files in the current directory. So, make sure you have created a separate directory for your hw 6 program. Do not create subdirectories in the hw6 directory.

5. Exp(x)

6. Sinh(x) (hyperbolic sine)

7. Quit

Now, before you non-mathematicians have a conniption1 fit, we will explain here below how to handle all the above. OVERALL, you are required to use functions for much of this assignment. Each of the options 1 through 6 will contain calls to functions, which themselves may contain calls to other functions. None of the computations so designated above should be done with code right there in the associated case. As an example, under case 1, your code should call a function to retrieve user input.

Factorial: Handle this option exactly how you handled it before in hw 4. That is, cast the input to an integer first.

Nth root: The formula for the Nth root is given by

xk+1 = ( (N-1) xk + A / xkN-1 ) / N , k = 0, 1, 2, ....

Thus, the square-root formula would be x = (x + A/x)2, without the subscripts. For the fifth root, x = (4x + A/x4)/5. Etc. Of course, upon option 3 being chosen, you will have to prompt the user for the value of N, the root they desire (you know, 2 for square root, 3 for cube root, etc.) NOTE: use A (that's what you are trying to find the root of) as your initial guess, x0, at the root. Also, iterate this formula 8 times.

Power of x: This is self explanatory. And you will also need to input from the user the power of x they desire.

Exponential of x: You know that the formula for ex is 1 + x + x2/2 + x3/6 + x4/24 + ... = x0/0! + x1/1! + x2/2! + x3/3! + ... Now, since you have functions for xn and n!, use them to compute this. For this choice, use 10 terms.

Sinh(x): This is the "hyperbolic sine of x". It is given by sinh(x) = x + x3/3! + x5/5! + ... And, again use your functions to compute this. For this choice, use 5 terms. Alternatively, sinh(x) = (ex - e-x) / 2.

Additional Notes: You are not to use the cmath library; you are to code these mathematical functions yourself. You are to use functions fully, and to provide proper function descriptions, pre- and post-conditions. You are to do this project in 3 files.

When you submit: During the submit process,

  • choose option 1, enter 0

  • choose option 2

  • choose option 1, enter 27

  • choose option 3, enter for the 3rd root

  • choose option 1, enter 2

  • choose option 5

  • choose option 6

  • quit

As always, don't hesitate to ask Ralph any questions about this assignment you may have.

1I have no idea what this means, but we used to say it as kids. I think it's sorta like a heart attack.

Specifications: Your program will again be menu driven and operate pretty much the same way. This time the menu will be the following Menu

1. Enter a positive number, x

2. Factorial (of integer part of x)

3. Nth root of x

4. Power of x, xn

Background: For assignment #4, you wrote a program to help Ralph impress Lisa with his advanced math skills. So far, so good. However, Ralph is now a bit more demanding. He has caught wind of this new concept in math/programming - functions! Ralph is now serious about having his code written neatly, cleanly, modifiable, serviceable. He wants you to write a similar program (does math), but this time he wants you to use functions fully. And, he has new topics in math he is trying to learn, so your menu of options is going to change up a bit.