Question: I have finished the program but stuck with the main function pls write the main function using argv and args #include #include #include #include using

I have finished the program but stuck with the main function pls write the main function using argv and args
 
 
#include #include #include #include using namespace std; double sqrt(double num, float epsilon=1e-7) { if(num == 0) return 0; if(num == 1) return 1; if(num<0) return std::numeric_limits::quiet_NaN(); // Assuming the sqrt of num as num only double x = num; // The closed guess will be stored in the root double root; while (1) { // Calculate more closed x root = 0.5 * (x + (num / x)); // Check for closeness if (abs(root - x) < epsilon) break; // Update root x = root; } return root; } int main() { } 
Develop a program in sqrt.cpp to compute the square root of a double using Newton's method. The main function should take in either one or two command line arguments, both of which are doubles. The first argument is the number of which to take the square root. It is, of course, a required argument. The second argument is optional. It is the value of epsilon, the amount by which the abs(last_guess - next_guess) is allowed to differ. If no argument is supplied, espilon should be set to 1e-7, which is 10-7. You MUST implement in your code a function that has the following header: double sqrt(double num, double epsilon) The algorithm breaks down as follows: Return numeric_limits::quiet_NaN(), if the num < 0. This constant is found in the limits header. Return num, if num is 0 or 1. Repeat next_guess = (last_guess + num/last_guess) / 2 until abs(last_guess - next_guess) <= epsilon. Ultimately, return the last value of next_guess. The output should be displayed with fixed notation and 8 digits of precision after the decimal point. You will need to include the iomanip header to modify the output format. Use the following script Download scriptto test your work. It must pass the test cases on your Ubuntu virtual machine. Copy the script to the folder where your source code and makefile Download makefilereside, and run it with the command:
 
 
 
run_test_with_args "" "Usage: ./sqrt  [epsilon]" run_test_with_args "10 11 12" "Usage: ./sqrt  [epsilon]" run_test_with_args "x" "Error: Value argument must be a double." run_test_with_args "x 0.1" "Error: Value argument must be a double." run_test_with_args "10 x" "Error: Epsilon argument must be a positive double." run_test_with_args "10 0" "Error: Epsilon argument must be a positive double." run_test_with_args "10 -1" "Error: Epsilon argument must be a positive double." run_test_with_args "-1" "nan" run_test_with_args "-1 0.1" "nan" run_test_with_args "0" "0.00000000" run_test_with_args "1" "1.00000000" run_test_with_args "4" "2.00000000" run_test_with_args "1048576" "1024.00000000" run_test_with_args "10" "3.16227766" run_test_with_args "734658345" "27104.58162378" run_test_with_args "734658345 100" "27104.58183928" run_test_with_args "734658345 10" "27104.58183928" run_test_with_args "734658345 1" "27104.58162378" run_test_with_args "20.0 1" "4.47831445" run_test_with_args "20.0 0.1" "4.47214022" run_test_with_args "20.0 0.01" "4.47214022"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!