Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Sample Lab Report: Define inputs and relationships: The inputs the user provides will be the coefficients of the quadratic equation coefa * x 2 + coefb * x + coefc = 0 , coefa, coefb and coefc There are no constants needed as input to this algorithm. The value of the root x of the quadratic equation is − coefB ± coef b 2 − 4 × coefa × coefc root = x = 2 × coefa The discriminant of the quadratic equation will be determined to help discriminate between different kinds of solutions of the quadratic equation. The discriminant is descri min ant = coef b 2 − 4 × coefa × coefc Define outputs: Any one of the following, the output chosen will be determined by the values of the coefficients 1. When the discriminant is < 0, the solutions are imaginary and the following message should be printed to the output window before the program terminates: There are no real roots 2. When the discriminant = 0, the solution is a pair of identical roots and the following message should be printed before the program terminates; Note that the number printed in the message will be the actual value of the double real root. . There is one double root, root1 = root2 = 4.00 3. When the discriminant > 0, the solution includes two real roots and the following message should be printed before the program terminates; Note that the numbers printed in the message will be the actual values of the two real roots. There are two real roots, root1 = -1.00 and root2 = 3.00 4. When coefa = 0, the solution is the solution to a linear equation and therefore the solution is a single root. In the case the following message should be printed. Note that the number in the following message will be the actual value of the single root There is one real root, root = 2.00 5. When all coefficients are 0 then any real number can be a root of the quadratic equation. In this case the following message should be printed. Every real number is a root 6. When coefa=0, coefb=0, coefc not zero then there is no solution to the quadratic equation. Print the following message There are no real roots State the problem Assume that the coefficients of a quadratic equation, coefa, coefb and coefc in the equation coefa * x 2 + coefb * x + coefc = 0 are given, that is they will be supplied by the user of the program. Determine the real roots of the quadratic equation specified by the given coefficients, or indicate that there are no solutions. The solution must handle all possible sets of coefficients the user might enter, and must print a message indicating there are no real roots if all roots of the quadratic equation are complex or if there are no roots of the quadratic equation. The solution should recognize when there is a repeated root of the quadratic equation, when there is a single root, and when there are two distinct roots. Final Detailed Algorithm Remember the algorithm does not contain language specific information For your lab report you will submit EITHER a flow chart OR a written list of steps not both. I have provided a sample of each here in the sample lab report. Start main Prompt for confidents using prompt specified in problem coefa, coefb, coefc Print summary of coefficients using format specified in problem Calculate discriminant coefb*coefb - 4*coefa*coefc coefa = 0 N discriminant = 0 Y Y N Y discriminant < 0 N coefb = 0 Y root1 = -coefb /(2*coefa) N root1 = (-coefb + discriminant) / (2*coefA) root1 = -coefC / coefb There is one real root which occurs twice. root1= ….. one real root root1= ….. coefc = 0 Y All values of x are roots root2 = (-coefb - discriminant) / (2*coefa) The two real roots are root1=…… and root 2=….. N A There are no real roots A End main Final Detailed algorithm 1. Prompt for coefa using the prompt a. “Enter the value of the coefficient of the second order (x squared) term:” b. Read the value of coefa 2. Prompt for coefb using the prompt a. “Enter the value of the coefficient of the first order term:” b. Read the value of coefb 3. Prompt for coefa using the prompt a. “Enter the value of the constant term:” b. Read the value of coefc 4. Read in coefa, coefb, and coefc, the coefficients of the quadratic equation 5. Print 2 blank lines after your input is complete 6. Print a summary of the input values of the coefficients of the quadratic equation using fixed point format with three digits after the decimal. The values should be printed within the following messages (replacing the numbers shown as examples). The coefficients of the quadratic equation are: Coefficient of the second order term is 1.323, Coefficient of the first order term is 3.645, Coefficient of the constant term is 2.152 7. Print a three blank lines after printing the coefficients 8. Calculate the discriminant: coefb*coefb - 4*coefa*coefc 9. If coefa=0 and coefb=0 and coefc=0 then a. Print the string “Every real number is a root” b. Exit the program 10. if coefa = 0 and coefb = 0 and coefc ≠ 0 then a. Print the string “There are no real roots” b. Exit the program 11. If coefa= 0 and coefb ≠ 0 then a. Solve for the single root -coefc/coefb b. Print the string “There is one real root, root1 = ” c. Print the value of the single root d. Exit the program 12. If the discriminant (b*b=4ac) is zero a. Calculate the single root -coefb b. Print the string “There is one double root, root1 = root2 = “ c. Print the value of root1 d. Exit the program 13. If the discriminant (b*b=4ac) is positive a. Solve the quadratic equation for two identical roots b. root1 = − coefb + coef b 2 − 4 × coefa × coefc 2 × coefa − coefb − coef b 2 − 4 × coefa × coefc root 2 = 2 × coefa c. Print the string “There are two real roots, root1 = “ d. Print the value of root 1 e. Print the string “ and root 2 = “ f. Print the value of root2 g. Exit the program 14. If the discriminant (b*b=4ac) is negative a. The quadratic equation has no real roots. b. Print the string “There are no real roots” c. Exit the program Test plan for quadratic root solver (to be used for grading of your codes) 1. coefB 2 − 4(coefA)( coefC ) > 0; resulting in two real roots, the common case Sample test data for this case coefa =5, coefb =9 and coefc =2 Enter the value of the coefficient of the second order (x squared) term: 5.0 Enter the value of the coefficient of the first order term: 9.0 Enter the value of the constant term: 2.0 The coefficients of the quadratic equation are: Coefficient of the second order term is 5.000 Coefficient of the first order term is 9.000, Coefficient of the constant term is 2.000 There are two real roots, root1 = -0.26 and root2 = -1.54. 2. coefB 2 − 4(coefA)( coefC ) < 0; resulting in imaginary roots (no real roots) Sample test data for this case coefa =3, coefb =4 and coefc =5 Enter the value of the coefficient of the second order (x squared) term: 3.0 Enter the value of the coefficient of the first order term: 4.0 Enter the value of the constant term: 5.0 The coefficients of the quadratic equation are: Coefficient of the second order term is 3.000 Coefficient of the first order term is 4.000, Coefficient of the constant term is 5.000 There are no real roots. 3. coefB 2 − 4(coefA)( coefC ) = 0; resulting in two identical real roots Equation for the solution for the root is x = - coeffB / ( 2 * coeffA ) Sample test data for this case coefa =4, coefb =8 and coefc =4 Enter the value of the coefficient of the second order (x squared) term: 4.0 Enter the value of the coefficient of the first order term: 8.0 Enter the value of the constant term: 4.0 The coefficients of the quadratic equation are: Coefficient of the second order term is 4.000 Coefficient of the first order term is 8.000, Coefficient of the constant term is 4.000 There is one double root, root1 = root2 = -1.00. 4. coefa =0 coefb ≠0 Equation for the solution for the root is x = - coefc / coefb Prints: one real root, root1= and the value of the root Sample test data for this case coefa = 0.0, coefb = 5.0, coefc = 25.0 Enter the value of the coefficient of the second order (x squared) term: 0.0 Enter the value of the coefficient of the first order term: 5.0 Enter the value of the constant term: 25.0 The coefficients of the quadratic equation are: Coefficient of the second order term is 0.000 Coefficient of the first order term is 5.000, Coefficient of the constant term is 25.000 There is one real root, root1 = -5.00. 5. coefa =0 coefb = 0 coefc =0 The quadratic equation reduces to 0.0 = 0.0; all values of x are roots Prints all values of x are roots of the equation Sample test data for this case coefa = 0.0, coefb = 0.0, coefc =0.0 Enter the value of the coefficient of the second order (x squared) term: 0.0 Enter the value of the coefficient of the first order term: 0.0 Enter the value of the constant term: 0.0 The coefficients of the quadratic equation are: Coefficient of the second order term is 0.000 Coefficient of the first order term is 0.000, Coefficient of the constant term is 0.000 All values of x are roots 6. coefa =0 coefb = 0 coefc ≠0 The quadratic equation reduces to coefc = 0.0. If coefc is not zero the equation has no solutions. Prints “There are no real roots” Sample test data for this case coefa = 0.0, coefb = 0.0, coefc = 25.0 Enter the value of the coefficient of the second order (x squared) term: 0.0 Enter the value of the coefficient of the first order term: 0.0 Enter the value of the constant term: 25.0 The coefficients of the quadratic equation are: Coefficient of the second order term is 0.000 Coefficient of the first order term is 0.000, Coefficient of the constant term is 25.000 There are no real roots