Question 2 (10 marks) Ever wonder how the tandard C math functions make their ca
ID: 3598324 • Letter: Q
Question
Question 2 (10 marks) Ever wonder how the tandard C math functions make their calculations. This question lets you explore how to compute hyperbolic sine of any value ofx, sinhx). The following infinite series gives the value of sinh(x): Equation 1 Such series serves as a basis for calculating sinh(x in a program i.e. in a function). O of terms for computing the value (it is impossible to compute an infinite number of terms). Thus the above equation becomes: f course a program has to limit the number Equation2 Develop software that meets the following requirements: Prompts the user for the value ofx and the number of terms, n, in the series used to compute sinh(r). o Check that the number of terms given by the user is positive. . Computes the value of sinhx) using the above series and displays the results to the user · Prompts the user to quit the program with the message ..Do you wish to quit (yn)?', and read in a character. Repeat the above steps if the user enters and stop the program if the user answers 'n Keep prompting the user if an invalid answer is entered. Print the message"Program terminated" when the program terminates. · Respect the following guidelines: DO NOT use arrays or DONOT use standard math functions i or structures in your answer. your answer. Have the main function call a separate function, getInput, to get input values from the user. Recall that you can pass addresses to simple variables to a function in a parameter so that the function can fill in the variable value. Have the main function call a separate function, sinHyper, to compute the value of sinh(x). o Given that the powers ofx in the numerator and the factorial in the denominator will become v rery 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 is calculated from the previous term. If we number the terms using i starting at 0 (and the term to x), then the term t can be computed from the previous term tas follows: o o The above computation does not involve the same large mumbers as the numerator denominator of the terms in Equation 2. Equation 2). o Recall that fflush function should be called before reading in a character input from the user. o Ifn is the number of terms used to calculate sinh(x), then i varies between 0 and n-1 (i.e. N-n-l in A loop to control termination of the program is part of the main function. .Explanation / Answer
#include<iostream>
using namespace std;
int main(){
string ch;
double x;
int n;
while(1){
cout << "Enter the value of x :";
cin >> x;
cout << "Enter the value of n :";
cin >> n;
double value;
for(int i = 0; i<n; i++){
if (i==0)
value = x;
else
value = value + (double)((x*x)/((2*i+1)*2*i))*value;
}
cout << "sinh(" << x <<") is " << value << endl;
cout<< "Do you wish to quit?(y/n) :";
cin >> ch;
if (ch[0] == 'y')
break;
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.