Question
***************** USING THIS TEMPLATE PLEASE #include #include using namespace std; //Funtion prototype double takeInput(); double squareRoot(double userInput); double calculatePctErr(double approximation, double userInput); void outputValues(double approximation,
***************** USING THIS TEMPLATE PLEASE
#include
using namespace std;
//Funtion prototype double takeInput(); double squareRoot(double userInput); double calculatePctErr(double approximation, double userInput); void outputValues(double approximation, double userInput, double pctErr);
int main(void){ double input, guess, pcErr; input = takeInput(); guess = squareRoot(input); pcErr = calculatePctErr(guess, input); outputValues(guess, input, pcErr); return 0; }
//Function that takes user input to calculate an approximate square root double takeInput(){ //Your code goes here }
/*Function that calculates an approximation of a square root using the Babylonian method */ double squareRoot(double userInput){ //Your code goes here }
//Function that calculates the percent error in the approximation double calculatePctErr(double approximation, double userInput){ //Your code goes here }
/*Function that outputs the approximation and actual square root values and percent error value. */ void outputValues(double approximation, double userInput, double pctErr){ //Your code goes here }
1. [30 pts] The Babylonian algorithm to compute the square root of a positive number n is as follows: (a) Make a guess at the answer (you can pick n/2 as initial guess (b) Computer = n/guess (c) Set guess = (guess +r)/2 (d) Go back to step (b) for as many iterations as necessary. More times the repetition, the closer guess gets to the square root of n Your program inputs a double for n from the console, iterates through the Babylo- nian algorithm five times, and outputs the answer as a double to two decimal places to the console. The program should also use the sqrt function from the cmath library to calculate the actual square root of the user input and calculates a % error as follows: Error = abs(guess - actual) * 100/actual Use the abs function from the same cmath library to calculate the absolute value of the difference and output it to two decimal places. Experiment with several inputs and starting values for the guess to test your program for correctnessStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started