Created
April 25, 2017 04:14
-
-
Save anonymous/704fdbac1caab8fe807906a06f0be7ef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "function.h" | |
using namespace std; | |
Polynomial::Polynomial() | |
{ | |
greatestPower=0; | |
coefficients[0]=0; | |
} | |
Polynomial::Polynomial(const int N, const int C[51]) | |
{ | |
greatestPower=N; | |
for(int i=N; i>=0; i--) | |
{ | |
coefficients[i]=C[i]; | |
} | |
} | |
Polynomial Polynomial::add( const Polynomial b) const | |
{ | |
Polynomial c; | |
int a=(greatestPower>b.greatestPower)?greatestPower:b.greatestPower; | |
c.greatestPower =a; | |
for(int i=a; i>=0; i--) | |
{ | |
c.coefficients[i]=coefficients[i]+b.coefficients[i]; | |
} | |
return *c; | |
} // add function | |
Polynomial Polynomial::subtract( const Polynomial b) const | |
{ | |
Polynomial c; | |
int a=(greatestPower>b.greatestPower)?greatestPower:b.greatestPower; | |
c.greatestPower =a; | |
for(int i=a; i>=0; i--) | |
{ | |
c.coefficients[i]=coefficients[i]-b.coefficients[i]; | |
} | |
return *this; | |
} // subtract function | |
Polynomial Polynomial::multiplication( const Polynomial b) const | |
{ | |
Polynomial c; | |
int a=greatestPower*b.greatestPower; | |
c.greatestPower =a; | |
for(int i=greatestPower; i>=0; i--) | |
{ | |
for(int j=b.greatestPower; j>=0; j--) | |
{ | |
c.coefficients[i+j]+=coefficients[i]*b.coefficients[j]; | |
} | |
} | |
return *this; | |
} // multiplication function | |
void Polynomial::output() const | |
{ | |
for(int i=this->greatestPower; i>0; i--) | |
{ | |
cout<< this->coefficients[i] << " "; | |
} | |
cout << this->coefficients[0] << endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment