Polynomial
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
# include <iostream>
using namespace std ;
class Polynomial
{
private :
int *array ;
int x ;
public :
Polynomial(int y=0 , int arr[]=0)
{
x = y ;
array = new int [x+1] ;
}
void setPolynomial() ;
void setPolynomial(int*) ;
int getPolynomial() ;
void operator = (const Polynomial& ) ;
Polynomial operator * (const Polynomial& ) ;
};
Polynomial Polynomial::operator * (const Polynomial& p)
{
x = p.x ;
int* arr = new int [x+1];
for ( int i = 0 ; i < x+1 ; i++ )
{
arr[i] = array[i] * p.array[i] ;
}
Polynomial result(x);
result.setPolynomial(arr);
return result;
}
int main ()
{
int power ;
char choice ;
cout << "The Polynomial Function to the Power : " ;
cin >> power ;
int* poly1 ;
Polynomial p1(power ,poly1);
p1.setPolynomial() ;
cout << "Enter Operator ( + , - , * , = , +=(1) , -=(2) , *=(3) ) : " ;
cin >> choice ;
if ( choice == '*')
{
int* poly2 ;
Polynomial p2(power ,poly2);
p2.setPolynomial();
Polynomial p3 ;
p3 = p1 * p2 ;
cout << endl ;
p3.getPolynomial() ;
}
system("pause");
return 0 ;
}
|
excuse me i want help
in the operator * it only multiply the cofficients but i want it to multiply in this form
(4x2 – 4x – 7)(x + 3)
= (4x2 – 4x – 7)(x) + (4x2 – 4x – 7)(3)
= 4x2(x) – 4x(x) – 7(x) + 4x2(3) – 4x(3) – 7(3)
= 4x3 – 4x2 – 7x + 12x2 – 12x – 21
= 4x3 – 4x2 + 12x2 – 7x – 12x – 21
= 4x3 + 8x2 – 19x – 21
can any one help me in this code plz
please i need help
heeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeelp please
I'm guessing you want to know how to handle multiplication of two polynomials?
How would you multiply them on paper?
Topic archived. No new replies allowed.