qq_32950413 于 2016.03.25 21:24 提问

[Error] a function-definition is not allowed here before '{' token
[Error] expected '}' at end of input

7个回答

qq_32950413   2016.03.25 21:25

qq_32950413   2016.03.25 21:28

#include using namespace std;struct Node{float coef; //系数int exp; //指数Node next;};class LinkList{private: Node*head;public:LinkList( ); LinkList(int n); ~LinkList( ); void PrintList( ); void Sort(LinkList A);void Add(LinkList &A,LinkList B);void Mul(LinkList&A,LinkList B);void PloyMul();void ExitSystem();void Menu();};LinkList::LinkList(){ head=new Node; head->next=NULL;}LinkList::LinkList(int n){ head=new Node; head->next=NULL; Node*p,*r; for(int i=0;i>p->coef>>p->exp; p->next=r->next; r->next=p;}}LinkList::~LinkList(){ Node*p=head->next; while(p){ head->next=p->next; delete p; p=head->next; } delete head;} void LinkList::PrintList(){Node*p=head->next;if(p->coef>0){ if(p->coef==1){ if(p->exp==1) cout<<"X";elsecout<<"X"<exp; } else{ if(p->exp==1) cout<coef<<"X"; else cout<coef<<"X"<exp; } }else if(p->coef==0){ } else { if(p->coef==-1){ if(p->exp==1) cout<<"-X"; else cout<<"-X"<exp; } else { if(p->exp==1) cout<coef<<"X"; else cout<coef<<"X"<exp; } p=p->next; while(p!=NULL){ }if(p->coef>0){ if(p->coef==1){ if(p->exp==1) cout<<"+X";elsecout<<"+X"<exp; } if(p->coef!=1){ if(p->exp==1) cout<<"+"<coef<<"X"; else cout<<"+"<coef<<"X"<exp; } }if(p->coef==0){ }if(p->coefcoef==-1){ if(p->exp==1) cout<<"-X"; else cout<<"-X"<exp; } if(p->coef!=-1){ if(p->exp==1) cout<coef<<"X"; else cout<coef<<"X"<exp; } p=p->next;}}void LinkList:: Sort(LinkList A) {Node*p=head->next,*q,*maxp;int temp1,twmp2;while(p->exp){ maxp=p,q=p->next; while(p){ if(maxp->expexp)maxp=q; q=q->next; } temp1=p->exp; p->exp=maxp->exp; maxp->exp=temp1; temp=p->coef; p->coef=map->coef; maxp->coef=temp2; p=p->next;}}void LinkList::Add(LinkList &A,LinkList B){ Node*pr,*qr,*p,*q,*v;pr=A.head;p=pr->next;qr=B.head;q=qr->next;while(p!=NULL&&q!=NULL){ if(p->expexp){ pr=p; p=p->next; } else if(p->exp>q->exp){ v=q->next; pr->next=q; q->next=p; q=v; } else { p->coef=p->coef+q->coef; if(p->coef==0){ pr->next=p->next; pr=p; delete p; p=pr->next; } else{ pr=p; p=p->next; } qr->next=q->next; qr=q; delete q; q=qr->next; } if(q!=NULL){ pr->next=q; delete B.head; }}} void LinkList:: Mul(LinkList&A,LinkList B){LinkList D;Node*pr,*qr,*p,*q,*rr,*r;pr=A.head;p=pr->next;qr=B.head;q=qr->next;while(q!=NULL){ LinkList C; rr=C.head; r=rr; while(p!=NULL) { Node*s; s=new Node; s->coef=(p->coef)(q->coef); s-exp=p->exp+q-exp; r=s; r->next=Null; pr=p; p=p->next; } Add(D,C); qr=q; q=q->next; p=pr->next;}if(q==NULL){Sort(D);D.PrintList();} else{ cout<<"error!"<>n1; LinkList A(n1); Sort(A); cout<<"输入第二个多项式的项数："<>n2; LinkList B(n2); Sort(B); cout<<"相乘后结果："; Mul(A,B); cout<<"\n是否继续" }}void LinkList::ExitSystem(){ exixt(1);}void LinkList::Menu(){ while(true){ char sign; cout<<"\n\n"; cout<<"1.chengfa"; cout<<"2.tuichu"; cout<<""; cin>>sign; switch(sign) {case'1':PloyMul(); break; case'2':ExitSystem(); break; default:break; } cin.sync(); system("cls"); }}int main(){ Menu(); return 0;}

qq_32950413   2016.03.25 21:29

qq_32950413   2016.03.25 21:30

qq_32950413   2016.03.25 21:33

#include using namespace std;
struct Node{float coef; //系数
int exp; //指数Node next;};
class LinkList{private: Node*head;
public:LinkList( );
LinkList(int n);
~LinkList( );
void PrintList( );
void Sort(LinkList A);
void Add(LinkList &A,LinkList B);
void Mul(LinkList&A,LinkList B);
void PloyMul();void ExitSystem();
void Menu();};
LinkList::LinkList(){ head=new Node; head->next=NULL;}
LinkList::LinkList(int n){ head=new Node; head->next=NULL; Node*p,*r; for(int i=0;i>p->coef>>p->exp; p->next=r->next; r->next=p;}}LinkList::~LinkList(){ Node*p=head->next; while(p){ head->next=p->next; delete p; p=head->next; } delete head;} void LinkList::PrintList(){Node*p=head->next;if(p->coef>0){ if(p->coef==1){ if(p->exp==1) cout<<"X";elsecout<<"X"<exp; } else{ if(p->exp==1) cout<coef<<"X"; else cout<coef<<"X"<exp; } }else if(p->coef==0){ } else { if(p->coef==-1){ if(p->exp==1) cout<<"-X"; else cout<<"-X"<exp; } else { if(p->exp==1) cout<coef<<"X"; else cout<coef<<"X"<exp; } p=p->next; while(p!=NULL){ }if(p->coef>0){ if(p->coef==1){ if(p->exp==1) cout<<"+X";elsecout<<"+X"<exp; } if(p->coef!=1){ if(p->exp==1) cout<<"+"<coef<<"X"; else cout<<"+"<coef<<"X"<exp; } }if(p->coef==0){ }if(p->coefcoef==-1){ if(p->exp==1) cout<<"-X"; else cout<<"-X"<exp; } if(p->coef!=-1){ if(p->exp==1) cout<coef<<"X"; else cout<coef<<"X"<exp; } p=p->next;}}void LinkList:: Sort(LinkList A) {Node*p=head->next,*q,*maxp;int temp1,twmp2;while(p->exp){ maxp=p,q=p->next; while(p){ if(maxp->expexp)maxp=q; q=q->next; } temp1=p->exp; p->exp=maxp->exp; maxp->exp=temp1; temp=p->coef; p->coef=map->coef; maxp->coef=temp2; p=p->next;}}void LinkList::Add(LinkList &A,LinkList B){ Node*pr,*qr,*p,*q,*v;pr=A.head;p=pr->next;qr=B.head;q=qr->next;while(p!=NULL&&q!=NULL){ if(p->expexp){ pr=p; p=p->next; } else if(p->exp>q->exp){ v=q->next; pr->next=q; q->next=p; q=v; } else { p->coef=p->coef+q->coef; if(p->coef==0){ pr->next=p->next; pr=p; delete p; p=pr->next; } else{ pr=p; p=p->next; } qr->next=q->next; qr=q; delete q; q=qr->next; } if(q!=NULL){ pr->next=q; delete B.head; }}} void LinkList:: Mul(LinkList&A,LinkList B){LinkList D;Node*pr,*qr,*p,*q,*rr,*r;pr=A.head;p=pr->next;qr=B.head;q=qr->next;while(q!=NULL){ LinkList C; rr=C.head; r=rr; while(p!=NULL) { Node*s; s=new Node; s->coef=(p->coef)
(q->coef); s-exp=p->exp+q-exp; r=s; r->next=Null; pr=p; p=p->next; } Add(D,C); qr=q; q=q->next; p=pr->next;}if(q==NULL){Sort(D);D.PrintList();} else{ cout<<"error!"<>n1; LinkList A(n1); Sort(A); cout<<"输入第二个多项式的项数："<>n2; LinkList B(n2); Sort(B); cout<<"相乘后结果："; Mul(A,B); cout<<"\n是否继续" }}void LinkList::ExitSystem(){ exixt(1);}void LinkList::Menu(){ while(true){ char sign; cout<<"\n\n"; cout<<"1.chengfa"; cout<<"2.tuichu"; cout<<""; cin>>sign; switch(sign) {case'1':PloyMul(); break; case'2':ExitSystem(); break; default:break; } cin.sync(); system("cls"); }}int main(){ Menu(); return 0;}

qq423399099      2016.03.25 22:07

`````` struct Node{
float coef; //系数
int exp; //指数
Node next;//应该改为Node *next;
};
LinkList::LinkList(int n)
{
head=new Node;
head->next=NULL;
Node*p,*r;
for(int i=0;i>p->coef>>p->exp; p->next=r->next; r->next=p;}//for循环中居然出现了4个分号。。。
}
``````
CSDNXIAOD   2016.03.30 11:25

----------------------biu~biu~biu~~~在下问答机器人小D，这是我依靠自己的聪明才智给出的答案，如果不正确，你来咬我啊！