题目
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
#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
提问时间:2021-01-24
答案
有个大问题:主函数里面的指针p,与Polynomial* readPoly()中的p,属于不同的作用域.两个是不同的两个指针变量.所以你在readPoly()当中创建了的多项式结构并没有赋给主函数里面的p,这时p所指向的内存是未知的,可能引起...
举一反三
我想写一篇关于奥巴马的演讲的文章,写哪一篇好呢?为什么好
奥巴马演讲不用看稿子.为什么中国领导演讲要看?
想找英语初三上学期的首字母填空练习……
英语翻译
1,人们染上烟瘾,最终因吸烟使自己丧命.
最新试题
- 1醉翁亭记中作者到底在乐些什么?如何理解乐与醉的关系?
- 2一瓶钢笔墨水相当于多少支水笔
- 3一根长1m的圆柱形木料,截成两段后,表面积比原来增加0.8平方米原圆柱体体积为多少
- 4方程3-m分之x2-m+2分之y2=1表示双曲线,则m的取值范围
- 5哪位好人帮我用英语解释一下outsourcing这个词?
- 6甲乙两根钢管,甲管截去十几分之一到乙管上,这时两根钢管一样长如果这时的乙管长18米,那么甲管原来长多少
- 7spring outing(春游)是名词词组还是动词词组?
- 8有哪些如词语中有两个反义词的词,如"喜新厌旧"
- 912.5g氯酸钾和3.5g二氧化锰混合加热,待完全反应后,冷却称量剩余固体物质为10.7g,
- 10是不是所有金属都可以被磁体吸引
热门考点