454,468 Members | 1,453 Online
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,468 IT Pros & Developers. It's quick & easy.

# Polynomial class c++

 P: 26 im making a polynomial class, operator / is working while the operator /= overloaded function is not working.Someone pleasssssssssssssseeeee help out. ive to submit it next week. Expand|Select|Wrap|Line Numbers     int degree;     double ab[100];     char dummy;   /////////////////////////////Division////////      Poly  Poly::operator/(Poly& a)    {        Poly temp;        double result[20],temp1[20],temp2[20],temp3[20];        int count=0,cnt,i=0,j=0,k=0;          for(i=0 ; i<=20 ; i++)        {            result[i]=0;temp1[i]=0;temp2[i]=0;temp3[i]=0;          }          if(degree>=a.degree)        {            for(i=degree; i>=0 ; i--)            temp1[i]=ab[i];             for(i=a.degree-1 ; i>=0 ;i--)            temp2[i]=a.ab[i]*-1;                 for(i=degree ; i>=a.degree ; i--)            {                cnt=0;                result[count]=temp1[i];                  for(j=a.degree-1 ; j>=0 ; j--)                {                    temp3[j]=temp2[j]*temp1[i];                }                  for(k=i-1 ; k>=0 ; k--)                {                    if(a.degree-1-cnt>=0)                    {                        temp1[k]+=temp3[a.degree-1-cnt];                        cnt++;                    }                  }                  count++;              }              count-=1;              for(i=count ; i>=0 ; i--)                temp.ab[count-i]=result[i];            temp.degree=count;            temp.dummy=dummy;        }          else            cout<<" invalid input "<<"\n";          return temp;    }     //////////not working        Poly&  Poly::operator/=(Poly& a)    {        double result[20],temp1[20],temp2[20],temp3[20];        int count=0,cnt,i=0,j=0,k=0;          for(i=0 ; i<=20 ; i++)        {            result[i]=0;temp1[i]=0;temp2[i]=0;temp3[i]=0;          }            if(degree>=a.degree)        {              for(i=degree; i>=0 ; i--)            temp1[i]=ab[i];             for(i=a.degree-1 ; i>=0 ;i--)            temp2[i]=a.ab[i]*-1;                 for(i=degree ; i>=a.degree ; i--)            {                cnt=0;                result[count]=temp1[i];                  for(j=a.degree-1 ; j>=0 ; j--)                {                    temp3[j]=temp2[j]*temp1[i];                }                  for(k=i-1 ; k>=0 ; k--)                {                    if(a.degree-1-cnt>=0)                    {                        temp1[k]+=temp3[a.degree-1-cnt];                        cnt++;                    }                  }                  count++;              } count--;                 this->degree=count;              for(i=degree ; i>=0 ; i--)             this->ab[degree-i]=result[i];              cout<<"done";            }          else            cout<<" invalid input "<<"\n";          return *this;   } Nov 16 '08 #1
4 Replies

 Expert Mod 5K+ P: 9,197 If your Poly::operator/() is working then why not just: Expand|Select|Wrap|Line Numbers Poly& Poly::operator/=(Poly& a) {      *this = *this / a;      return *this; }   ? Nov 16 '08 #2

 P: 26 If your Poly::operator/() is working then why not just: Expand|Select|Wrap|Line Numbers Poly& Poly::operator/=(Poly& a) {      *this = *this / a;      return *this; }   ? u r genius.......oooohhhh how stupid of me.....its working now....thanks a lot a lot....im so happy......thanksss but still why that function /= isn't working ??? i jst copy paste that / code and change the assignment of result to temporary object to this pointer... Nov 17 '08 #3

 Expert 100+ P: 469 Perhaps in your /= operator you are using this as if it was the original polynomial after you have modified it. Nov 17 '08 #4

 P: 26 Perhaps in your /= operator you are using this as if it was the original polynomial after you have modified it. but ive used this pointer when all the calculations are done....at the end before ending if ive changed the the original attributes it should work Nov 17 '08 #5