Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

8:29 PM Sun Feb 10 26% uottawa. brightspace.com 4 of 5 Question 2 (15 marks) cosh(x) Ever wonder how the standard C math functions make

image text in transcribedimage text in transcribed

8:29 PM Sun Feb 10 26% uottawa. brightspace.com 4 of 5 Question 2 (15 marks) cosh(x) Ever wonder how the standard C math functions make their calculations. This question lets you explore how to compute hyperbolic cosine of any value ofx, cosh(x). The following math infinite series gives the value of cosh(x): cosh x = 1+-+-+-+ Equation 1 2! 4!6! Such series serves as a basis for calculating cosh(r) in a program (i.e. in a function). To allow a computer program to calculate cosh(x), the number of terms for computing the value must be limited (it is impossible to compute an infinite number of terms). Thus the above equation is changed to: cosh x +-+-+-+ . .. = Equation 2 (2i)! Develop software that meets the following requirements: Prompt the user for the value of x and the number of terms, n, in the series used to compute cosh(r). Use a function, getNumTerms, to get the value for n (the functions returns the value ofn). The function must ensure that the user returns a value for n that is strictly positive (greater than 0) The main function shall call this function o Compute the value of cosh(x) using the above series and displays the results to the user Use a function, coshyper, to compute and return the value of cosh(x). The function receives the values of x and n. In the function use a loop to compute the values of the terms of the series and accumulate the values in a variable Given that the powers of x, x2, in the term numerator and the factorial. (2i), in the term denominator will become very large in a very few terms, calculating the values of each term separately will quickly reach the limit of the computer Use a strategy where the value of a term of equation 2 is calculated from the value of the previous term. o o o " The terms of the equation are numbered with i where i starts at 0: to, ti, t2, ..., tN. Thus equation 2 can be expressed as 2i)! where2! Note now that the term t can be computed from the previous term t as follows: (2i) (2i-1) The above computation does not involve the same large numbers as the numerator'denominator of the terms in Equation 2. Note that term to is known to have the value 1 " o Ifn is the number of terms used to calculate cosh(x), then i varies between 0 and n- (i.e. N- n 1 in Equation 2) In the function main, prompt the user to quit the program with the message "Do you wish to quit (y)? ", and read in a character. Repeat the above steps if the user enters 'n' and stop the program if the user answers 'y'. Keep prompting the user if an invalid answer is entered i.e. the user enters a character other than 'y' or 'n'). Print the message "Program terminated" when the program terminates. 4 8:29 PM Sun Feb 10 26% a uottawa.brightspace.com 5 of 5 Respect the following guidelines: DO NOT use arrays or structures in your answer DO NOT use standard math functions in your answer Recall that fflush function should be called before reading in a character input from the user. To answer this question, please provide 1) The source code to your program in a C file (DO NOT insert the source code into your assignment file, PDF file) 2) Insert the output for the following test cases into your assignment document. Include testing of bad values for n and the answer when prompting to quit (number of terms) cosh(x) 0 35 15.3 5.60E-03 1543080635 2.352409615 7.93007E+14 2.20636E+06 1.00001568 50 30 Note that the values in the above table are calculated using Excel; the software may not give identical results, particularly for low value of n. The following shows a sample output that tests the above values as well as improper input. 3.Q lease enter a real value for x: 0 o you want to quit o you want to quit (y): b o you want to quit n): o you want to quit y) o you want to quit yn o you want to quit yn) you want to quit (y) n lease enter a real value for x: 1 ohinbodebte you want to quit (y): n lease enter a real value for x: -1.5 osh(-1 How many to you want to quit y) n lease enter a real value for x: 35 osh (35.000000) is 1.26797e+012 many terms to use: you want to quit Cy n lease enter a real value for x: -15.3 osh(-1 How many terms to use: ) is 2. 20636e+006 you want to quit y n): n lease enter a real value for x 5.6e-3 many terms to cosh ( Do you want to quit (y): y rogram terminated rocess returned (Ox0) execution time 156.931 s ress any key to continue

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

More Books

Students also viewed these Databases questions

Question

If you were forced to give up one sense, which would it be? Why?

Answered: 1 week ago