| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 610 人关注过本帖
标题:帮忙改一下程序错误
只看楼主 加入收藏
妄想之渡
Rank: 2
等 级:论坛游民
帖 子:26
专家分:48
注 册:2013-5-23
结帖率:100%
收藏
 问题点数:0 回复次数:1 
帮忙改一下程序错误
#include<stdio.h>
#include<stdlib.h>
#include<string>
#define max 100
typedef struct Stu{
    int number;
    char name;
    struct Stu *next;
}Stu,*linklist;
typedef struct TStudentMark{
    int mark;
    int count;
    struct TStudentMark *lchild,*rchild;
    Stu *list;
}TStudentMark,*TSMark;

void mainlist(TSMark tree);

TSMark insert(TSMark tree,int score,int num,char nam)
{
    TSMark p,q,t;
    linklist l,i,j;
    p=tree;
    q=NULL;
    while(p&&p->mark!=score)
    {
        p=q;
        if(score<p->mark)
        p=p->lchild;
        else
        p=p->rchild;
    }
    if(p==NULL)
    {
        t=(TSMark)malloc(sizeof(TStudentMark));
        t->mark=score;
        t->lchild=t->rchild=NULL;
        l=t->list;
        l=(linklist)malloc(sizeof(Stu));
        l->number=num;
        l->name=nam;
        l->next=NULL;
        if(tree==NULL)tree=t;
        else if(q->mark>score)q->lchild=t;
        else q->rchild=t;
    }
    if(p->mark==score)
    {
        while(i)
        {
            j=i;
            i=i->next;
        }
        i=j->next;
        i->number=num;
        i->name=nam;
        i->next=NULL;
    }
    return tree;
}

void Fun_1(TSMark tree)
{int score,num;
char nam;
printf("请输入成绩、学号,姓名:\n");
scanf("%d %d %c",&score,&num,&nam);
tree=insert(tree,score,num,nam);
printf("输入完毕,继续请按1,其他退出;");
int k;
scanf("%d",&k);
if(k==1)Fun_1(tree);
else {system("cls");mainlist(tree);}
}

void Fun_2(TSMark tree)
{TSMark p,s[max];
linklist l;
int top=0;
p=tree;
while(p||top)
{
    while(p)
    {
        s[top++]=p;
        p=p->lchild;
    }
    if(top)
    {
        p=s[--top];
        printf("分数:%2d\n",p->mark);
        printf("学号、姓名:");
        l=p->list;
        while(l)
        {
            printf("%d %c  ",l->number,l->name);
            l=l->next;
        }
    }
    p=p->rchild;
}


void Fun_3(TSMark tree)
{
    TSMark p,s[max];
    linklist l;
    int num,top=0;
    p=tree;
    printf("请输入学号:");
    scanf("%3d",&num);
    while(p||top)
    {
        while(P)
        {
            l=p->list;
            if(l->number!=num)
            {
                l=l->next;
            }
            printf("该生成绩为:%2d",p->mark);
            s[top++]=p;
            p=p->lchild;
        }
        if(top)
            {
                p=s[--top];
                p=p->rchild;
            }
    }
}

void Fun_4(TSMark tree)
{
    TSMark p;
    linklist l;
    int top=0;
    p=tree;
    while(p||top)
    {
        while(p)
        {
            l=p->list;
            p->count=0;
            if(l)
            {
                p->count++;l=l->next;
            }
            printf("分数:%2d  人数:%2d\n",p->mark,p->count);
            s[top++]=p;
            p=p->lchild;
        }
        if(top)
        {
            p=s[top--];
            p=p->rchild;
        }
    }
    if(tree==NULL)
    {
        printf("还未录入成绩,请稍后查询。\n");
        printf("返回请按1.");
        int k;
        scanf("%d",&k);
        if(k==1){system("cls");mainlist(tree);}
    }
}

void delet_L(linklist head,int num)
{
    linklist l,p;
    l=head;
    while(l->number==num)
    {
        p=l;l=l->next;free(p);
    }
}
TSMark delet_T(TSMark tree,int num,int score)
{
 TSMark p,parent,s,q;   //parent指向要删除的节点的双亲,p指向要删除的节点
    p=tree;
    parent=NULL;
    while(p)
    {
        if(p->mark==score)
            break;
        parent=p;
        if(p->mark>score)
            p=p->lchild;
        else
            p=p->rchild;
    }
    if(p==NULL)                  //不存在该树节点
        return tree;
    if(p->lchild==NULL)         //无左子树,右子树可有可无
    {
        if(parent==NULL)
            tree=p->rchild;
        else
            if(parent->lchild==p)
                parent->lchild=p->rchild;
            else
                parent->rchild=p->rchild;
        delet_L (p->list,num); free(p);
    }
    else //有左子树,右子树可有可无
    {
        q=p;
        s=q->lchild; ////
        while(s->rchild)
        {
            q=s;
            s=s->rchild;
        }
        if(q==p) //其左孩子没有右子树
            q->lchild=s->lchild;

        else
            q->rchild=s->lchild;
        p->score=s->score; delet_L (s->list,num);
        free(s);
    }
 return tree;   
}



void Fun_5(TSMark tree)
{
    int num,score;
    TSMark p;
    p=tree;
    printf("输入要删除的分数:%3d\n");
    scanf("%d",&score);
    printf("输入要删除的学号:%3d\n");
    scanf("%d",&num);
    delet_T(tree,num,score);
}





void mainlist(TSMark tree)
{system("cls");
printf("**********欢迎使用上海理工大学学生成绩管理系统**********\n");
printf("                 请选择:                                \n");
printf("                 1、学生成绩、信息输入                  \n");
printf("                 2、升序浏览                            \n");
printf("                 3、成绩查询                            \n");
printf("                 4、统计                                \n");
printf("                 5、删除                                \n");
printf("                 6、退出                                \n");
printf("********************************************************\n");

int n;
scanf("%d",&n);
switch(n)
{
case 1:Fun_1(tree);
    break;
case 2:Fun_2(tree)
    break;
case 3:Fun_3(tree);
    break;
case 4:Fun_4(tree);
    break;
case 5:Fun_5(tree);
    break;
case 6:exit;
default :printf("输入错误,请重新选择");
    }
system("pause");
}





void main()
{
    TSMark tree=NULL;
    mainlist(tree);
}

程序运行后的报错我都看不懂
搜索更多相关主题的帖子: include number insert count 
2013-07-02 13:13
妄想之渡
Rank: 2
等 级:论坛游民
帖 子:26
专家分:48
注 册:2013-5-23
收藏
得分:0 
木有人么?
发一下报错信息
学生成绩管理.cpp
.cpp(104) : error C2601: 'Fun_3' : local function definitions are illegal
.cpp(133) : error C2601: 'Fun_4' : local function definitions are illegal
.cpp(169) : error C2601: 'delet_L' : local function definitions are illegal
.cpp(178) : error C2601: 'delet_T' : local function definitions are illegal
.cpp(228) : error C2601: 'Fun_5' : local function definitions are illegal
.cpp(244) : error C2601: 'mainlist' : local function definitions are illegal
.cpp(280) : error C2601: 'main' : local function definitions are illegal
.cpp(286) : fatal error C1004: unexpected end of file found
执行 cl.exe 时出错.
2013-07-02 14:57
快速回复:帮忙改一下程序错误
数据加载中...
 
   



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

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