### Polynomial with Class and Header

Gentlemen,

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.

Then here is the main
 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556`` ``````#include #include "Polynomial.h" using namespace std; void printRoots(Polynomial p) { double r1=0, r2=0; if ( p.findRoots(r1, r2) ) { cout << "\twith roots at " << r1 << " and " << r2 << endl; } else { cout << "\tNo Roots" << endl; } } int main() { Polynomial p1(14, 19, 2); // Provide a constructor to set A, B, C Polynomial p2; // Default constructor should initialize to all zeros double tmp; cout << "Enter A: "; cin >> tmp; p2.setA(tmp); cout << "Enter B: "; // A, B, and C need to be private variables - supply getters and setters. cin >> tmp; p2.setB(tmp); cout << "Enter C: "; cin >> tmp; p2.setC(tmp); cout << "Two polynomials will be used: " << endl; cout << "P1: Predefined: "; p1.print(); // Should print as 14x^2 + 19x + 2 cout << "P2: User-Defined: "; p2.print(); // Should print in the same format, but with the user-entered values. cout << "Enter an x value to evaluate both polynomials: "; cin >> tmp; cout << "P1: " << p1.evaluate(tmp) << endl; printRoots(p1); cout << "P2: " << p2.evaluate(tmp) << endl; printRoots(p2); }``````

Here is the Header file I created
 ``1234567891011121314151617181920212223242526`` ``````#ifndef POLYNOMIAL_H #define POLYNOMIAL_H class Polynomial { public: double x, p1, p2; int a1, b1, c1; Polynomial(); Polynomial(double a1, double b1, double c1); double evaluate (double x); double findRoots (double &r1, double &r2); double setA(double a); double setB(double b); double setC(double c); void print(); private: double a, b, c; }; #endif // POLYNOMIAL_H ``````

Lastly here is another source
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748`` ``````#include "Polynomial.h" #include #include using namespace std; double tmp; Polynomial :: Polynomial() { x, a, b, c = 0; } double Polynomial :: Polynomial (a1, b1, c1){ } double Polynomial :: evaluate(double x){ } // j * pow (x, 2) + k * x + c = 0 double Polynomial :: setA(double a){ a = tmp; } double Polynomial :: setB(double b){ b = tmp; } double Polynomial :: setC(double c){ c = tmp; } void Polynomial :: print(){ }``````

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.