来看看这个C++程序
在下边的这个程序中,编译能通过,运行过程中有错误,调式有expression cannot evaluted的错误,高手帮调式下,谢了!代码如下:#include<iostream.h>
#include<cstdio>
struct Node
{
float conf;
int exps;
Node *next;
Node()
{
conf=0.0;
exps=0;
next=NULL;
}
};
Node *createNode()
{
Node *str,*p;
float c;
int e;
p=new Node;
str=p;
cin>>c>>e;
p->conf=c;
p->exps=e;
while(true)
{
Node *temp=new Node;
cin>>c>>e;
temp->conf=c;
temp->exps=e;
p->next=temp;
p=temp;
if(c==0.0&&e==0)
{
temp->conf=0.0;
temp->exps=0;
break;
}
}
return str;
}
void printA(Node *pp)
{
//Node *np=NULL;
cout<<"多项式为:";
cout<<pp->conf<<"x"<<char(94)<<pp->exps;
//for(np=pp->next;((np->conf!=0.0)||(np->exps!=0));np=np->next)
pp=pp->next;
while((pp->conf!=0.0)||(pp->exps!=0))
{
if(pp->conf>0)
{
cout<<" + "<<pp->conf<<"x"<<char(94)<<pp->exps;
}
if(pp->conf<0)
{
cout<<" - "<<-pp->conf<<"x"<<char(94)<<pp->exps;
}
pp=pp->next;
}
cout<<endl;
}
void clears(Node *xp)
{
Node *cp=NULL,*tp;
for(cp=xp;((cp->conf!=0)||(cp->exps!=0));cp=cp->next)
{
tp=cp->next;
delete cp;
cp=tp;
}
delete cp;
}
Node *add(Node *A,Node *B)
{
Node *q1=NULL,*p1=NULL,*r,*tp,*first;
float temp;
q1=A;
p1=B;
tp=new Node;
first=tp;
bool t=true;
while((q1->conf!=0.0||q1->exps!=0)&&(p1->conf!=0.0||p1->exps!=0))
{
if(q1->exps>p1->exps)
{
if(t)
{
tp->conf=q1->conf;
tp->exps=q1->exps;
t=false;
q1=q1->next;
}
else
{
r=new Node;
r->conf=q1->conf;
r->exps=q1->exps;
tp->next=r;
tp=r;
q1=q1->next;
}
}
if(q1->exps<p1->exps)
{
if(t)
{
tp->conf=p1->conf;
tp->exps=p1->exps;
t=false;
p1=p1->next;
}
else
{
r=new Node;
r->conf=p1->conf;
r->exps=p1->exps;
tp->next=r;
tp=r;
p1=p1->next;
}
}
if(q1->exps==p1->exps)
{
temp=q1->conf+p1->conf;
if(t)
{
if(temp!=0)
{
tp->conf=temp;
tp->exps=p1->exps;
}
t=false;
p1=p1->next;
q1=q1->next;
}
else
{
r=new Node;
r->conf=temp;
r->exps=p1->exps;
tp->next=r;
tp=r;
p1=p1->next;
q1=q1->next;
}
}
}
while((q1->conf!=0.0||q1->exps!=0))
{
r=new Node;
r->conf=q1->conf;
r->exps=q1->exps;
tp=r;
q1=q1->next;
}
while((p1->conf!=0.0||p1->exps!=0))
{
r=new Node;
r->conf=p1->conf;
r->exps=p1->exps;
tp=r;
p1=p1->next;
}
r=new Node;
r->conf=0;
r->exps=0;
return first;
}
void main()
{
Node *ttp1,*ttp2,*ttp3;
cout<<"请输入第一个多项式:"<<endl;
ttp1=createNode();
cout<<"请输入第二个多项式:"<<endl;
ttp2=createNode();
printA(ttp1);
printA(ttp2);
ttp3=add(ttp1,ttp2);
printA(ttp3);
}