Question: Please write the C++ code. Follow all instructions when writing the code. Please answer question at the end as well PART 2: ROUND-OFF ERROR You

Please write the C++ code. Follow all instructions when writing the code. Please answer question at the end as well

Please write the C++ code. Follow all instructions when writing the code.

Please answer question at the end as well PART 2: ROUND-OFF ERROR

PART 2: ROUND-OFF ERROR You should know from ECE2020 that a digital representation of certain real numbers is only an approximation. For example, irrational numbers such as T, e, V2, etc...have only a finite number of digits that can be represented in a digital computer. The two main representations that we will use in C++ will be single precision (32-bit) and double precision (64-bits) numbers. In each of the number formats, a certain number of bits is dedicated to the exponent (8 bits for single precision and 11 bits for double precision), the mantissa (23 bits for single precision and 52 bits for double precision), and I bit for the sign bit. I would like for you to use a C++ program to calculate the roots of the following quadratic equation: 2x2 6000.002x + 60 Please use the following non-conventional Muller's method for the quadratic equation in your program to solve for the roots 2c In fact, I would like for you to use a global function that has four parameters that you pass to it (i.e. a flag to indicate if it should return the plus or minus solution, a, b, and c). You should make one function using only float's and the other only double's so that you can compare the results. To calculate the square root, you can use the sqrt(x) function that is a part of the cmath library. To include this in your program you must have the follow ing preprocessor directive. # include The actual exact roots of this equation are X1 =-0.001 and X2 =-3000. Please compare how your program calculates this with first float types and then with doubles. You can calculate the error given by: % error-100 * (actual-approximation)/actual QUESTION YOU NEED TO ANSWER: Given the fact that both roots can easily be represented with a float, why do you get a couple percent error for one of the roots? In your Labl directory, please call your source code lab1part2.cc. Possible sample output is as follows. Using the float data type the roots are: x1 you calculate> % error = you calculate> you calculate> % error = Using the double data type the roots are: x1 x2 % error % error Problem 2: ROUND-OFF ERROR Please turn in the program you wrote to calculate the values in the following chart. Using a float x1 = %error from actual root- %error from actual root %error from actual root- %error from actual root x2= Using a double x1 = x2 Given the fact that each root can easily be represented in a float. Why do you think that there was error using the floating point? Be as specific as you can. You might write your answer on the back of this sheet

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!