C++问题:定义一个多项式类Polynomial,其实例为多项式:a0+a1x+a2x2+...+anxn定义一个多项式类Polynomial,其实例为多项式:a0+a1x+a2x2+...+anxn,该类具有如下的接口:class Polynomial { .public:Polynomial(); Polynomial(double coefs[],int exps[],int size); //系数数组、指数数组和项数 Polynomial(const Polynomial&); Polynomial(); Polynomial& operator=(const Polynomial&); int degree() const; //最高幂指数 double evaluate(double x) const; //计算多项式的值 bool operator==(const Polynomial&) const; bool operator!=(const Polynomial&) const
C++问题:定义一个多项式类Polynomial,其实例为多项式:a0+a1x+a2x2+...+anxn
定义一个多项式类Polynomial,其实例为多项式:a0+a1x+a2x2+...+anxn,该类具有如下的接口:
class Polynomial
{ .
public:
Polynomial();
Polynomial(double coefs[],int exps[],int size);
//系数数组、指数数组和项数
Polynomial(const Polynomial&);
Polynomial();
Polynomial& operator=(const Polynomial&);
int degree() const; //最高幂指数
double evaluate(double x) const; //计算多项式的值
bool operator==(const Polynomial&) const;
bool operator!=(const Polynomial&) const;
Polynomial operator+(const Polynomial&) const;
Polynomial operator-(const Polynomial&) const;
Polynomial operator*(const Polynomial&) const;
Polynomial& operator+=(const Polynomial&);
Polynomial& operator-=(const Polynomial&);
Polynomial& operator*=(const Polynomial&);
};
其实很简单class Polynomial { double *pcoefs; int *pexps; int num_of_items; int add(const Polynomial &p,double *coefs,int *exps) const; int subtract(const Polynomial &p,double *coefs,int *exps) const; ...