C++问题:定义一个多项式类Polynomial,其实例为多项式:a0+a1x+a2x2+...+anxn定义一个多项式类Polynomial,其实例为多项式:a0+a1x+a2x2+...+anxn,该类具有如下的接口:class Polynomial { .public:Polynomial(); Polynomial

来源:学生作业帮助网 编辑:作业帮 时间:2024/12/02 20:25:31
C++问题:定义一个多项式类Polynomial,其实例为多项式:a0+a1x+a2x2+...+anxn定义一个多项式类Polynomial,其实例为多项式:a0+a1x+a2x2+...+anxn,该类具有如下的接口:class Polynomial { .public:Polynomial(); Polynomial
xT]k@+K&fnv_T#LȇF- %A!*K_0&5i.!!9g;JL&qlw-wl_wT}J,YF;q5aM.KL^gl7,Ǟ}: dwAޯMxoNQ@$i A]1(4`m]{Ǐm -sA5$b] pE@hEwe SI %$󿎽?_)X6D$! `Pjr0z"T[8;h-/ΎCɀ:JmfxgΡĚ.RPQFL~Jx 8I;”xM<]_m{?S |"wK-avi%J8Ꙁlʲ~6 {\Gp ^A]]>J\pVRAb| PTFȩR% w< +BUXy*cQ%NTظQEW0 (X484L2a\ڍ>O&@oz#

C++问题:定义一个多项式类Polynomial,其实例为多项式:a0+a1x+a2x2+...+anxn定义一个多项式类Polynomial,其实例为多项式:a0+a1x+a2x2+...+anxn,该类具有如下的接口:class Polynomial { .public:Polynomial(); Polynomial
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&);
};

C++问题:定义一个多项式类Polynomial,其实例为多项式:a0+a1x+a2x2+...+anxn定义一个多项式类Polynomial,其实例为多项式:a0+a1x+a2x2+...+anxn,该类具有如下的接口:class Polynomial { .public:Polynomial(); 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;
public :
Polynomial();
Polynomial(double coefs[],int exps[],int size);
Polynomial(const Polynomial &p);
Polynomial();
Polynomial &operator=(const Polynomial &p);
int degree() const;
double evaluate(double x) const;
bool operator==(const Polynomial &p) const;
bool operator!=(const Polynomial &p) const;
Polynomial operator+(const Polynomial &p) const;
Polynomial operator-(const Polynomial &p) const;
Polynomial operator*(const Polynomial &p) const;
Polynomial &operator+=(const Polynomial &p);
Polynomial &operator-=(const Polynomial &p);
Polynomial &operator*=(const Polynomial &p);
};
int Polynomial::add(const Polynomial &p,double *coefs,int *exps) const
{ int count=0,i=0,j=0;
while (i