I'm very confused by this recent assignment I received from my Professor. Here is the actual assignment
CMPS 148: Homework 2
Write a class that models a polynomial equation of the form:
The class should have 3 properties, A, B, and C. You are to provide several functions as well,
including an evaluate function that accepts an “x” and computes the results, and a findRoots function
that executes the quadratic formula to determine the equationʼs roots (x values which cause the
polynomial to evaluate to 0).
Details for the evaluate function:
The function should return a double. There should be a single parameter, called x. When called, the
function computes Ax2 + Bx + C using the polynomialʼs A, B, and C values and returns the result.
Details for the findRoots function:
The quadratic formula is used to find the value(s) of x that lead to the polynomial equaling zero. It is
defined as follows:
Where the two values found can be called root1 and root2. If the value of b2-4ac is negative there
are no real roots (the function never equals 0).
Your findRoots function should return true or false, depending on whether or not there are real roots
(if b2-4ac is positive). The function accepts two double values using pass by reference. If there are
roots, then those two parameters are set within the function.
On the next page is a main function that uses the Polynomial class. For this homework assignment,
you must use this EXACT program – without modification! It is posted as a separate file on
Moodle. You may of course add print statements to help you debug while you work, but I will expect
you to turn in the file without any of your modifications.
Sorry for all the space taken.. Here are my questions:
As you can see I have the constructors defined. I'm wondering how can I possible have the print() constructor and the printRoots() accept two different sets of variables but function in the same constructor?
I could do this but the issue is that I cannot edit main() to make use of seperate constructors / functions.
I thought of a robust and stupid way of using a if statement with a counter in the constructor and having it say if this is the second time you're being used then print this or use these variables instead. I feel there is a simpler way though.
Sample output – user input in red.
Two polynomials will be used:
14x^2 + 19x + 2
P2: User-Defined: 1x^2 + 1x + 1
Enter an x value to evaluate both polynomials: 8
with roots at -0.11501 and -1.24213