c++ 多项式 Polynomial#include using namespace std;struct Polynomial {int degree;int *coeffs; // array of coefficients from // lowest degree to highest degree};// reads the coefficients of a polynomial from standard input and // creates a polynomia

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/14 02:50:17

c++ 多项式 Polynomial#include using namespace std;struct Polynomial {int degree;int *coeffs; // array of coefficients from // lowest degree to highest degree};// reads the coefficients of a polynomial from standard input and // creates a polynomia
c++ 多项式 Polynomial
#include
using namespace std;
struct Polynomial {
int degree;
int *coeffs; // array of coefficients from
// lowest degree to highest degree
};
// reads the coefficients of a polynomial from standard input and
// creates a polynomial which it returns
Polynomial* readPoly();
// outputs a polynomial to standard output using the variable x
void outputPoly( Polynomial* p,char x );
// computes the sum of two polynomials
Polynomial* addPoly( Polynomial* a,Polynomial* b );
// computes the product of two polynomials
Polynomial* multPoly( Polynomial* a,Polynomial* b );
int main()
{
char x;
Polynomial *p;
readPoly();
outputPoly(p,x);
return 0;
}
Polynomial* readPoly()
{
int deg,*coefficient;
coutdeg;
coefficient = new int[deg+1]; // space for deg+1 coefficient
cout degree = deg;
p -> coeffs = coefficient;
}
//if the last degree is associated with a zero ,the output will show an extra "+" sign in the end
void outputPoly(Polynomial* p,char x)
{
x = 'x';
//char sign = '+';
for(int i= 0;idegree;i++){
string sign = "+";
if(p->coeffs[i] == 0)
{
continue;
}
if(i == 0)
{
if((p->coeffs[i+1]degree))
sign = "";
coutcoeffs[i]degree)) //if it is the last coefficent with number
sign = "";
cout

c++ 多项式 Polynomial#include using namespace std;struct Polynomial {int degree;int *coeffs; // array of coefficients from // lowest degree to highest degree};// reads the coefficients of a polynomial from standard input and // creates a polynomia
有个大问题:主函数里面的指针p,与Polynomial* readPoly()中的p,属于不同的作用域.两个是不同的两个指针变量.所以你在readPoly()当中创建了的多项式结构并没有赋给主函数里面的p,这时p所指向的内存是未知的,可能引起系统报错.
改法:
1.readPoly()最后加一个 return p...
主函数里面 p = readPoly();
2.由于用了动态分配,最后应该释放掉好像是用delete吧,在主函数最后把原先用new分配的指针所指向的空间都释放了.
3.输出也有问题:好像不能输出负系数的?比如"x^3 - x^2"...
大概就发现了这几个问题,你改了看下还有错误的话再说吧.

一道简单的英文3次多项式题,谢谢Consider the cubic polynomial P(x) = x^3 − x.(a) Factorize the cubic polynomial into a product of linear factors.(b) What are the roots of the polynomial.(c) Determine whether the polynomial is even, C++问题:定义一个多项式类Polynomial,其实例为多项式:a0+a1x+a2x2+...+anxn定义一个多项式类Polynomial,其实例为多项式:a0+a1x+a2x2+...+anxn,该类具有如下的接口:class Polynomial { .public:Polynomial(); Polynomial reduced polynomial什么意思 多项式中reduced怎么翻译 Factoring a Polynomial有关能否构成多项式的定理 1.polynomial 是多项式,那么binomial算是polynomial 2.y的2次方,和y 算是like term吗 c++ 多项式 Polynomial#include using namespace std;struct Polynomial {int degree;int *coeffs; // array of coefficients from // lowest degree to highest degree};// reads the coefficients of a polynomial from standard input and // creates a polynomia 如果用循环链表表示一元多项式,试编写一个函数 Calc(x),计算多项式在x处的值.#include//#includeusing namespace std;class polynomial{ public: float coef; int exp; polynomial *next; //void count(po C语言指针问题求指错题目要求是:某多项式(polynomial)的描述如下:1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + ...现在请你求出该多项式的前n项的和.输入要求:输入数据由2行组成,首先是一个正整数T,表示测 find a third degree polynomial with real coefficients that has 2,3-i as zeros 关于高次多项式函数的图像问题High-degree polynomial function:If n (the highest exponent)is odd,and An>0,the graph falls to the left and rises to the right.If n is odd,and An<0,the graph rises to the left and falls to the right.If n i 一个Matlab问题,关于多项式的.[S,LEN] = POLY2STR(P,'s') also returns the maximum wrapped length of the polynomial.请问maximum wrapped length of the polynomial是个什么?那个没有用 polynomial什么意思 mclaurin polynomial是什么意思 quadratic polynomial是什么意思 orthogonal polynomial是什么意思 polynomial regression是什么意思 quadratic polynomial是什么意思 美国高中数学:find a third degree polynomial with real coefficients that has 2 and 3-i as zeros.