Your solution that you submit should consist of two (2) files: Polynomial.h (cla
ID: 3711945 • Letter: Y
Question
Your solution that you submit should consist of
two (2) files:
Polynomial.h (class specification file)
Polynomial.cpp (class implementation file)
The application program (Polynomial_app.cpp) has already been completed for you.
POLYNOMIAL_APP.CPP
#include <iostream>
#include "Polynomial.h"
using namespace std;
int main()
{
Polynomial a, b, c, t;
a. enterTerms();
b. enterTerms();
t = a; // save the value of a
cout << " First polynomial is: ";
a. printPolynomial();
cout << " Second polynomial is: ";
b. printPolynomial();
cout << " Adding the polynomials yields: ";
c = a + b;
c. printPolynomial();
cout << " += the polynomials yields: ";
a += b;
a. printPolynomial();
cout << " Subtracting the polynomials yields: ";
a = t; // reset a to original value
c = a - b;
c.printPolynomial();
cout << " -= the polynomials yields: ";
a -= b;
a. printPolynomial();
cout << endl;
system("PAUSE"); //remove this if you are not using windows
return 0;
} // end main
SAMPLE OUTPUT:
thank you for any help!!
Develop class Polynomial. The internal representation of a Polynomial is an array or vector of terms. Each term contains a coefficient and an exponent, e.g., the term .2x has the coefficient 2 and the exponent 4. Develop a complete class containing proper constructor and destructor functions as well as set and get functions. The class should also provide the following overloaded operator capabilities: a. Overload the addition operator (+) to add two Polynomials. b Overload the subtraction operator() to subtract two Polynomials c. Overload the assignment operator () to assign one Polynomial to another. d. Overload the addition assignment operator(+) e. Overload the subtraction assignment operator () Beyond overloading these operators, the code in the polynomial_app.cpp will give you an idea of what member functions you need to implement in the Polynomial class.Explanation / Answer
As you have asked only for header file, I provide the synopisis of the class.
It is required for you to implemen it.
If you want implementation also, I will have to write more code...
class Polynomial
{
private:
double *coeff;
int degree; //this is the degree of the polynomial (i.e. one less then the length of the array of coeff)
public:
Polynomial();
Polynomial(double coeffs[] , int nterms);
Polynomial(Polynomial&);
Polynomial(double); //the constructor to initialize a polynomial equal to the given constant
~Polynomial() { delete coeff; } //the deconstructor to clear up the allocated memory
//the operations to define for the Polynomial class
Polynomial operator+(Polynomial p) const;
Polynomial operator-(Polynomial p) const;
Polynomial operator*(Polynomial p) const;
Polynomial printPloyNomial() ;
};
Polynomial::Polynomial() {
degree = 0;
coeff = new double[degree + 1];
coeff[0] = 0;
}
//Initialize a polynomial with the given coefficient array and degree
Polynomial::Polynomial(double coeffs[], int nterms){
degree = nterms;
coeff = new double[degree]; //array to hold coefficient values
for(int i = 0; i < degree; i++)
coeff[i] = coeffs[i];
}
Polynomial::printPloyNomial(){
degree = nterms;
for(int i = 0; i < degree; i++)
cout << coeff[i] ;
}
Polynomial::Polynomial(Polynomial&){
}
//The constructor to initialize a polynomial equal to the given constant
Polynomial::Polynomial(double){
}
Polynomial::operator *(Polynomial p) const{
}
Polynomial::operator +(Polynomial p) const{
}
Polynomial::operator -(Polynomial p) const{
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.