Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The general form for a quadratic equation is Ax2 + Bx + C = 0 The solution for x can be found using the quadratic
The general form for a quadratic equation is
Ax2 + Bx + C = 0
The solution for x can be found using the quadratic formula, which returns 2 values for x.
x1 = (-B + (B2 4AC)1/2 ) / 2A
x2 = (-B - (B2 4AC)1/2 ) / 2A
Note that if 4AC is larger than B2 then square root function will fail as the C++ math library will not take the square root of a negative number.
Write a C++ program that will calculate both solutions to X for a quadratic formula. Your program must include 2 functions one for each root. Each function should check if 4AC is larger than B2. If it is, then the function should throw an exception indicating that that is a problem.
Your main function will need to check for exceptions and display an error message if either or both of the functions thrown one.
Your program will prompt the user for the values for A, B and C. After the calculations for both values x are done, it will prompt the user if they wish to enter another formula. If the user chooses yes, the program will continue as before, prompting the user for the values of A, B and C. If the user chooses no, the program will end. Please note that if the program can use the quadratic formula to calculate the value for x, it must display the value for both values of x.
Run your program to solve for x in the following formulas:
5x2 + 7x + 2 = 0
3x2 + 2x + 5 = 0
2x2 + 3x + -1 = 0
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