my project is
Develop class Polynomial.This internal representation of a polynomial is an array of terms.Each term contains a coefficient and an exponent, hence you can have an array for coefficients and exponents as a member of your class(maximum number of terms will 100 however your class should also contain a member variable that indicates how many terms are there in a given instance of the polynomial class).
the term 2x^4 has a coefficient of 2 and exponent of 4. Develop a full class containing proper constructor and destructor functions as well as set and get functions. The class should also provide the following overloaded operator capabilities:
1 overload the addition operator (+) to add two polynomials.
2 overload the subtraction operator (-)to subtract two polynomials
3 overload the assignment operator to assign one polynomial to another
4 overload the multiplication operator(*) to multiply two polynomials
please help me in building this code
#include<iostream>
usingnamespace std;
class Polynomial
{
private:
int *Coefficient;
int *Exponents;
int Nterms;//number of terms
public:
Polynomial();
int getC(){return Coefficient};
int getE(){return Exponents};
void getUserInput();
friend Polynomial operator+(const Polynomial&);
};
Polynomial operator+(Polynomial&A,Polynomial&B){ //Adds two polynomial objects when exponents become equal in the loop
Polynomial C;
for(int i=0;i<100;i++){
if(A.getE()[i]==B.getE()[i]){
C.getE()[i]=A.getE()[i];
C.getC()[i]=B.getE()[i]+A.getE()[i];
}
}
return C;
};
Polynomial operator-(Polynomial&A,Polynomial&B){//Sub two polynomial objects when exponents become equal in the loop
Polynomial C;
for(int i=0;i<100;i++){
if(A.getE()[i]==B.getE()[i]){
C.getE()[i]=A.getE()[i];
C.getC()[i]=B.getE()[i]-A.getE()[i];
}
}
return C;
};
//constructors
Polynomial::Polynomial()
{
Nterms=0;
Coefficient = newint[100];
Exponents = newint[100];
for (int i = 0; i < 100; i++)
{
Coefficient[i] = 0;
Exponents[i] = 0;
}
}
void Polynomial::getUserInput(){//Allows user to enter coef and expo
cout<<"Enter the Exponent of Polynomial: ";
cin>>Exponents[Nterms];
cout<<endl;
cout<<"Enter the Coefficient of Polynomial: ";
cin>>Coefficient[Nterms];
Nterms++;
}