| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 554 人关注过本帖
标题:【求助】请求懂得人修改我的成绩统计程序
取消只看楼主 加入收藏
hjhppx
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2011-9-19
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:2 
【求助】请求懂得人修改我的成绩统计程序
大家帮助我一下,我做出来的成绩统计程序输入到成绩单中以后,显示不了社会和总成绩,希望大家耐心帮帮我。我急着要用,谢谢!!

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define N 15                                //学号位数
#define  M 15                                //姓名字节数
#define  L 6                                //成绩科目数

void printf_(struct stu *);                    //输出单个的学生数据
void printf_(struct stu *);                    //输出单个的学生数据
struct stu * scanf1_();                        //接收单个的学生数据,返回指针,
struct stu * scanf_();                        //得到学生的数据,并放入到链表中
void print_(struct stu *);                    //输出链表中的学生信息
struct stu *num_paixu(struct stu *);        //用链表给学生排序
void chaxun(struct stu *);                    //根据学生的学号查询学生的信息,并把学生的数据输出
struct stu * charu(struct stu *);            //将学生的数据插入到顺序排放的链表中,并且插入后也是顺序排放的。
struct stu * shanchu(struct stu *);            //删除数据
void xiugai(struct stu *);                    //修改学生的信息。
void fprint_(struct stu *);                    //把数据写入到文件
int to_ji(struct stu *);                    //统计学生的总人数
int t_ji_tj(struct stu *);                    //统计成绩在某一区间内的人数
struct stu * ch_ji_paixu(struct stu *);        //按成绩排序,默认的是按总成绩排序
void avrage(struct stu *head,float *);        //计算平均成绩
void fb_avrage(float *);                    //将平均成绩放在文件的最后面
//struct stu * load();                        //从文件读取学生信息
//建立学生结构体
struct stu
{
    char num[N];
    char name[M];
    int ch_ji[L];
    struct stu *next;
};


void main()
{   
    int n,x=1,k=0;
    float a[L]={0};
    struct stu *head=NULL;

    char ch;
    while(x)
    {    system("cls");
        printf("                            黄剑豪创作,成绩统计程序\n");
        printf("                  0---退出系统                    1---录入数据                 \n");
        printf("                  2---保存文件                    3---按成绩排序               \n");
        printf("                  4---输出信息                    5---按学号排序               \n");
        printf("                  6---统计人数                    7---查询信息                 \n");
        printf("                  8---插入数据                    9---删除数据                 \n");
        printf("                 10---修改数据                   11---读取数据                 \n");
        printf("*******************************************************************************\n");
        scanf("%d",&n);
        getchar();
        switch(n)
        {
            case 0:
                x=0;break;
            case 1:
                head=scanf_();break;
            case 2:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入学生的数据!");

                    getchar();
                    break;
                }
                else
                    fprint_(head);break;
            case 3:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入学生的数据!");
                    getchar();
                    break;
                }
                else
                {
                    head=ch_ji_paixu(head);
                    break;
                }
            case 4:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入学生的数据!");
                    getchar();
                    break;
                }
                else
                    print_(head);break;
            case 5:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入学生的数据!");
                    getchar();
                    break;
                }
                else
                {
                    head=num_paixu(head);
                    printf("是否显示排序结果 Y/N ?");
                    ch=getchar();getchar();
                    if(ch=='y'||ch=='Y')
                    {
                        printf("\n");
                        print_(head);
                    }
                    break;
                }
            case 6:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入学生的数据!");
                    getchar();
                    break;
                }
                else
                {
                    k=to_ji(head);
                    printf("总共有%3d 名学生",k);
                    getchar();
                    break;
                }
            
            case 7:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入学生的数据!");
                    getchar();
                    break;
                }
                else
                {
                    chaxun(head);
                    getchar();
                    break;
                }
        
            case 8:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入学生的数据!");
                    getchar();
                    break;
                }
                else
                    head=charu(head);break;
            
            case 9:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入学生的数据!");
                    getchar();
                    break;
                }
                else
                {
                    head=shanchu(head);
                    break;
                }
        
            case 10:
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入学生的数据!");
                    getchar();
                    break;
                }
                else
                {
                    xiugai(head);
                    break;
                }
/*            case 11:
                head = load();
                if(head==NULL||head->next==NULL)
                {
                    printf("请先录入学生的数据!");
                    getchar();
                }
                break;
                */
               
               
               
               

               
            
            default :
                printf("输入有误,请重新输入!");
                getchar();
                break;
        }
    }
}

//输出单个的学生数据
void printf_(struct stu *p0)
{
    int i;
    printf("学号:");
    puts(p0->num);
    printf("姓名:");
    puts(p0->name);
    printf("语文   数学    英语    科学    社会   总成绩\n");
    for(i=0;i<L;i++)
        printf("%-8d",p0->ch_ji[i]);
    printf("\n");
}
//接收单个的学生数据,返回指针,
struct stu * scanf1_()
{
    int i,sum=0;
    struct stu *p0;
    p0=(struct stu *)malloc(sizeof(struct stu));
    printf("请输入学生的学号:");
    gets(p0->num);
    printf("请输入学生的姓名:");
    gets(p0->name);
    printf("请输入学生的五科成绩(语文、数学、英语、科学、社会):");
    for(i=0;i<L-1;i++)
    {
        scanf("%d",&p0->ch_ji[i]);
        sum+=p0->ch_ji[i];
    }
    getchar();
    p0->ch_ji[L-1]=sum;
    return p0;
}
//得到学生的数据,并放入到链表中
struct stu * scanf_()
{
    struct stu *p1,*p2,*head;   
    int i,sum=0,n=0;
    printf("注意:当学生学号为  0  时输入结束\n\n");
    p1=(struct stu *)malloc(sizeof(struct stu));   /*得到学生信息*/
    head=p2=p1;
    do
    {    printf("请输入学生的学号:");   
        gets(p1->num);
        if(strcmp(p1->num,"0")==0)
            break;
        printf("请输入学生的姓名:");
        gets(p1->name);
        printf("请输入学生的五科成绩(语文、数学、英语、科学、社会):");
        for(i=0;i<L-1;i++)
        {
            scanf("%d",&p1->ch_ji[i]);
            sum+=p1->ch_ji[i];
        }
        getchar();
        printf("\n");
        p1->ch_ji[L-1]=sum;
        sum=0;
        p1=(struct stu *)malloc(sizeof(struct stu));
        p2->next=p1;
        p2=p1;
        n++;
    }while(1);
    p1->next=NULL;
    printf("成绩输入结束!\n");   
    getchar();/*学生的数据被放在链表中*/
    return head;
}
    /*输出链表中的学生信息*/
void print_(struct stu *head)            
{
    int i;
    struct stu *p1,*p2;
    p1=p2=head;
    while(p1->next!=NULL)
    {
        printf("学号: ");
        puts(p1->num);
        printf("姓名: ");
        puts(p1->name);
        printf("语文   数学    英语    科学    社会   总成绩\n");
        for(i=0;i<L;i++)
            printf("%-8d",p1->ch_ji[i]);
        printf("\n");
        p1=p2->next;
        p2=p1;
    }
    getchar();
}
    /*用链表给学生排序*/
struct stu *num_paixu(struct stu *head)               
{
    struct stu *p1,*p2,*p3,*p4,*p5,*p6,*p7;
    int x=1;
    for(p1=head;p1->next!=NULL;p4=p1,p1=p1->next)
    {
        p3=p1;
        for(p2=p1->next,p5=p7=p2;p2->next!=NULL;p7=p2,p2=p2->next)
        {
            if(strcmp(p3->num,p2->num)>0)
            {
                p3=p2;
                p5=p7;
            }
        }
        if(p3!=p1)
        {            
            if(x&&p1==head)
            {
                p6=p1->next;
                p1->next=p3->next;
                p3->next=p6;
                p5->next=p1;
                head=p3;
                p1=p3;
                x=0;
            }
            else
            {
                p6=p1->next;
                p1->next=p3->next;
                p3->next=p6;
                p4->next=p3;
                p5->next=p1;
                p1=p3;
            }

        }
    }
    printf("排序成功!\n");
    return head;
}
//根据学生的学号查询学生的信息,并把学生的数据输出
void chaxun(struct stu *head)
{
    char a[N];
    struct stu *p1;
    printf("请输入要查询的学号:");
    gets(a);
    p1=head;
    while(p1->next!=NULL)
    {
        if(strcmp(p1->num,a)==0)
            break;
        p1=p1->next;
    }
    if(p1->next==NULL)
        printf("没有找到学号为 %s 的学生!\n",a);
    else
    {
        printf("要查询的学生信息如下:\n\n");
        printf_(p1);
    }
}
//将学生的数据插入到顺序排放的链表中,并且插入后也是顺序排放的。
struct stu * charu(struct stu *head)
{
    struct stu *p1,*p2,*p3;
    p1=scanf1_();
    p2=head;
    p3=p2;
    while((strcmp(p2->num,p1->num)<0)&&p2->next!=NULL)
    {
        p3=p2;
        p2=p2->next;
    }
    if(p2==head)
    {
        p1->next=head;
        head=p1;
    }
    else
    {
        p3->next=p1;
        p1->next=p2;
    }
    printf("插入成功!\n");
    getchar();
    return head;
}
//删除数据
struct stu * shanchu(struct stu *head)
{
    char a[N];
    struct stu *p1,*p2,*p3;
    printf("请输入要删除的学生的学号:");
    gets(a);
    p1=head;
    p2=p1;
    while((strcmp(p2->num,a)!=0)&&p2->next!=NULL)
    {
        p3=p2;
        p2=p2->next;
    }
    if(p2->next==NULL)
        printf("没有找到要删除的数据!\n");
    else if(p2==head)
    {
        head=p2->next;
        printf("删除成功!\n");
    }
    else
    {   
        p3->next=p2->next;
        printf("删除成功!\n");
    }
    getchar();
    return head;
}
//修改学生的信息。
void xiugai(struct stu *head)
{
    char a[N];
    struct stu *p1;
    int i,k;
    printf("输入要修改的学生的学号");
    gets(a);
    p1=head;
    while(p1->next!=NULL)
    {
        if(strcmp(p1->num,a)==0)
            break;
        p1=p1->next;
    }
    if(p1->next==NULL)
    {
        printf("没有要找的学生信息!\n");
        getchar();
    }
    else
    {
        printf("***********************************\n");
        printf("*    0---放弃修改                 *\n");
        printf("*    1---修改学号                 *\n");
        printf("*    2---修改姓名                 *\n");
        printf("*    3---修改成绩                 *\n");
        printf("*    4---修改全部                 *\n");
        printf("***********************************\n");
        scanf("%d",&k);
        getchar();
        switch(k)
        {
            case 0:
                break;
            case 1:
                printf("请输入新学号:");
                gets(p1->num);
                printf("修改成功!");
                getchar();
                break;
            case 2:
                printf("请输入新姓名:");
                gets(p1->name);
                printf("修改成功!");
                getchar();
                break;
            case 3:
                {
                    printf("***********************************\n");
                    printf("*    0---放弃修改                 *\n");
                    printf("*    1---修改全部成绩             *\n");
                    printf("*    2---修改语文成绩             *\n");
                    printf("*    3---修改数学成绩             *\n");
                    printf("*    4---修改英语成绩             *\n");
                    printf("***********************************\n");
                    scanf("%d",&k);
                    switch(k)
                    {
                    case 0:
                        break;
                    case 1:
                        p1->ch_ji[L-1]=0;
                        printf("请输入学生的五科成绩(语文、数学、英语、科学、社会):");
                        for(i=0;i<L-1;i++)
                        {
                            scanf("%d",&p1->ch_ji[i]);
                            p1->ch_ji[L-1]+=p1->ch_ji[i];
                        }
                        printf("修改成功!");
                        getchar();
                        getchar();
                        break;
                    case 2:
                        printf("请输入新语文成绩:");
                        scanf("%d",&p1->ch_ji[0]);
                        printf("修改成功!");
                        getchar();
                        break;
                    case 3:
                        printf("请输入新数学成绩:");
                        scanf("%d",&p1->ch_ji[1]);
                        printf("修改成功!");
                        getchar();
                        break;
                    case 4:
                        printf("请输入新英语成绩:");
                        scanf("%d",&p1->ch_ji[2]);
                        printf("修改成功!");
                        getchar();
                        break;
                    case 5:
                        printf("请输入新科学成绩:");
                        scanf("%d",&p1->ch_ji[0]);
                        printf("修改成功!");
                        getchar();
                        break;
                    case 6:
                        printf("请输入新社会成绩:");
                        scanf("%d",&p1->ch_ji[0]);
                        printf("修改成功!");
                        getchar();
                        break;
                    default :   
                        printf("您的输入有误!");
                        getchar();
                        break;
                    }
                    break;
                }
            case 4:
                printf("请输入新的学号:");
                gets(p1->num);
                printf("请输入新的姓名:");
                gets(p1->name);
                p1->ch_ji[L-1]=0;
                printf("请输入新的五科成绩(语文、数学、英语、科学、社会):");
                for(i=0;i<L-1;i++)
                {
                    scanf("%d",&p1->ch_ji[i]);
                    p1->ch_ji[L-1]+=p1->ch_ji[i];
                }
                printf("修改成功!");
                getchar();
                getchar();
                break;
            default:
                printf("您的输入有误!");
                getchar();
                break;
        }
    }
}
//把数据写入到文件
void fprint_(struct stu *head)
{
    FILE *fb;
    struct stu *p1;   
    if((fb=fopen("成绩单.txt","w"))==NULL)
    {
        printf("文件   成绩单.txt    打开失败");
        exit(0);
    }
    fprintf(fb,"学号          姓名         语文          数学         英语         科学         社会       总成绩\n");
    for(p1=head;p1->next!=NULL;p1=p1->next)
        fprintf(fb,"%-13s%-15s%-13d%-14d%-14d%d\n",p1->num,p1->name,p1->ch_ji[0],p1->ch_ji[1],p1->ch_ji[2],p1->ch_ji[3]);
    fclose(fb);        
    printf("文件成功保存到  成绩单.txt 中!\n");
    getchar();
}
//统计学生的总人数
int to_ji(struct stu *head)
{
    int n=0;
    struct stu *p1;
    for(p1=head;p1->next!=NULL;p1=p1->next)
        n++;
    return n;
}

//按成绩排序
struct stu * ch_ji_paixu(struct stu *head)
{
    struct stu *p1,*p2,*p3,*p4,*p5,*p6,*p7;
    int x=1,n,i=L-1;
    char ch;
    printf("***********************************\n");
    printf("*    0---退出                     *\n");
    printf("*    1---按总成绩排序             *\n");
    printf("*    2---按语文成绩排序           *\n");
    printf("*    3---按数学成绩排序           *\n");
    printf("*    4---按英语成绩排序           *\n");
    printf("*    5---按科学成绩排序           *\n");
    printf("*    6---按社会成绩排序           *\n");
    printf("***********************************\n");
    scanf("%d",&n);
    if(n!=0)
        getchar();
    switch(n)
    {
        case 0:  break;
        case 1:   i=L-1;break;
        case 2:   i=0;break;
        case 3:   i=1;break;
        case 4:   i=2;break;
        default:
            printf("输入有误!");
            getchar();
            break;            
    }
    if(n<=4&&n>0)
    {
        for(p1=head;p1->next!=NULL;p4=p1,p1=p1->next)
        {
            p3=p1;
            for(p2=p1->next,p5=p7=p2;p2->next!=NULL;p7=p2,p2=p2->next)
            {
                if(p3->ch_ji[i]-p2->ch_ji[i]<0)
                {
                    p3=p2;
                    p5=p7;
                }
            }
            if(p3!=p1)
            {            
                if(x&&p1==head)
                {
                    p6=p1->next;
                    p1->next=p3->next;
                    p3->next=p6;
                    p5->next=p1;
                    head=p3;
                    p1=p3;
                    x=0;
                }
                else
                {
                    p6=p1->next;
                    p1->next=p3->next;
                    p3->next=p6;
                    p4->next=p3;
                    p5->next=p1;
                    p1=p3;
                }

            }
        }
        printf("排序成功!\n");
        printf("是否查看排序结果 Y/N  ");
        ch=getchar();getchar();
        if(ch=='y'||ch=='Y')
        {
            printf("\n");
            print_(head);
        }
    }
    return head;
}

/* 从文件读入学生记录
struct stu * load()
{
    struct stu *p1, *tail, *head ;
    head = tail = NULL;
    char filepn[10];
    FILE *fp;
    if((fp=fopen("成绩单.txt","r")) == NULL)
    {
        printf("文件   成绩单.txt    打开失败");
        exit(0);
    }
    while (!feof(fp)){
        p1 = (struct stu *) malloc (sizeof(struct stu));
        fscanf(fp, "%s%s%d%d%d%d\n", &p1->num, &p1->name, &p1->ch_ji[0], &p1->ch_ji[1], &p1->ch_ji[2]);
        if(head == NULL)
            head = p1;
        else  
            tail->next = p1;
        tail = p1;
    }
    fclose(fp);
    return head;
}


*/

谢谢!
搜索更多相关主题的帖子: 统计 void include 成绩单 总成绩 
2011-09-19 20:52
hjhppx
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2011-9-19
收藏
得分:0 
到底是什么地方出问题了呢?告诉我一下。
2011-09-19 20:57
hjhppx
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2011-9-19
收藏
得分:0 
调试是没问题的。可是做出来保存成绩就会出现问题。
2011-09-20 20:34
快速回复:【求助】请求懂得人修改我的成绩统计程序
数据加载中...
 
   



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

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