示例#1
0
//For backward directions that take 2 arguments
const Poly operator*(int scale, const Poly &P){
Poly P1 = P;
for(int i=0; i < P.getOrder(); i++){
P.coeff[i] *= scale;
}
P1.set(P.coeff, P.getOrder()-1);
return P1;
}
示例#2
0
//Operator * Scaler Overloading
Poly Poly::operator*(const int scale){
Poly P = *this;
for(int i=0; i < P.getOrder(); i++){
P.coeff[i] *= scale;
}
P.set(P.coeff, P.getOrder()-1);
return P;
}
示例#3
0
//Operator * another polynomial
Poly Poly::operator*(const Poly &rhs){
Poly P = *this;

//Initializing the maximum order
int max_order = (P.getOrder() + rhs.getOrder())-1;

//Initializing the new set for summation
int *coeff_final = new int[max_order];
int *coeff_temp = new int[max_order];

for(int i=0; i < max_order; i++){
coeff_final[i] = 0;
coeff_temp[i] = 0;
}

for(int i=0; i < P.getOrder(); i++){
coeff_final[i] = P.coeff[i];
}

for(int i=0; i<rhs.getOrder(); i++){
  
  //Create a new summation array
  if(i > 0){
  delete[] coeff_temp;
  int *coeff_temp = new int[max_order];  
  for(int i=0; i < max_order; i++){
  coeff_temp[i] = 0;
  }
  }

  for(int j=0; j<P.getOrder(); j++){
  
  int total_order = i + j;
  
  if(i == 0){
  coeff_final[total_order] = P.coeff[j]*rhs.coeff[i];
  }
  else{
  coeff_temp[total_order] = P.coeff[j]*rhs.coeff[i];
  coeff_final[total_order] += coeff_temp[total_order];
  }

  }
}

//Setting the coefficients are order into the class
P.set(coeff_final, max_order-1);
delete[]coeff_final;
delete[]coeff_temp;
return P;
};
示例#4
0
//Operator + Overloading
Poly Poly::operator+(const Poly &rhs){

Poly P = *this;

if(P.getOrder() > rhs.getOrder())
{
 int *coeff_temp = new int [P.getOrder()];
 
 for(int i=0; i < P.getOrder(); i++){
 coeff_temp[i] = 0;
 }

 for(int i=0; i < rhs.getOrder(); i++){
 coeff_temp[i] = rhs.coeff[i];
 }

 for(int i=0; i < P.getOrder(); i++){
 P.coeff[i] = coeff[i] + coeff_temp[i];
 }
 P.set(P.coeff, P.getOrder()-1);
 return P;
}
else
{
 int *coeff_temp = new int [rhs.getOrder()];
 for(int i=0; i < P.getOrder(); i++){
 coeff_temp[i] = P.coeff[i];
 }

 P.coeff = coeff_temp;
 
 for(int i=0; i<rhs.getOrder(); i++){
 rhs.coeff[i] = rhs.coeff[i] + P.coeff[i];
 }
 P.set(rhs.coeff, rhs.getOrder()-1);
 return P;
};
};