首页 > 中学考试杂题 > 题目详情
如果用循环链表表示一元多项式,试编写一个函数 Calc(x),计算多项式在x处的值.#include//#include
题目内容:
如果用循环链表表示一元多项式,试编写一个函数 Calc(x),计算多项式在x处的值.
#include
//#include
using namespace std;
class polynomial
{
public:
float coef;
int exp;
polynomial *next;
//void count(polynomial *p,int x);
};
int main()
{
void count(polynomial *p,int x);
// string str;
polynomial *p;
p=new polynomial;
int e;
float c;
polynomial *q,*r;
q=p;
r=p;
// coutexp=e;
r->next=q;
r=q;
}
// cout>x;
count(p,x);
return 0;
}
void count(polynomial *p,int x)
{
float c;
int e;
int f=1;
float num=0;
polynomial *k,*m;
k=p;
m=p;
while(k!=m)
{
c=k->coef;
e=k->exp;
p=k->next;
k=p;
if(e>=1)
{
for(e;e>0;e--)
{
f=x*f;
num+=c*f;
}
f=1;
}
if(e==0)
num+=c;
if(e
如果用循环链表表示一元多项式,试编写一个函数 Calc(x),计算多项式在x处的值.
#include
//#include
using namespace std;
class polynomial
{
public:
float coef;
int exp;
polynomial *next;
//void count(polynomial *p,int x);
};
int main()
{
void count(polynomial *p,int x);
// string str;
polynomial *p;
p=new polynomial;
int e;
float c;
polynomial *q,*r;
q=p;
r=p;
// coutexp=e;
r->next=q;
r=q;
}
// cout>x;
count(p,x);
return 0;
}
void count(polynomial *p,int x)
{
float c;
int e;
int f=1;
float num=0;
polynomial *k,*m;
k=p;
m=p;
while(k!=m)
{
c=k->coef;
e=k->exp;
p=k->next;
k=p;
if(e>=1)
{
for(e;e>0;e--)
{
f=x*f;
num+=c*f;
}
f=1;
}
if(e==0)
num+=c;
if(e
#include
//#include
using namespace std;
class polynomial
{
public:
float coef;
int exp;
polynomial *next;
//void count(polynomial *p,int x);
};
int main()
{
void count(polynomial *p,int x);
// string str;
polynomial *p;
p=new polynomial;
int e;
float c;
polynomial *q,*r;
q=p;
r=p;
// coutexp=e;
r->next=q;
r=q;
}
// cout>x;
count(p,x);
return 0;
}
void count(polynomial *p,int x)
{
float c;
int e;
int f=1;
float num=0;
polynomial *k,*m;
k=p;
m=p;
while(k!=m)
{
c=k->coef;
e=k->exp;
p=k->next;
k=p;
if(e>=1)
{
for(e;e>0;e--)
{
f=x*f;
num+=c*f;
}
f=1;
}
if(e==0)
num+=c;
if(e
本题链接: