Exercise #3, Functions Given a positive integer n and a floating point number x between 0.0 and 360.0. The objective of this exercise is to write a C++ program to compute the below math equations: y = xx π/180 yll y5 3! 5! y7 y9 7! 9! + 11! We decompose the eqations into 5 simplified expressions as follows: 1. y=r(x) = x x π/180 2. p(y, k) = yk 3. f(k)= k! 4. q(y,k) = P(y.k) f(k) 5. S(y,n)=y-q(y,3)+q(y, 5)-q(y, 7) + q(y, 9) -q(y, 11)+...+q(y,n) S(y, n) = y- + y3 where k is an integer smaller than or equal to n Write C++ functions to calculate each of the above expressions. In your main, you prompt the user to enter x and n, control the user input, then call function S(x, n) to compute expression 5. Function S(x, n) will call function r(x) to get y, then it calls other functions as needed to complete the computations and display your result at the end. e.g. Value of x: 30 Number of interations n: 12 S(30,12): 0.5 Method 1 int fact, sign=-1; float y = x*M_PI/180, p, sum = 0; for(int i=1;i

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Exercise #3, Functions
Given a positive integer n and a floating point number x between 0.0 and 360.0. The objective of
this exercise is to write a C++ program to compute the below math equations:
y = xx π/180
уз y5 y7
39
ylı
3! 5! 7! 9! 11!
We decompose the eqations into 5 simplified expressions as follows:
1. y=r(x) = x x π/180
2. p(y, k) = yk
where k is an integer smaller than or equal to n
3. f(k)= k!
4. q(y, k) =
5.
S(y,n)=y-q(y, 3) + q (y, 5)-q(y, 7) + q(y, 9)-q(y, 11) +±q(y,n)
p(y,k)
f(k)
S(y, n) y- +
Method 1
int fact, sign=-1;
float y = x*M_PI/180, p, sum =0;
for(int i=1;i<=n; i+=2)
{
Write C++ functions to calculate each of the above expressions. In your main, you prompt the user
to enter x and n, control the user input, then call function S(x, n) to compute expression 5.
Function S(x, n) will call function r(x) to get y, then it calls other functions as needed to complete
the computations and display your result at the end. e.g.
Value of x: 30
Number of interations n: 12
S(30,12): 0.5
p= 1;
fact= 1;
for(int j=1; j<=i; j++)
{
Two other programmers calculated the above expression using different methods, in Method 1 (see
below), the programmer used two loops, in Method 2 the programmer used one single loop.
Method 2
int fact, sign=-1;
float y = x*M_PI/180, p, sum = 0;
for(int i=1; i<n; i+=2)
{
p= p*y;
fact=fact*j;
}
+
sign=-1*sign;
sum += sign*p/fact;
+...+
}
yn
n!
if(i==1){
p= y;
fact= 1;
}
else {
p= p*y*y;
fact fact* (i-1)*(i);
}
sign=-1*sign;
sum += sign*p/fact;
Try to understand the above methods, test them, then compare the three implementations (yours, method1, and
method2) to find out: which one is the best, what are the advantages and disadvantages of each method.
By the way, when you test the three methods: They all should GIVE THE SAME RESULT. This is one way to verify that
your implementation is correct.
e.g. S(30,12)= 0.5
S(45,12)= 0.707107
S(60,12)=0.866025
Transcribed Image Text:Exercise #3, Functions Given a positive integer n and a floating point number x between 0.0 and 360.0. The objective of this exercise is to write a C++ program to compute the below math equations: y = xx π/180 уз y5 y7 39 ylı 3! 5! 7! 9! 11! We decompose the eqations into 5 simplified expressions as follows: 1. y=r(x) = x x π/180 2. p(y, k) = yk where k is an integer smaller than or equal to n 3. f(k)= k! 4. q(y, k) = 5. S(y,n)=y-q(y, 3) + q (y, 5)-q(y, 7) + q(y, 9)-q(y, 11) +±q(y,n) p(y,k) f(k) S(y, n) y- + Method 1 int fact, sign=-1; float y = x*M_PI/180, p, sum =0; for(int i=1;i<=n; i+=2) { Write C++ functions to calculate each of the above expressions. In your main, you prompt the user to enter x and n, control the user input, then call function S(x, n) to compute expression 5. Function S(x, n) will call function r(x) to get y, then it calls other functions as needed to complete the computations and display your result at the end. e.g. Value of x: 30 Number of interations n: 12 S(30,12): 0.5 p= 1; fact= 1; for(int j=1; j<=i; j++) { Two other programmers calculated the above expression using different methods, in Method 1 (see below), the programmer used two loops, in Method 2 the programmer used one single loop. Method 2 int fact, sign=-1; float y = x*M_PI/180, p, sum = 0; for(int i=1; i<n; i+=2) { p= p*y; fact=fact*j; } + sign=-1*sign; sum += sign*p/fact; +...+ } yn n! if(i==1){ p= y; fact= 1; } else { p= p*y*y; fact fact* (i-1)*(i); } sign=-1*sign; sum += sign*p/fact; Try to understand the above methods, test them, then compare the three implementations (yours, method1, and method2) to find out: which one is the best, what are the advantages and disadvantages of each method. By the way, when you test the three methods: They all should GIVE THE SAME RESULT. This is one way to verify that your implementation is correct. e.g. S(30,12)= 0.5 S(45,12)= 0.707107 S(60,12)=0.866025
Expert Solution
steps

Step by step

Solved in 6 steps with 2 images

Blurred answer
Knowledge Booster
Declaring and Defining the Function
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education