
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question

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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 6 steps with 2 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.Similar questions
- write python code for functions:arrow_forwardplease solve as soon as possiblearrow_forwardlanguage: Python Problem: Write a recursive function to add a positive integer b to another number a, add(a, b), where only the unit 1 can be added, For example add(5, 9) will return 14. When creating the function, also create a test case to prove the program works. The pseudocode is: # Base case: if b is 1, you can just return a + 1# General case: otherwise, return the sum of 1 and what is returned by adding a and b - 1arrow_forward
- In C++ language only !!arrow_forwardCreate a c++ program that asks the user to enter all of his 3 quizzes during the preliminary coverage. The program would then compute the average of these 3 quizzes. Afterwards, the program would ask the user again to enter 3 quizzes for his/her midterm coverage. The program again would compute the average for the quizzes for the midterm coverage. Use the math function max() to find out which of the two average grades are highest. Example: Please enter 1st prelim quiz: ____ Please enter 2nd prelim quiz: ___ Please enter 3rd prelim quiz: ___ Please enter 1st midterm quiz: ____ Please enter 2nd midterm quiz: ____ Please enter 3rd midterm quiz: ____ The average of your quizzes in prelims and midterms are: 93 for prelims and 97 for midterms. 97arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

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