Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   Polynomial help (http://www.go4expert.com/forums/polynomial-help-t20525/)

 risha_messi 27Dec2009 22:15

Code:

```# 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

 All times are GMT +5.5. The time now is 04:00.