标题:请教下大家这段程序的错误在哪里,怎么改都不对??
只看楼主
qq979981948
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2016-5-16
结帖率:0
已结贴  问题点数:20 回复次数:4 
请教下大家这段程序的错误在哪里,怎么改都不对??
#include<iostream.h>
#include<string.h>
#include<stdlib.h>
#include<string.h>
#include<iomanip.h>
struct node
{
    char Name[9],Class_0[20],Num[11];
    int Order;
    float Elec,C_prog,Media,Eng,Math,Sport,Polity,Ave;
    node *next;
};
void *Create_Order()
{
    node *pn,*head=0;
    int num;
    cout<<"产生一条有序链表,请输入学生班级学号姓名与成绩,以-1结束"<<endl;
    cin>>num;
    while(num!=-1)
    {
        pn=new node;
        pn->num=num;
        cin>>pn->score;                         //???
        head=Insert(head,pn);                     //??
        cin>>num;
    }
    return head;
}
void *Satistic(node *head,char num[])                           //计算平均分
{
    while(head!=0)
    {
        p->Satistic=(p->Elec+p->C_prog+p->Media+p->Eng+p->Math+p->Sport+p->Polity)/7;
        p=p->next;
    }
}
void *Lookup(node *head,char num[])                        //查找指定学生信息
{
    cout<<"请输入要查询的学生学号,以-1结束"<<endl;
    cin>>num;
    node *pc,*pa;
    pc=pa=head;
    if(head==NULL)
    {
        cout<<"链表为空"<<endl;       //链表为空
        return NULL;
    }
    else
    {
        while(pc!=0&&pc->num!=num)           //查找节点
        {
            pa=pc;
            pc=pc->next;
        }
        if(pc==NULL)
            cout<<"未找到该学生信息"<<endl;
        else
        {
            cout<<"班级   学号   姓名   电子技术  C++程序设计  多媒体技术  大学英语  高等数学  大学体育 马克思主义政治经济学 平均成绩 名次"<<endl;
            cout<<pc->Class_0<<pc->Num<<pc->Name<<pc->Elec<<pc->C_prog<<pc->Media<<pc->Eng<<pc->Math<<pc->Sport<<pc->Polity<<pc->Ave<<pc->Order;
        }
    }
}
void *Modify(node *head)                          //????修改指定学生信息
{
    cout<<"请输入要修改的学生学号"<<endl;
    cin>>num;
        
}
void *Delete(node *head,char num[])                 //删除指定学生信息
{
    cout<<"请输入要删除学生的学号"<<endl;
    cin>>num;
    node *pc,*pa;
    pc=pa=head;
    if(head==NULL)
    {
        cout<<"链表为空"<<eddl;
        return NULL;
    }
    else if(pc->num==num)
    {
        head=pc->next;
        delete pc;
        cout<<"学生信息已删除"<<endl;
    }
    else
    {
        while(pc!=0&&pc->num!num)
        {
            pa=pc;
            pc=pc->next;
        }
        if(pc==NULL)
            cout<<"链表中没有要删除的学生信息"<<endl;
        else
        {
            pa->next=pc->next;
            delete pc;
            cout<<"学生信息已删除"<<endl;
        }
    }
    return head;
}
void sort(int s)                                //排序后输出
{
    int chang;
    int b[40];
    while(s==0)
    {
    cout<<"没有记录,请先输入记录!"<<endl;
    break;
    }
    if(s!=0)
    {
    cout<<"班级   学号   姓名   电子技术  C++程序设计  多媒体技术  大学英语  高等数学  大学体育 马克思主义政治经济学 平均成绩 名次"<<endl;
   

void *Insert(node *head,node *pn)                     //插入新学生信息
{
    cout<<"请输入要插入的学生信息"<<endl;
                                                           //???
    node *pc,*pa;
    pc=pa=head;
    if(head==0)
    {
        head=pn;
        pn->next=0;
        return head;
    }
    if(pn->score>=pc->score)
    {
        pn->next=head;
        head=pn;
        return head;
    }
    while(pc!=0&&pn->score<=pc->score)
    {
        pa=pc;
        pc=pc->next;
    }
    pn->next=pc;
    pa->next=pn;
  return head;
}
void Output(node *head)                          // 输出函数
{
    node *p=head;
    cout<<"班级   学号   姓名   电子技术  C++程序设计  多媒体技术  大学英语  高等数学  大学体育 马克思主义政治经济学 平均成绩 名次"<<endl;
    while(p!=0)
    {
        cout<<pc->Class_0<<pc->Num<<pc->Name<<pc->Elec<<pc->C_prog<<pc->Media<<pc->Eng<<pc->Math<<pc->Sport<<pc->Polity<<pc->Ave<<pc->Order;
        p=p->next;
    }
}
void Delchain(node *head)                        //删除整个表格
{
    node *p;
    p=head;
    while(head)
    {
        head=p->next;
        delete p;
        p=head;
        cout<<"表格已删除"<<endl;
    }
}
void main()
{
    node *head;
    int num,x;
    cout<<"         ********菜单******       "<<endl;
    cout<<"         *输入学生信息请按  1*      "<<endl;
    cout<<"         *计算平均分请按    2*      "<<endl;
    cout<<"         *查询学生信息请按  3*      "<<endl;
    cout<<"         *修改学生信息请按  4*      "<<endl;
    cout<<"         *删除学生信息请按  5*      "<<endl;
    cout<<"         *按平均分排序请按  6*       "<<endl;
    cout<<"         *插入学生信息请按  7*      "<<endl;
    cout<<"         *输出学生信息表请按8*      "<<endl;
    cout<<"         *删除表格请按      9*             <<endl;
    cin>>x;
    switch(x)
    {
        case 1:Create_order();
        case 2:Satistic(head,num[]);
        case 3:Lookup(head,num[]);
        case 4:Modify(head);
        case 5:Delete(head,num[])
                case 6:Sort();
        case 7:Insert();
        case 8:Output(head);
        case 9:Delchain;
    }

}

e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(22) : error C2039: 'num' : is not a member of 'node'
        e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(7) : see declaration of 'node'
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(23) : error C2039: 'score' : is not a member of 'node'
        e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(7) : see declaration of 'node'
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(24) : error C2065: 'Insert' : undeclared identifier
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(24) : error C2440: '=' : cannot convert from 'int' to 'struct node *'
        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(33) : error C2065: 'p' : undeclared identifier
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(33) : error C2227: left of '->Satistic' must point to class/struct/union
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(33) : error C2227: left of '->Elec' must point to class/struct/union
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(33) : error C2227: left of '->C_prog' must point to class/struct/union
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(33) : error C2227: left of '->Media' must point to class/struct/union
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(33) : error C2227: left of '->Eng' must point to class/struct/union
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(33) : error C2227: left of '->Math' must point to class/struct/union
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(33) : error C2227: left of '->Sport' must point to class/struct/union
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(33) : error C2227: left of '->Polity' must point to class/struct/union
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(34) : error C2227: left of '->next' must point to class/struct/union
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(50) : error C2039: 'num' : is not a member of 'node'
        e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(7) : see declaration of 'node'
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(50) : fatal error C1903: unable to recover from previous error(s); stopping compilation
执行 cl.exe 时出错.
搜索更多相关主题的帖子: include Media 姓名 
2016-06-24 17:08
jklqwe111
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:35
帖 子:335
专家分:1125
注 册:2014-4-13
得分:20 
pn->num=num;  对应e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(22) : error C2039: 'num' : is not a member of 'node'
大小写错误    pn->Num=num
2016-06-24 20:17
jklqwe111
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:35
帖 子:335
专家分:1125
注 册:2014-4-13
得分:0 
cin>>pn->score;  score;  无中生有的变量
2016-06-24 20:44
jklqwe111
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:35
帖 子:335
专家分:1125
注 册:2014-4-13
得分:0 
e:\microsoft visual studio\common\msdev98\bin\cpp1.cpp(24) : error C2065: 'Insert' : undeclared identifier
对应 head=Insert(head,pn);Insert()函数使用前没有声明
2016-06-24 20:50
jklqwe111
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:35
帖 子:335
专家分:1125
注 册:2014-4-13
得分:0 
void *Satistic(node *head,char num[])                           //计算平均分
{
    while(head!=0)
    {
        p->Satistic=(p->Elec+p->C_prog+p->Media+p->Eng+p->Math+p->Sport+p->Polity)/7;
        p=p->next;
    }
}
p既没声明,也没定义,另外char num[]这个参数没有用到。以下代码供参考。
int Satistic(node *head)                           //计算平均分
{   
    node *p;
    if (head==NULL) return 0;
    p=head;
    while(p)
    {  
        p->Ave=(p->Elec+p->C_prog+p->Media+p->Eng+p->Math+p->Sport+p->Polity)/7;
        p=p->next;
    }
    return 1;
}
返回链表指针的函数返回值应该定义为node *
比如   void *Insert(node *head,node *pn)  
改为   node *Insert(node *head,node *pn)

p->Satistic   ???????
2016-06-24 21:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-466327-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.827910 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved