Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Show a picture of the completion of a successful run that does not usethe test value from the Example Output section 2. Declare a variable

image text in transcribedimage text in transcribedimage text in transcribedShow a picture of the completion of a successful run that does not usethe test value from the Example Output section

2. Declare a variable in your main function of type int, called S. 3. Get user input for a value for S that is somewhere between 20 and 400 . Note: For most of the labs in this class, we make an assumption that the user is both competent and benevolent. This user always enters values that are correct. LAB QUESTION \#1: Why would it be a security risk in "real life" to make this assumption? What could happen? 4. Make an initial approximation for S, which we will call x0. For this lab, we will assume that x0=21S. So initialize x0 to be one half of S Note: It is understood that you cannot make your variables with subscripted names. You should use x0 through x9. LAB QUESTION \#2: Why is it a logic error to make your x0 variable of type int? 5. After you have your initial approximation x0, use that number with the general formula below to calculate the next, closer approximation, called x1, using an assignment statment to save this value. xn+1=21(Xn+xnS) Note: Said in English, this means that the next value of x is equal to one-half of the sum of the current x and the quantity S divided by the current x. Essentially, you are taking the average of xn and xnS. (The average of two things is the sum of the two things, divided by 2) So this means that x1=21(x0+x0S) and xn+2=21(x1+x1S), etc. 6. Use x1 to calculate x2,x2 to calculate x3, etc. all the way to x9 (We could keep going, but 10 terms, x0 to x9, should be more than enough to approximate to desired precision) NOTE: Because we don't (theoretically) know about loops yet, there is a lot of duplication in this code. That is fine. 7. Print the value of the variables, S and x0 to x9 to the screen. 3 Example Output The next section shows results of a successful runs, and represents the output of a correctly functioning program. You may use this as test data to ensure that your program is functioning, if you wish. 1 Introduction For this lab, you are to assume that you are a junior programmer and your boss has just asked you to implement a program that finds the square root of a number. She tells you that she wants you to use a simplified version of Newton's Method to find it, because she's not sure that the built-in C++ square root method is working. You decided that you should look at the Wikipedia page for Newton's Method 1, but unless you are pretty mathematically inclined, it doesn't really make much sense to you. So your boss clarifies that you are required to use a simplified version of the method, called the Babylonian Method 2, because it's a lot easier to use than the normal Newton's method, which uses calculus. NOTE: Neither one of those Wikipedia pages are required to complete the lab. They are there for background information for students who wish to delve further into the algorithm involved and the mathematics behind the lab 2 Assignment Your boss explains the assignment like this: There is some starting number, called S, that we want to find the square root of. (i.e. we want to find S ) Your program should: 1. Have a header comment and main method that looks like this: (you may cut and paste this code, it shouldn't have issues) / Newton - Calculates the square root of a number with Newton's Method. Author: YourName Due: 2022-MM-DD Version: 1.0 Lab Questions: 1.) answer ... * \#include using namespace std; int main() \{ I/code will go here later! \} \( 1_{\text {https://en, wikipedia,org/triki//Nerton's_method }} \) 2 https://en.wikipedia.org/wiki//Methods_of_computing_square_rootsmBabylonian_ method Page 1 3.1 Example Run The user entered a number in range, and the program printed the results. Enter an integer, S: 25 S=25 x0=12.5000 x1=7.2500 x2=5.3491 x3=5.0113 x4=5.0000 x5=5.0000 x6=5.0000 x7=5.0000 x8=5.0000 x9=5.0000

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions