⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 char13.9.c

📁 c语言版的学生成绩管理系统
💻 C
字号:
#include<stdio.h>struct student{    char number[3];    char name[10];    int score[3];    float avrg;}std[10];void sort(){    int i;    int k;    int j;    struct student temp;    for(i=0;i<3;i++){        k=i;        for(j=i+1;j<3;j++){            if(std[k].avrg>std[j].avrg)                k=j;        }        if(k!=i){            temp=std[i];            std[i]=std[k];            std[k]=temp;        }    }}void store(int n){    FILE  *file;    file=fopen("stud","wb");    if(file==NULL)        printf("can't open file in the store");    int i;    for(i=0;i<n;i++)        fwrite(&std[i],sizeof(struct student),1,file);    fclose(file);}void read(int n){    int i;    FILE *file;    file=fopen("stud","rb");    if(file==NULL)        printf("can't open file in read\n");    for(i=0;i<n;i++)        fread(&std[i],sizeof(struct student),1,file);    fclose(file);}void pnt(int n){    int i;    int j;    for(i=0;i<n;i++){        printf("%s  %s  ",std[i].number,std[i].name);        for(j=0;j<3;j++)            printf("%d  ",std[i].score[j]);    }}main(){    int i;    int j;    float sum;    printf("please enter 3 students data\n");    for(i=0;i<3;i++){        sum=0;        scanf("%s%s",std[i].number,std[i].name);        for(j=0;j<3;j++){            scanf("%d",&std[i].score[j]);            sum+=std[i].score[j];         }        std[i].avrg=sum/3.0;    }    sort();        store(3);    printf("NO. Name Score1 Score2 Score3\n");    pnt(3);       struct student temp;    printf("please enter the new student data\n");    scanf("%s%s",temp.number,temp.name);    scanf("%d%d%d",&temp.score[0],&temp.score[1],&temp.score[2]);    temp.avrg=(temp.score[0]+temp.score[1],temp.score[2])/3.0;      read(3);    int flag=0;    FILE *file;    file=fopen("new_std","rb");    if(file==NULL){        printf("can't open file when insert new node\n");        exit(0);    }    for(i=0;i<3;i++){        if(temp.avrg<std[i].avrg&&flag==0){            fwrite(&temp,sizeof(struct student),1,file);            flag=1;            i-=1;            continue;        }        fwrite(&std[i],sizeof(struct student),1,file);    }    fclose(file);        file=fopen("new_std","rb");    if(file==NULL){        printf("can't read from new_std\n");        exit(0);    }        printf("NO. Name Score1 Score2 Score3\n");    pnt(4);    fclose(file);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -