計(jì)算機(jī)等級(jí)考試三級(jí)編程解析九

字號(hào):

九、學(xué)生成績,結(jié)構(gòu)體問題
    下列程序的功能是:已知學(xué)生的記錄由學(xué)號(hào)和學(xué)習(xí)成績構(gòu)成,N名學(xué)生的數(shù)據(jù)已存入
    A數(shù)組中。找出成績的學(xué)生記錄(假定成績的記錄中的),通過形參返回。
    請考生編寫函數(shù)MMM(STU A[],STU *S)實(shí)現(xiàn)程序的要求,最后調(diào)用函數(shù)READWRITEDAT
    ()把結(jié)果輸出到文件OUT.DAT中.
    例如: KS01 87
    KS09 97
    KS11 67
    則調(diào)用該函數(shù)后,輸出THE :KS09,97
    # include"stdio.h"
    # include"string.h"
    # define N 10
    void readwritedat();
    typedef struct ss{
    char num[10];
    int s;
    }STU;
    mmm(STU a[],STU *s)
    {
    }
    main()
    {
    STU a[N]={{"01",81},{"02",89},{"03",66},{&quo
    t;04",87},{"05",77},
    {"06",90},{"07",79},{"08",61},{"09&qu
    ot;,80},{"10",71}},m;
    int i;
    for(i=0;iprintf("No=%s Mark=%d\n",a[i].num,a[i].s);
    mmm(a,&m);
    printf("the highest: %s,%d\n",m.num,m.s);
    readwritedat();
    }
    void readwritedat()
    {
    FILE *rf,*wf;
    STU a[N],m;
    int i;
    rf=fopen("in.dat","r");
    wf=fopen("out.dat","w");
    for(i=0;i<10;i++)
    fscanf(rf,"%s,%d",a[i].num,&a[i].s);
    mmm(a,&m);
    fprintf(wf,"the top: %s,%d\n",m.num,m.s);
    fclose(rf);
    fclose(wf);
    }
    /* 注:較簡單。*/
    mmm(STU a[],STU *s)
    {
    int i;
    s->s=a[0].s;
    for(i=1;iif(a[i].s>s->s)
    *s=a[i];
    }