Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that solves a quadratic equation in all cases, including when bo

ID: 643330 • Letter: W

Question

Write a program that solves a quadratic equation in all cases, including when both roots are complex numbers. For this, you need to set up the following classes:

?? Complex, which encapsulates a complex number

ComplexPair, which encapsulates a pair of complex numbers

Quadratic, which encapsulates a quadratic equation

SolveEquation, which contains the main method
Along with the usual constructors, accessors, and mutators, toString, equals you will need to

code additional methods:

?? In the Complex class, a method that determines whether a complex object is real

?? In the ComplexPair class, a method that determines whether both complex numbers are

identical

?? In the Quadratic class, a method to solve the quadratic equation and return ComplexPair object

Additionally, you need to include code in the main method to solve several examples of quadratic equations input from the keyboard. Your output should make comments as to what type of roots we get (double real root, distinct real roots, distinct complex roots). You should check that your code works in all four basic cases:

?? The quadratic equation is actually a linear equation.

?? Both roots are complex.

?? There is a double real root.

?? There are two distinct real roots.

Explanation / Answer

#include int quadRoots(double a,double b, double c,double* r1,double* r2); void printRoots(int nr,double* r1,double* r2); using namespace std; int main() { double root1[2], root2[2]; int nRoots; // example with real roots nRoots = quadRoots(1.0, 3.3, 2.1, root1, root2); printRoots(nRoots,root1,root2); // example with complex roots nRoots = quadRoots(1.0, 3.3, 5.1, root1, root2); printRoots(nRoots,root1,root2); // example with real roots, one zero nRoots = quadRoots(1.0, 3.3, 0.0, root1, root2); printRoots(nRoots,root1,root2); // example of a linear function that should produce 1 root nRoots = quadRoots(0.7-1.0+0.3, 3.3, 2.1, root1, root2); printRoots(nRoots,root1,root2); // example that has no solutions nRoots = quadRoots(0.7-1.0+0.3, 0.0, 5.5, root1, root2); printRoots(nRoots,root1,root2); cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote