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 S(y, n) = y- y3 y5 y7 v9 y11 + 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 3. f(k) = k! where k is an integer smaller than or equal to n 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) 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. p= p*y; fact=fact*j; } sign=-1*sign; sum += sign*p/fact; ± yn n! if(i==1){ p= y; fact= 1; } else { int fact, sign=-1; float y = x*M_PI/180, p, sum = 0; for(int i=1;i<=n; i+=2) { p= p*y*y; fact= fact* (i-1)*(i); } Method 2 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
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 S(y, n) = y- y3 y5 y7 v9 y11 + 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 3. f(k) = k! where k is an integer smaller than or equal to n 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) 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. p= p*y; fact=fact*j; } sign=-1*sign; sum += sign*p/fact; ± yn n! if(i==1){ p= y; fact= 1; } else { int fact, sign=-1; float y = x*M_PI/180, p, sum = 0; for(int i=1;i<=n; i+=2) { p= p*y*y; fact= fact* (i-1)*(i); } Method 2 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
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
Related questions
Question
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 4 images
Knowledge Booster
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.Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education