baozhadehulu 2016-01-06 03:49 采纳率: 52.6%
浏览 1541
已采纳

请教一个有关c语言的问题

错误如下:
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;
}
  • 写回答

3条回答 默认 最新

  • threenewbee 2016-01-06 04:31
    关注

    void Select()定义中switch少后括号

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能