Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can someone help me with this? The code is supposed to be written in C++. I'm having trouble finding the roots and displaying them. The
Can someone help me with this? The code is supposed to be written in C++. I'm having trouble finding the roots and displaying them. The directions and example screenshots are attached.
In this program, you will create a program that solves a quadratic equation using the Quadratic Formula. The Quadratic formula solves for the roots of a quadratic equation that is in the form of: ax2 + bx + c The Quadratic Formula is defined as: -b + b2 - 4ac 2a Your program should prompt the user to enter in the values of a, b and c. These values can be ANY number (including a decimal number). The program should store these values when entered and then calculate the discriminant (the vb2 - 4ac portion). The program should then calculate the roots of the equation. Finally, the program should display the original equation, the value of the discriminant, and the values of the roots. See screen shots below. Use the caret symbol () to represent exponentiation when displaying equations. Use the caret symbol () to represent exponentiation when displaying equations. Ex. 22 would be displayed as 242 Remember to make sure that the program is well documented with comments!! NOTES: The formulas must be written to work in CH. You will need to use parentheses for grouping your operations to ensure the proper order of operations. To calculate the square of a number you can keep it simple and multiply the number by itself, or you can use the cmath library's pow() function. pow(base, exponent) ex. 32 would be pow(3,2) To calculate the square root of the discriminant use the cmath library's sqrt() function. Have your program use the discriminant to determine the number of roots, and only calculate the root or roots if necessary, based on the rules below. You will need a decision control structure for this (chap. 4). Consider: Is there a simpler formula for calculating the root if there is only one? 1. A discriminant that is positive has two roots 2. A discriminant that is zero has only one root 3. For simplicity's sake, we will say that a discriminant that is negative means the equation has no roots. (Note: a negative discriminant really signifies complex solutions) For the output, the program should display the original equation, the value of the discriminant, and the values of the root or roots or a message stating there are no roots. Use the caret symbol (~) to represent exponentiation when displaying equations. Ex. 22 would be displayed as 242 See the extra credit screens shots below for examples. Welcome to the Quadratic Formula Solver Please enter in the value of a: 1 Please enter in the value of b: 7 Please enter in the value of c: 12 The equation is 1.20x^2 + 7.eex + 12.00 The discriminant = 1.ee There are two roots and the values are: -3.ee and -4.00 Thank you for using the Quadratic Formula Solver Press any key to continue ... Welcome to the Quadratic Problem Solver Please enter the value of a: 10 Please enter the value of b: -1 Please enter the value of c: -2 The equation is: 10.00x^2 + -1.00x + -2.00 The discriminant is: 81.00 There are two roots and the values are: 0.50 and -0.40 Thank you for using the quadratic problem solver. Press any key to continueStep 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