#include "poly.h" poly :: poly { degree = 0; coeff = new double[1]; coeff[degree] = 0.0; } poly :: poly(double *c, int d) { coeff = new double[d+1]; for(int i=0; i<=d; i++) { coeff[i] = c[i]; } degree = d; } poly:: ~poly() { delete [] coeff; } poly& poly :: operator=(const poly &p) { if(this == &p){ return *this; } else { delete [] coeff; degree = p.degree; coeff = new double[degree+1]; for(int i=0; i<=degree; i++){ coeff[i] = p.coeff[i]; } } return *this; } poly operator+(const poly p,const poly q) { poly r, a=p, b=q; if(p.degree > q.degree) { r.set_degree(a.degree); b.set_degree(a.degree); } else { r.set_degree(b.degree); a.set_degree(b.degree); } for(int i=0; i<=r.degree; i++){ r.coeff[i] = a.coeff[i] + b.coeff[i]; } return r; } poly operator-(const poly p,const poly q) { poly r, a=p, b=q; if(p.degree > q.degree) { r.set_degree(a.degree); b.set_degree(a.degree); } else { r.set_degree(b.degree); a.set_degree(b.degree); } for(int i=0; i<=r.degree; i++){ r.coeff[i] = a.coeff[i] - b.coeff[i]; } return r; } poly operator*(const poly p,const poly q) { poly r; r.set_degree(p.degree + q.degree); for(int i=0; i<=p.degree; i++) { for(int j=0; j<=q.degree; j++) { r.coeff[i+j] = p.coeff[i] * q.coeff[j] + r.coeff[i+j]; } } return r; } poly operator/(const poly p,const poly q) { poly r; int rdeg = p.degree-q.degree; r.set_degree(rdeg+1); poly a=p, b=q; return r; } poly operator%(const poly p,const poly q) { poly r; return r; }