Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a C++ program call QuadraticSolver that prompts the user for the coefficient of the quadratic term, the coefficient of the linear term, and the
Write a C++ program call QuadraticSolver that prompts the user for the coefficient of the quadratic term, the coefficient of the linear term, and the constant term of a quadratic equation. The program then invokes the quadToString function with the relevant arguments to display the quadratic equation and determines its discriminant, roots, axis of symmetry, vertex x-intercepts and y-intercept, invoking the appropriate sub-functions, where applicable. It also determines whether the parabola is concave upward or downward. A parabola is concave upward if the coefficient of its quadratic term is positive and concave downward when the coefficient of the quadratic term is negative. Write the program incrementally. Write a preliminary version of the progranm so that it prints a message indicating that the equation is not quadratic if the input for the quadratic coefficient is 0 and calls the quadToString func- tion with the relevant arguments to print the quadratic equation in standarod form when a non-zero coefficient is entered for the quadratic term. You can then define the discriminant and solve sub-functions and add code to com pute the roots and all the properties of the equation, calling the appropriate sub-functions where applicable. You may also want to incrementally add the code for solving the equation: First, the code to solve an equation whose ir- rational part is 0, second, the code to solve the equation when it has two real roots and, finally, the code to solve the equation when its roots are complex pical sample runs of the program should appear as shown below: Listing 1: Sample Run l Enter the coefficient of the quadratic term -> 1 2 Enter the coefficient of the linear term -> -6 3 Enter the constant term -> 9 5 For the quadratic equation x2 - 6x + 9- 0 6 7Discriminant: 0.000 Axis of symmetry: x = 3.000 9 Vertex (3.000, 0.000) 10 y-intercept: (0.000, 9.000) 11 x-intercept: (3.000, 0.000) 12 Shape: Concave upward 13 Root: x -3.000) Listing 2: Sample Run 1 Enter the coefficient of the quadratic term- -4 2 Enter the coefficient of the linear term -> 0 3 Enter the constant term-> 64 5 For the quadratic equation -4x2 + 640 6 7 Discriminant: 1024.000 8 Axis of Symmetry:x-0.000 9 Vertex: (0.000, 64.000) 10 y-intercept: (0.000, 64.000) 11 x-intercepts: (4.000, 0.000) and (-4.000, 0.000) 12 Shape: Concave downward 13 Roots:x--4.000, 4.000 Listing 3: Sample Run 1 Enter the coefficient of the quadratic term -> 3 2 Enter the coefficient of the linear term -> 45 3 Enter the constant term -> 0 5 For the quadratic equation 3x^2 + 45x 0: 6 7 Discriminant: 2025.000 Axis of Symmetry: x -7.500 9 Vertex: (-7.500, -168.750) 10 y-intercept: (0.000, 0.000) 11 x-intercepts: (-15.000, 0.000) and (0.000, 0.000) 12 Shape: Concave upward 13 Roots: x -t0.000, -15.000 Listing 4: Sample Run 1 Enter the coefficient of the quadratic term -> 0 2 Enter the coefficient of the linear term -> 9 3 Enter the constant term ->2.5 5 ERROR: The quadratic term must be nonzero. Listing 5: Sample Run 1 Enter the coefficient of the quadratic term -> 12 2 Enter the coefficient of the linear term -> -7 3 Enter the constant term -> -12 5 For the quadratic equation 12x2 - 7x 6 7 Discriminant: 625.000 8 Axis of Symmetry: x- 0.292 9 Vertex: (0.292, -13.021) 10 y-intercept: (0.000, -12.000) 11 x-intercepts: (-0.750, 0.000) and (1.333, 0.000) 12 Shape: Concave upward 13 Roots:x -1.333, 0.750 12-0 Listing 6: Sample Run 1 Enter the coefficient of the quadratic term -> 9 2 Enter the coefficient of the linear term -> 0 3 Enter the constant term -> 16 5 For the quadratic equation 9x 2 + 160: 7 Discriminant: -576.000 8 Axis of Symmetry: x - -0.000 9 Vertex: (-0.000, 16.000) 10 y-intercept: (0.000, 16.000) 11 x- intercepts: none 12 Shape: Concave upward 13 Roots: x {1.3331, -1.3331} Listing 7: Sample Run 1 Enter the coefficient of the quadratic term -> 4 2 Enter the coefficient of the linear term -> -12 3 Enter the constant term -25 5 For the quadratic equation 4x2 - 12x + 250 6 7 Discriminant: -256.000 8 Axis of Symmetry: x- 1.500 9 Vertex: (1.500, 16.000) 10 y-intercept: (0.000, 25.000) 11 x-intercepts: none 12 Shape: Concave upward 13 Roots: x1.500+2.000i, 1.500-2.000ih 1. When the solution is real (not complex) and the irrational part of the solution is 0, the equation has only one root, rationalPart. The equation has only one x-intercept whose x-coordinate is rationalPart. 2. When the solutions are real and the irrational part of the solution is pos- itive, the equation has two real roots, rationalPart + irrationalPart and rationalPart - irrational Part 3. When the solutions are complex, the roots of the equation are rational Part + irrationalParti and rationalPart - irrationalParti where rational Part should be displayed only when it is non-zero. Also the equation has no x-intercepts To solve the quadratic equation, you will define two additional sub-functions between the using directive and the main functions k * * Computes the discriminant of a quadratic equation with * the specified parameters * Qparam qCoef the coefficient of the quadratic term * Qparam linCoef the coefficient of the linear term @paramcTerm the constant term * Oreturn the discriminant of a quadratic equation double discriminant(double qCoef, double linCoef, double cTerm) k * * Computes the rational and irrational parts of the solutions * of a quadratic equation with the specified parameters * Oparam qCoef the coefficient of the quadratic ternm Oparam linCoef the coefficient of the linear term OparamcTerm the constant term * Oparam rat the rational part of the solution * Oparam irrat the irrational part of the solution * Qparam cmplx indicates whether or not the roots are complex; * true when the roots are complex and false 1f they are real. void solve (double qCoef, double linCoef, double cTerm double& rat, double& irrat, bool& cmplx)
Step 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