| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 220 人关注过本帖
标题:修改程序代码中的错误
取消只看楼主 加入收藏
云心別鹤
Rank: 1
来 自:甘肃平凉
等 级:新手上路
帖 子:3
专家分:0
注 册:2010-12-1
结帖率:0
收藏
 问题点数:0 回复次数:0 
修改程序代码中的错误
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "malloc.h"
#define  cnt 32
typedef float elem;
typedef struct   student
{
    long int numble;
    char name[10];
    elem dy;
    elem zy;
    elem ty;
    elem a[8];
    elem b[6];
    elem sum;
    }stu;


stu   s[cnt];


float countstu(stu *s,int m,int n)//计算每位学生的总成绩
{
    int i,j;
    s->dy=0;
    s->ty=0;
    s->sum=0;
    for(i=0;i<m;i++)
        s->dy+=s->a[i];
        s->dy*=5.0;
    for(j=0;j<n;j++)
        s->ty+=s->b[j];
        s->ty*=5.0;
    s->sum=s->dy+s->zy+s->ty;
    return s->sum;
}



void sortsum(stu *s,int cnt)//按总成绩高低排序并输出排序后的结

{
    int i,j,k;
    stu R;
    for(i=0;i<cnt-1;i++)
        for(j=1;j<cnt;j++)
             if(s[i]->sum<s[j]->sum)
             {
               R=s[i];
               s[i]=s[j];
               s[j]=R;
             }
    for(i=0;i<cnt;i++)
    {
     printf("输出学号为ld的学生记录:")    ;
     printf("%ld\t %s\t %6.2f\t ",s[i]->numble,s[i]->name,s
[i]->zy);
     for(j=0;j<m,j++)
         printf("%6.2f\t ",s[i].a[j]);
     for(k=0;k<n,k++);
         printf("%6.2f\t ",s[i].b[k]);
     printf("%6.2f\t %6.2f\t %6.2f\t",s[i]->dy,s[i]-
>ty,s[i]->sum);
     printf("\n");

    }
}



    /*按智育成绩排序*/
void  stuzy()
{
    int i,j;
    stu R;
    for(i=0;i<cnt-1;i++)
        for(j=1;j<cnt;j++)
             if(s[i]->zy<s[j]->zy)
             {
               R=s[i];
               s[i]=s[j];
               s[j]=R;
             }
    for(i=0;i<cnt;i++)
        printf("%ld\t %s\t %6.2f\t\n",s[i].numble,s
[i].name,s[i].zy);
}
    /*按德育成绩排序*/
void  study(stu s[],int cnt)
{
    int i,j;
    stu R;
    for(i=0;i<cnt-1;i++)
        for(j=1;j<cnt;j++)
             if(s[i]->dy<s[j]->dy)
             {
               R=s[i];
               s[i]=s[j];
               s[j]=R;
             }
    for(i=0;i<cnt;i++)
        printf("%ld\t %s\t %6.2f\t\n",s[i].numble,s
[i].name,s[i].dy);
}
    /*按体育成绩排序,仅输出成绩大于等于10的学生信息*/
void stuty(stu s[],int cnt)
{
    int i,j;
    stu R;
    for(i=0;i<cnt-1;i++)
        for(j=1;j<cnt;j++)
             if(s[i]->ty<s[j]->ty)
             {
               R=s[i];
               s[i]=s[j];
               s[j]=R;
             }
    for(i=0;i<cnt;i++)
        if(s[i].ty>=10.0)
            printf("%ld\t %s\t %6.2f\t\n",s[i]-
>numble,s[i]->name,s[i]->ty);
        else break;
}

void  checkstu(stu s[],int cnt)//查询姓名为"**"的学生信息
{
    int i;
    for(i=0;i<n&&strcmp(s[i].name,"李同学"),i++);/*空循环
,条件为假时退出*/
    if(i==n)    printf("未找到**同学的相关信息");
        else if(i<n)
    {
        printf("输出查询结果:\n");
        printf("%ld, %s, %6.2f",s[i]->numble,s[i]-
>name,s[i]->zy);
        for(j=0;j<m,j++)
            printf("%6.2f",s[i]->a[j]);
        for(k=0;k<n,k++);
            printf("%6.2f,s[i].b[k]");
        printf("%6.2f, %6.2f, %6.2f",s[i]->dy,s[i]->ty,s
[i]->sum);
    }
}
void avestu(stu s[],int cnt)//输出全班同学的平均成绩
{
    int i;
    float count1=0.0,count2=0.0;count3=0.0,count=0.0;
    float avgzy,avgdy,avgty,avg;
    for(i=0;i<cnt;i++)
    {
        count1+=s[i]->zy;
        count2+=s[i]->dy;
        count3+=s[i]->ty;
        count+=s[i]->sum;
    }
    avgzy/=cnt;
    avgdy/=cnt;
    avgty/=cnt;
    avgzy/=cnt;
    avg/=cnt;
    printf("输出学生的智育,德育,体育的平均分:\n");
    printf("avgzy=%6.2f\navgdy=%6.2f\navgty=%
6.2f\n",avgzy,avgdy,avgty);
    printf("输出学生的总成绩的平均分:\n");
    printf("avg=%6.2f",avg);
}
void readdat()
{
    FILE *fp;
    char  str[],ch[];
    int i;
    fp=fopen("in.dat","r");
    for(i=0;i<32;i++)
    {
            fscanf(fp,"%ld ",&s[i].numble);
            gets(s[i].name);
            fsc%anf(fp,"%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f ",&s[i].zy,&s[i].a[0],&s[i].a[1],&s [i].a[2],&s[i].a[3],&s[i].a[4],&s[i].a[5],&s[i].a[6],&s[i].a[7],&s[i].b[0],&s[i].b[0],&s[i].b[1],&s [i].b[2],&s[i].b[3],&s[i].b[4],&s[i].b5],&s[i].dy,&s [i].ty,&s[i].sum);
    }
    fclose(fp);
}
void  writedat()
{
    FILE *fp;
    int i,j,k;
    fp=fopen(fp,"out.dat","w");
    for(i=0;i<32;i++)
    {
        fprintf(fp,"%ld %s %6.2f %6.2f %6.2f %6.2f %
6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %6.2f %
6.2f %6.2f %6.2f ",
            s[i].numble,s[i].name,s[i].zy,s[i].a
[0],s[i].a[1],s[i].a[2],s[i].a[3],s[i].a[4],s[i].a[5],s[i].a
[6],s[i].a[7],
            s[i].b[0],s[i].b[0],s[i].b[1],s[i].b
[2],s[i].b[3],s[i].b[4],s[i].b[5],s[i].dy,s[i].ty,s[i].sum);
    }
    fclose(fp);

void main()
{
    stu  s[cnt];
    int  i;
    s=(stu *) malloc (cnt*sizeof(stu));
    readdat();
    writedat();
    for(i=0;i<cnt;i++)
        printf("输出学号为%ld的总绩点: %f",s
[i].numble,countstu(&s[i],8,6));
    printf("按总成绩高低依次输出学生的信息:\n");
    sortsum(&s,cnt,8,6);
    printf("输出平均分:\n");
        avestu(&s,cnt);
    printf("按智育成绩高低输出:\n");
         stuzy(&s,cnt);
    printf("按德育成绩高低输出:\n");
         study(&s,cnt);
    printf("按体育成绩高低输出:\n");
         stuty(&s,cnt);
    printf("查询李同学的信息:\n");  
         checkstu(&s,cnt,"李同学");
}
      
   
搜索更多相关主题的帖子: 代码 
2010-12-02 20:18
快速回复:修改程序代码中的错误
数据加载中...
 
   



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

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