如果用循环链表表示一元多项式,试编写一个函数 Calc(x),计算多项式在x处的值.#include//#includeusing namespace std;class polynomial{ public: float coef; int exp; polynomial *next; //void count(po
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/18 14:19:49
如果用循环链表表示一元多项式,试编写一个函数 Calc(x),计算多项式在x处的值.#include//#includeusing namespace std;class polynomial{ public: float coef; int exp; polynomial *next; //void count(po
如果用循环链表表示一元多项式,试编写一个函数 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//#includeusing namespace std;class polynomial{ public: float coef; int exp; polynomial *next; //void count(po
#include
using namespace std;
class polynomial
{
public:
float coef;
int exp;
polynomial *next;
//void count(polynomial *p,int x);
};
int main()
{
float count(polynomial *p,int x);
polynomial *p;
p = new polynomial;
int e;
float c;
polynomial *q, *r;
q=p;
r=p;
cout