C++ for Engineers and Scientists
C++ for Engineers and Scientists
4th Edition
ISBN: 9781133187844
Author: Bronson, Gary J.
Publisher: Course Technology Ptr
bartleby

Videos

Textbook Question
Book Icon
Chapter 6.2, Problem 11E

(Numerical) a. The following is an extremely useful programming algorithm for rounding a real number to n decimal places:

Step 1: Multiply the number by 10 n

Step 2: Add 0.5

Step 3: Delete the fractional part of the result

Step 4: Divide by 10 n

For example, using this algorithm to round the number 78.374625 to three decimal places yields:

S t e p   1 :   78.374625   ×   103   =   78374.625 S t e p   2 :   78374.625   +   0.5   =   78375.125 S t e p   3 :   R e t a i n i n g   t h e   i n t e g e r   p a r t   =   78375 S t e p   4 :   78375   d i v i d e d   b y   103   =   78.375

Using this algorithm, write a C++ function that accepts a user-entered value and returns the result rounded to two decimal places.

b. Enter, compile, and run the program written for Exercise 11a.

Blurred answer
Students have asked these similar questions
Use Newton’s method to: (a) Create a program that computes for the power am/n given a real number a. You are not allowed to use roots, or raise numbers to fractional powers in the formula. [Hint: This value is the solution of xn − am = 0.] (b) Create a program that computes for arcsin(x) of a given number x ∈ [0, 1]. You are not allowed to use inverse trigonometric functions in the formula but trigonometric functions such as sin, cos, tan are allowed.
a) The following is an extremely useful programming algorithm for rounding a real number to n decimal places: Step 1: Multiply the number by 10" Step 2: Add 0.5 for rounding up. Subtract 0.5 for rounding down. Step 3: Delete/remove the fractional part of the result Step 4: Divide by 10" For example, using this algorithm to round the number 78.374625 to three decimal places yields the result of 78.375. write a C++ function that accepts a user-entered real number value and returns the result rounded to n decimal places. (b) Develop, compile, and run a program that accepts user input, uses the function written in part (a) and displays the rounded value to specified number of decimal places.
Q1) Write a computer program that uses Newton's method to find the root of a given function, and apply this program to find the root of the following functions, using co as given. Stop the iteration when the error as estimated by n+1 - Enl is less than 10-6. Compare to your results for bisection. (a) f(x) = 1-2xe-/2, xo = 0; (b) f(x)=5-x-¹, x = ¹; (c) f(x)= x³ - 2x - 5, xo = 2; (d) f(x)=e-2, xo = 1; (e) f(x)=x-e, xo = 1; (f) f(x)=x-x-1, xo = 1; (g) f(x)=x²-sinx, xo =/; (h) f(x)= x³-2,0 = 1; (i) f(x) = x + tan x, zo = 3; (j) f(x)=2x-¹ In x, xo = 3.
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Boolean Algebra - Digital Logic and Logic Families - Industrial Electronics; Author: Ekeeda;https://www.youtube.com/watch?v=u7XnJos-_Hs;License: Standard YouTube License, CC-BY
Boolean Algebra 1 – The Laws of Boolean Algebra; Author: Computer Science;https://www.youtube.com/watch?v=EPJf4owqwdA;License: Standard Youtube License