错误如下:
yuan.cpp
i:\数据结构课程设计\yiyuanduoxiangshi\yuan.cpp(2) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\数据结构课程设计\yiyuanduoxiangshi\yuan.cpp(5) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\数据结构课程设计\yiyuanduoxiangshi\yuan.cpp(6) : error C2143: syntax error : missing ';' before '{'
i:\数据结构课程设计\yiyuanduoxiangshi\yuan.cpp(7) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\数据结构课程设计\yiyuanduoxiangshi\yuan.cpp(8) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\数据结构课程设计\yiyuanduoxiangshi\yuan.cpp(9) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\数据结构课程设计\yiyuanduoxiangshi\yuan.cpp(10) : error C2143: syntax error : missing ';' before 'PCH creation point'
i:\数据结构课程设计\yiyuanduoxiangshi\yuan.cpp(11) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
yiyuanduoxiangshi.exe - 1 error(s), 0 warning(s)
代码如下:
#include<iostream>
using namespace std;
float sum;
typedef struct PNode
{
float coef;
int expn;
struct PNode *next;
}PNode, *Polynomial;
void CreatePolyn(Polynomial &P,int n)
{//输入m项的系数和指数,建立表示多项式的有序链表P
P = new PNode;
P->next = NULL;
int i;
Polynomial s,pre,q;
for( i=1; i<=n; ++i )
{
s = new PNode;
cout<<"请输入系数和指数:"<<endl;
cin>>s->coef>>s->expn;
pre = P; // pre用于保存q的前驱,初值为头结点
q = P->next; // *q为第一个大于输入项指数的节点
while( q && q->expn<s->expn )
{
pre = q;
q = q->next;
}
s->next = q;
pre->next = s;
}
}
void AddPolyn(Polynomial &Pa,Polynomial &Pb)
{//多项式加法:Pa=Pa+Pb,利用两个多项式的节点构成和多项式
Polynomial p1,p2,p3,r;
p1 = Pa->next; p2 = Pb->next; //p1和p2初值分别指向Pa和Pb的首元结点
p3 = Pa; //p3指向和多项式的当前节点,初值为Pa
while( p1 && p2 ) //p1和p2均非空
{
if( p1->expn == p2->expn ) //指数相等
{
sum = p1->coef + p2->coef; //sum保存两项的系数和
if( sum!=0 ) //系数和不为零
{
p1->coef = sum; //修改Pa当前节点的系数值为两项系数的和
p3->next = p1; p3 = p1; //将修改后的Pa当前节点链在p3之后,p3指向p1
p1 = p1->next; //p1指向后一项
r = p2; p2 = p2->next; delete r; //删除Pb当前节点,p2指向后一项
}
else //系数和为零
{
r = p1; p1 = p1->next; delete r;
r = p2; p2 = p2->next; delete r;
}
}
else if( p1->expn < p2->expn ) //Pa当前节点的指数值小
{
p3->next = p1;
p3 = p1;
p1 = p1->next;
}
else //Pb当前节点的指数值小
{
p3->next = p2;
p3 = p2;
p2 = p2->next;
}
}
p3->next = p1?p1:p2; //插入非空多项式的剩余段
delete Pb;
}
void Output(Polynomial &Pa)
{
Polynomial p; //p用来指向当前节点
p = Pa->next;
cout<<"相加后的多项式为:"<<endl;
while ( p->next!=NULL )
{
cout<<p->coef<<"x^"<<p->expn<<"+";
p = p->next;
}
cout<<p->coef<<"x^"<<p->expn<<endl;
}
void Userface()
{
cout<<" 欢迎使用一元多项式加法器! "<<endl;
cout<<"--------------------------------------------- "<<endl;
// cout<<"- - "<<endl;
cout<<"- - "<<endl;
cout<<"- 1.计算 - "<<endl;
cout<<"- 2.退出 - "<<endl;
cout<<"- - "<<endl;
// cout<<"- - "<<endl;
cout<<"--------------------------------------------- "<<endl;
cout<<"请输入序号选择您需要的功能:"<<endl;
}
void Jisuan()
{
int n;
cout<<"请输入第一个多项式项数:"<<endl;
cin>>n;
Polynomial Pa;
CreatePolyn(Pa,n);
cout<<"请输入第二个多项式项数:"<<endl;
cin>>n;
Polynomial Pb;
CreatePolyn(Pb,n);
AddPolyn(Pa,Pb);
Output(Pa);
}
void Select()
{
int k;
cin>>k;
switch(k)
{
case 1: Jisuan();
break;
case 2: exit(1);
default:
cout<<"输入错误,请重新输入:"<<endl;
Userface();
Select();
break;
}
#include<iostream>
#include"Status.h"
using namespace std;
int main()
{
Userface();
Select();
return 0;
}