Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The general form for a quadratic equation is Ax 2 + Bx + C = 0 The solution for x can be found using the

The general form for a quadratic equation is

Ax 2 + Bx + C = 0

The solution for x can be found using the quadratic formula, which returns 2 values for x.

x 1 = (-B + (B 2 4AC) 1/2 ) / 2A

x 2 = (-B - (B 2 4AC) 1/2 ) / 2A

Note that if 4AC is larger than B 2 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 B 2. 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:

5x 2 + 7x + 2 = 0

3x 2 + 2x + 5 = 0

2x 2 + 3x + -1 = 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions