标题:学生信息管理系统
只看楼主
无意with
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2020-12-23
 问题点数:0 回复次数:1 
学生信息管理系统
学生包含以下信息项:学号、姓名、学院、班级、高数成绩、英语成绩、C语言成绩、总分、平均分。系统的主要功能包括:1. 创建学生成绩信息文件,根据提示输入学生的各项信息,计算出总分和平均分,然后将学生成绩信息存储到一个二进制文件中。2. 增加学生信息,在原有学生信息文件的基础上增加新的学生成绩信息,要求继续保存至原文件,并提示用户选择是否继续进行增加操作。3. 删除学生信息,提示用户输入要进行删除操作的学号,如果在文件中有该信息存在,则将该学号所对应的学生信息删除,否则输出提示信息,并提示用户选择是否继续进行删除操作。4. 修改学生信息,提示用户输入要进行修改操作的学号,如果在文件中有该息存在,则将提示用户输入该学号对应的要修改的选项,结果保存至原文件,并提示用户选择是否继续进行修改操作。5. 按不同条件对学生信息进行查询操作,输出满足条件的学生信息。(1) 按学号查询,输入学号。(2) 按姓名查询,输入全名。


可以不使用链表吗?

#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
#include <string.h>
#define len sizeof(struct stu)
#define lrj "-----------------------------------------------------------------------------\n"
#define djy "------------------------------------------\n"
void menu();
void chuangjian();
void write(struct stu *head);
void write2(struct stu *head);
struct stu *creat(void);
int xuanze(int num);
void zengjia();
void shifang(struct stu *head);
void chakan();
void shanchu();
void xiugai();
void xiu(double c,struct stu *head,FILE *fp);
void cheek();
void tongji();
void chakan();
void ji1(struct stu *head,FILE *fp);
void ji2(struct stu *head,FILE *fp);
void ji3(struct stu *head,FILE *fp);
int s;
int u=0;
struct stu
{
    double num;
    char name[100];
    char xueyuan[100];
    char banji[100];
    int math;
    int English;
    int C;
    int he;
    double ave;
    struct stu *next;
};
void menu()//开头
{
    printf("\n\n\n\n\n\n\t\n\n\n\t\t亲爱的同学:欢迎使用学生成绩管理系统!");
    getch();
    system("cls");
    return;
}
int main()//主选择界面
{
搜索更多相关主题的帖子: void 学生 stu int struct 
2020-12-23 16:11
无意with
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2020-12-23
得分:0 
#include<stdio.h>
#include<conio.h>
#include <stdlib.h>
#include <string.h>
#define len sizeof(struct stu)
#define lrj "-----------------------------------------------------------------------------\n"
#define djy "------------------------------------------\n"
void menu();
void chuangjian();
void write(struct stu *head);
void write2(struct stu *head);
struct stu *creat(void);
int xuanze(int num);
void zengjia();
void shifang(struct stu *head);
void chakan();
void shanchu();
void xiugai();
void xiu(double c,struct stu *head,FILE *fp);
void cheek();
void tongji();
void chakan();
void ji1(struct stu *head,FILE *fp);
void ji2(struct stu *head,FILE *fp);
void ji3(struct stu *head,FILE *fp);
int s;
int u=0;
struct stu
{
    double num;
    char name[100];
    char xueyuan[100];
    char banji[100];
    int math;
    int English;
    int C;
    int he;
    double ave;
    struct stu *next;
};
void menu()//开头
{
    printf("\n\n\n\n\n\n\t\n\n\n\t\t亲爱的同学:欢迎使用学生成绩管理系统!");
    getch();
    system("cls");
    return;
}
int main()//主选择界面
{

    int num,z,l;
    int ch;
    if(u==0)
    {
    menu();
    u=1;
    }
    printf("\n\t\t\t\t【     学生成绩管理系统    】\n");//菜单
    printf("\t*****************************************************************************\n\n");
    printf("\t【--------------- 1.创建学生成绩信息文件       2.增加学生信息 -------------】\n\n");
    printf("\t【--------------- 3.删除学生信息               4.修改学生信息--------------】\n\n");
    printf("\t【--------------- 5.查询学生信息               6.统计学生成绩   -----------】\n\n");
    printf("\t【--------------- 7.查看所有学生信息           8.退出       ---------------】\n\n");
    printf("\t*****************************************************************************\n\n");
    printf("请根据需要选择相应的序号:");
    scanf("%d",&ch);
     switch(ch)
    {
    case 1:    chuangjian();break;
    case 2 :  zengjia();break;
    case 3 :  shanchu();break;
    case 4 :  xiugai();break;
    case 5 :   cheek();break;   
    case 6 :   tongji();break;
    case 7 :   chakan();break;
    case 8 :
    {printf("\n\n\t\t程序已退出!\n\n");exit(0);}
    default :   
    {
    printf("\n\t选项错误,请正确输入数字\n");
    getch();
    system("cls");
    main();
    exit(0);
    }
    }
}
void chuangjian()//创建学生信息
{
    struct stu *head;
    system("cls");
    printf("请确定您要输入学生的人数:");
    scanf("%d",&s);
    printf("请输入第1个学生的信息\n");
    head=creat();
    write(head);
    printf("按回车返回主菜单");
    system("cls");
    main();
    exit(0);
}


struct stu *creat(void)//链表输入
{
    int he,i;
    double ave;
    struct stu *p1,*p2;
    struct stu *head=NULL;
    p1=p2=(struct stu*)malloc(len);
    printf("请输入该学生的学号:");scanf("%lf",&p1->num);
    printf("请输入该学生的姓名:");scanf("%s",p1->name);
    printf("请输入该学生的学院:");scanf("%s",p1->xueyuan);
    printf("请输入该学生的班级:");scanf("%s",p1->banji);
    printf("请输入该学生的高数成绩:");scanf("%d",&p1->math);
    printf("请输入该学生的英语成绩:");scanf("%d",&p1->English);
    printf("请输入该学生的C语言成绩:");scanf("%d",&p1->C);
        he=(p1->math)+(p1->English)+(p1->C);
       p1->he=he;
        ave=(he)/3.0;
        p1->ave=ave;
    head=p1;
    i=2;
    for(s;s>1;s--)
    {
        printf("请输入第%d个学生的信息\n\n",i);      
        p1=(struct stu*)malloc(len);
        printf("请输入该学生的学号:");
        scanf("%lf",&p1->num);
        printf("请输入该学生的姓名:");
        scanf("%s",p1->name);
        printf("请输入该学生的学院:");
        scanf("%s",p1->xueyuan);
        printf("请输入该学生的班级:");
        scanf("%s",p1->banji);
        printf("请输入该学生的高数成绩:");
        scanf("%d",&p1->math);
        printf("请输入该学生的英语成绩:");
        scanf("%d",&p1->English);
        printf("请输入该学生的C语言成绩:");
        scanf("%d",&p1->C);
    he=(p1->math)+(p1->English)+(p1->C);
    p1->he=he;
    ave=he/3.0;
    p1->ave=ave;p2->next=p1;
    p2=p1;
    i++;
    }
    p2->next=NULL;
    return head;
}

void write2(struct stu *head)//用以增加信息的输入
{
    struct stu *pp;
        FILE *fp=NULL;
    pp=head;
    int i;
    fp=fopen("D:\\student.dat","ab");//打开文件并使文件指针指向它
    if(fp==NULL)
    {
        printf("\n\t文件没有打开!程序结束!");
        getchar();
        exit(0);
    }
    else
    {
        pp=head;
        while(pp!=NULL)
        {
            fwrite(pp,sizeof(stu),1,fp);
            pp=pp->next;
        }
    }
    printf("\n已增加新的学生成绩信息\n\n");
    getch();
    fclose(fp);
    return;
}



void write(struct stu *head)//用以创建信息的输入
{
    struct stu *pp;
    pp=head;
    int i;
    FILE *fp = NULL;
    fp=fopen("D:\\student.dat","wb");//打开文件并使文件指针指向它
    if(fp==NULL)
    {
        printf("\n\t文件没有打开!程序结束!");
        getchar();
        exit(0);
    }
    else
    {
        pp=head;
        while(pp!=NULL)
        {
            fwrite(pp,sizeof(stu),1,fp);
            pp=pp->next;
        }
        
    }
    printf("\n\n信息已保存\n\n");
    fclose(fp);
    shifang(head);
    getch();
    return;
}


void zengjia()//学生信息的增加
{
    char c='\0';
    s=0;
    system("cls");
    struct stu *p,*head,*p2;
    FILE *fp=NULL;
    fp=fopen("D:\\student.dat","rb+");
    if(fp==NULL)
    {
        printf("\n\t找不到该文件!");
        getchar();
        exit(0);
    }
    else
    {
    p=(struct stu*)malloc(len);
    fread(p,sizeof(stu),1,fp);
    p2=p;
    while(!feof(fp))
    {
    p=(struct stu*)malloc(len);
    fread(p,sizeof(stu),1,fp);
    }
    fclose(fp);
    printf(lrj);
    head=creat();
    printf(lrj);
    write2(head);
    while(1)
    {
        c=getchar();
        if(c=='Y')
        {
            shifang(head);
            zengjia();
            exit(0);
        }
        else if(c=='N')
        {
            shifang(head);
            main();
            exit(0);
        }
    printf(lrj);
    printf("请问是否继续添加(Y or N)\n");
    printf(lrj);
    }
    }
}


void shanchu()//学生信息的删除
{
    int i=0;
    system("cls");
    double c;
    struct stu *p,*head,*p2,*p3,*p4,*p5;
    FILE *fp=NULL;
    printf(lrj);
    printf("请输入删除的学号:");
    scanf("%lf",&c);
    printf(lrj);
    printf("\n\n");
    fp=fopen("D:\\student.dat","rb");
    if(fp==NULL)
    {
        printf("\n\t文件没有打开!程序结束!");
        getchar();
        exit(0);
    }
    else
    {
        p=(struct stu*)malloc(len);
        fread(p,sizeof(stu),1,fp);
        p2=p;
        head=p;
        while(!feof(fp))
        {   
        p2=p;
        p=(struct stu*)malloc(len);
        fread(p,sizeof(stu),1,fp);
        p2->next=p;
        }
    }
    p2->next=NULL;
    p5=head;
    p4=p5;
    while(p5!=NULL)
    {
        if(c==p5->num)
        {
            i=1;
            if(head==p5)
            {
                head=p5->next;
                head=p5->next;
                free(p5);
            }
            else if(p5->next==NULL)
            {
                free(p5);
                p4->next=NULL;
            }
            else if(head!=p5&&p5->next!=NULL)
            {
                p3=p5->next;
                free(p5);
                p4->next=p3;
            }
        }
        if(p5==NULL)
        break;
        p4=p5;
        p5=p5->next;
    }
    if(i==0)
    {
        printf("\n没有找到该条学生信息,\n");
    }
    struct stu *pp;
    fp=fopen("D:\\student.dat","wb");
    if(fp==NULL)
    {
        printf("\n\t文件没有打开!程序结束!");
        getchar();
        exit(0);
    }
    else
    {
        pp=head;
        while(pp!=NULL)
        {
            fwrite(pp,sizeof(stu),1,fp);
            pp=pp->next;
        }
    }
    fclose(fp);
    printf("\n\t\t删除成功!\n\n\n");
    while(1)
        {
        c=getchar();
        if(c=='Y')
        {
        shifang(head);
        shanchu();
           exit(0);
        }
        else if(c=='N')
        {
        shifang(head);
        main();
        exit(0);
        }
        printf(lrj);
        printf("是否继续进行删除(Y or N)\n");
        printf(lrj);
        }
}
void xiugai()//修改信息函数
{
    int i=0;
    char ch;
    system("cls");
    double c;
    struct stu *p,*head,*p2,*head2,*pp;
    FILE *fp=NULL,*ftp=NULL;
    printf("请输入要修改的学生的学号:");
    scanf("%lf",&c);
    fp=fopen("D:\\student.dat","rb+");
    if(fp==NULL)
    {
        printf("\n\t文件没有打开!程序结束!");
        getchar();
        exit(0);
    }
    else
    {
        p=(struct stu*)malloc(len);
        fread(p,sizeof(stu),1,fp);
        p2=p;
        head=p;
        while(!feof(fp))
        {   
        p2=p;
        p=(struct stu*)malloc(len);
        fread(p,sizeof(stu),1,fp);
        p2->next=p;
        }
    }
    p2->next=NULL;
    pp=head;
    while(pp!=NULL)
    {
    if(c==(pp->num))
    {
        i=1;
        xiu(c,head,fp);
        break;
    }
    pp=pp->next;
    }
    if(i==0)
    {
    printf("\n\n没有找到该条成绩信息。\n\n");
        fclose(fp);
        while(1)
        {
        ch=getchar();
        if(ch=='Y')
        {
        shifang(head);
        xiugai();
         exit(0);
        }
        else if(ch=='N')
        {
        shifang(head);
        main();
         exit(0);
        }
        printf(lrj);
        printf("是否继续修改操作(Y or N)\n");
        printf(lrj);
        }
    }
}


void xiu(double c,struct stu *head,FILE *fp)//用于判断修改条件的函数
{
    int ch,i=0;
    int he;
    double ave;
    struct stu *p,*pp;
    p=head;
    i=0;
    while(p!=NULL)
    {
        if(c==(p->num))
        {
            printf(lrj);
            printf("\t\t请选择要进行的操作:\n");
            printf(lrj);
            printf("1.学号:\n\n");
            printf("2.姓名:\n\n");
            printf("3.学院:\n\n");
            printf("4.班级:\n\n");
            printf("5.高数成绩:\n\n");
            printf("6.英语成绩:\n\n");
            printf("7.C语言成绩:\n\n");
            printf("8.返回上一级:\n\n");
            printf("0.返回主菜单:\n\n");
            printf(lrj);
            printf("请选择修改的选项:");
            scanf("%d",&ch);
            if(ch==1)
            {
                system("cls");
                printf("原学号为:%.0lf\n\n",p->num);
                printf("请输入修改的学号:");
                scanf("%lf",&p->num);
                printf("\n修改成功!\n");
            }
            else if(ch==2)
            {
                system("cls");
                printf("原姓名为:%s\n\n",p->name);
                printf("请输入修改的姓名:");
                scanf("%s",p->name);
                printf("\n修改成功!\n");
            }
            else if(ch==3)
            {
                system("cls");
                printf("原学院为:%s\n\n",p->xueyuan);
                printf("请输入修改的学院:");
                scanf("%s",p->xueyuan);
                printf("\n修改成功!\n");
            }
            else if(ch==4)
            {
                system("cls");
                printf("原班级为:%s\n\n",p->banji );
                printf("请输入修改的班级:");
                scanf("%s",p->banji);
                printf("\n修改成功!\n");
            }
            else if(ch==5)
            {
                system("cls");
                printf("原高数成绩为:%d\n\n",p->math);
                printf("请输入修改的高数成绩:");
                scanf("%d",&p->math);
                printf("\n修改成功!\n");
            }
            else if(ch==6)
            {
                system("cls");
                printf("原英语成绩为:%d\n\n",p->English);
                printf("请输入修改的英语成绩:");
                scanf("%d",&p->English);
                printf("\n修改成功!\n");
            }
            else if(ch==7)
            {
                system("cls");
                printf("原C语言成绩为:%d\n\n",p->C);
                printf("请输入修改的C语言成绩:");
                scanf("%d",&p->C);
                printf("\n修改成功!\n");
            }
            else if(ch==0)
            {
            shifang(head);
            fclose(fp);
            main();
            exit(0);
            }
            else if(ch==8)
            {
            shifang(head);
            fclose(fp);  
            xiugai();
            exit(0);
            }
        he=(p->math)+(p->English)+(p->C);
        p->he=he;
        ave=(he)/3.0;
        p->ave=ave;
        }
    p=p->next;
    }
    fp=fopen("D:\\student.dat","wb");
    if(fp==NULL)
    {
        printf("\n\t文件没有打开!程序结束!");
        getchar();
        exit(0);
    }
    else
    {
        pp=head;
        while(pp!=NULL)
        {
            fwrite(pp,sizeof(stu),1,fp);
            pp=pp->next;
        }
    }
    fclose(fp);
    shifang(head);
        while(1)
        {
            ch=getchar();
            if(ch=='Y')
            {
            xiugai();
            break;
            }
            else if(ch=='N')
            {
            main();
            break;
            }
            printf(lrj);
            printf("是否继续进行修改(Y or N)\n");
            printf(lrj);
        }
    }

void cheek()//查询学生信息函数
{
    system("cls");
    char ch;
    int e,a;
    struct stu *p,*head,*p2,*pp;
    FILE *fp=NULL;
    double c;
    char n[100];
    fp=fopen("D:\\student.dat","rb+");
    printf(lrj);
    printf("请选择查询条件:\n");
    printf(lrj);
    printf("\n");
    printf("1.按学号查询\n\n");
    printf("2.按姓名查询\n\n");
    printf("0.返回主界面\n\n");
    printf(lrj);
    printf("请输入:");
    scanf("%d",&a);
    p=(struct stu*)malloc(len);//读取并建立链表
    fread(p,sizeof(stu),1,fp);
    p2=p;
    head=p;
    while(!feof(fp))
    {   
        p2=p;
        p=(struct stu*)malloc(len);
        fread(p,sizeof(stu),1,fp);
        p2->next=p;
    }
    if(a==1)
    {
        system("cls");
        printf("请输入学号:");
        scanf("%lf",&c);
        pp=head;
        while(pp!=NULL)
        {
            if(c==pp->num)
            {
                e=1;
                printf(djy);
                printf("学号:%.0lf    姓名:%s    学院:%s    班级:%s\n",pp->num,pp->name ,pp->xueyuan ,pp->banji);
                printf("高数成绩:%d\n英语成绩:%d\nC语言成绩:%d\n总分:%d\n平均分:%.2lf\n",pp->math ,pp->English ,pp->C ,pp->he,pp->ave );
            }
            pp=pp->next;
        }
        if(e==0)
        {
            printf("没有此学生的成绩信息。\n");
        }
        shifang(head);
        fclose(fp);
        while(1)
        {
            ch=getchar();
            if(ch=='Y')
        {
            cheek();
            exit(0);
        }
            else if(ch=='N')
        {
            cheek();
            exit(0);
        }
            printf(lrj);
            printf("是否继续进行查询(Y or N)\n");
            printf(lrj);
        }
    }
    else if(a==2)
    {
        pp=head;
        system("cls");
        printf("请输入姓名:");
        scanf("%s",&n);
        while(pp!=NULL)
        {
            if((strcmp(n,pp->name))==0)
            {
                e=1;
                printf("******************************************\n");
                printf("学号:%.0lf    姓名:%s    学院:%s    班级:%s\n",pp->num,pp->name ,pp->xueyuan ,pp->banji);
                printf("高数成绩:%d\n英语成绩:%d\nC语言成绩:%d\n总分:%d\n平均分:%.2lf\n",pp->math ,pp->English ,pp->C ,pp->he,pp->ave );
            }
            pp=pp->next;
        }
        if(e==0)
        {   
            printf("*************************************************\n");
            printf("没有此学生的成绩信息。\n");
        }
        shifang(head);
        fclose(fp);
        while(1)
        {   
            ch=getchar();
            if(ch=='Y')
        {
            cheek();
            exit(0);
        }
            else if(ch=='N')
        {
          main();
            exit(0);
        }
            printf(lrj);
            printf("是否继续进行查询(Y or N)\n");
            printf(lrj);
        }
        }
        else if(a==0)
        {
        shifang(head);
        fclose(fp);
        main();
        exit(0);
        }
        else
        {
        shifang(head);
        printf("\t\t输入错误");
        cheek();
        exit(0);
        }
}
void tongji()//统计的选择界面
{
    system("cls");
    int a=0,b=0,c=0,d=0,e=0;
    struct stu *p,*head,*p2;
    FILE *fp=NULL;
    int t;
    fp=fopen("D:\\student.dat","rb+");
    printf(lrj);
    printf("\n");
    printf("1.各分数段的人数\n\n");
    printf("2.各科最高分数的学生\n\n");
    printf("3.各科不及格率\n\n");
    printf("0.返回主界面\n\n");
    printf(lrj);
    printf("请选择选项:");
    scanf("%d",&t);
    p=(struct stu*)malloc(len);//读取并建立链表
    fread(p,sizeof(stu),1,fp);
   
    p2=p;
    head=p;
    while(!feof(fp))
    {   
        p2=p;
        p=(struct stu*)malloc(len);
        fread(p,sizeof(stu),1,fp);
        p2->next=p;
    }
    fclose(fp);
    if(t==1)
    {
        ji1(head,fp);
    }
    if(t==2)
    {
        ji2(head,fp);
    }
    if(t==3)
    {
        ji3(head,fp);
    }
    if(t==0)
    {
    shifang(head);
    main();
    exit(0);
    }
    else
    {
        shifang(head);
        printf("\t\t输入错误");
        tongji();
        exit(0);
    }
}


void ji1(struct stu *head,FILE *fp)//第一个统计
{
    system("cls");
    struct stu *pp;
    int a=0,b=0,c=0,d=0,e=0;
    pp=head;
    while(pp!=NULL)
    {
    if(pp->ave>=90&&pp->ave<=100)
    {
        a++;
    }
    else if(pp->ave>=80&&pp->ave<=89)
    {
        b++;
    }
    else if(pp->ave>=70&&pp->ave<=79)
    {
        c++;
    }
    else if(pp->ave>=60&&pp->ave<=69)
    {
        d++;
    }
    else if(pp->ave<=59)
    {
        e++;
    }
    pp=pp->next;
    }
    printf(lrj);
    printf("各分数段的人数分别为:");
    printf("\n");
    printf(lrj);
    printf("90-100的人数共有:%d人\n\n",a);
    printf("80-89的人数共有:%d人\n\n",b);
    printf("70-89的人数共有:%d人\n\n",c);
    printf("60-69的人数共有:%d人\n\n",d);
    printf("不及格的人数共有:%d人\n",e-1);
    printf(lrj);
    a=0;b=0;c=0;d=0;e=0;
    printf("\n\t\t按回车键返回上一界面\n");
    shifang(head);
    getchar();
    getchar();
    tongji();
    exit(0);
}


void ji2(struct stu *head,FILE *fp)//第二个统计
{
    system("cls");
    int m1,m2,m3;
    struct stu *pp,*pt1,*pt2,*pt3;
    int a=0,b=0,c=0,d=0,e=0;
    pp=head;
    m1=pp->math;
    m2=pp->English;
    m3=pp->C;
    pt1=pp;
    while(pp!=NULL)
    {
        if(m1<pp->math)
        {
        m1=pp->math;
        pt1=pp;
        }
        pp=pp->next;
    }
    pp=head;
    pt2=pp;
    while(pp!=NULL)
    {
        if(m2<pp->English)
        {
        m2=pp->English;
        pt2=pp;
        }
        pp=pp->next;
    }
    pp=head;
    pt3=pp;
    while(pp!=NULL)
    {
        if(m3<pp->C)
        {
        m3=pp->C;
        pt3=pp;
        }
        pp=pp->next;
    }
    printf(lrj);
    printf("高数最高分为:\n");
    printf(lrj);
    printf("学号:%.0lf    姓名:%s    学院:%s    班级:%s \n",pt1->num,pt1->name ,pt1->xueyuan ,pt1->banji);
    printf("高数成绩:%d\n英语成绩:%d\nC语言成绩:%d\n总分:%d\n平均分:%.2lf\n",pt1->math ,pt1->English ,pt1->C ,pt1->he,pt1->ave);
    printf(lrj);
    printf("英语最高分为:\n");
    printf(lrj);
    printf("学号:%.0lf    姓名:%s    学院:%s    班级:%s \n",pt2->num,pt2->name ,pt2->xueyuan ,pt2->banji);
    printf("高数成绩:%d\n英语成绩:%d\nC语言成绩:%d\n总分:%d\n平均分:%.2lf\n",pt2->math ,pt2->English ,pt2->C ,pt2->he,pt2->ave);
    printf(lrj);
    printf("C语言最高分为:\n");
    printf(lrj);
    printf("学号:%.0lf    姓名:%s    学院:%s    班级:%s \n",pt3->num,pt3->name ,pt3->xueyuan ,pt3->banji);
    printf("高数成绩:%d\n英语成绩:%d\nC语言成绩:%d\n总分:%d\n平均分:%.2lf\n",pt3->math ,pt3->English ,pt3->C ,pt3->he,pt3->ave);
    printf(lrj);
    printf("\n\t\t按回车键返回上一界面\n");
    getchar();
    getchar();
    shifang(head);
    tongji();
    exit(0);
}


void ji3(struct stu *head,FILE *fp)//第三个统计
{
    struct stu *pp;
    double a=0,b=0,c=0,d=0,n1,n2,n3;
    system("cls");
    pp=head;
    while(pp!=NULL)
    {
    if(pp->math<=59)
    {
        a++;
    }
    pp=pp->next;
    }
    pp=head;
    while(pp!=NULL)
    {
    if(pp->English<=59)
    {
        b++;
    }
    pp=pp->next;
    }
    pp=head;
    while(pp!=NULL)
    {
    if(pp->C<=59)
    {
        c++;
    }
    pp=pp->next;
    }
    pp=head;
    while(pp!=NULL)
    {
        d++;
        pp=pp->next;
    }
    n1=(a-1)/(d-1)*100;
    n2=(b-1)/(d-1)*100;
    n3=(c-1)/(d-1)*100;
    printf(djy);
    printf("\n");
    printf("三门课的不及格率分别为:");
    printf("\n\n");
    printf(djy);
    printf("高数的不及格率为:%.1lf %%\n",n1);
    printf("英语的不及格率为:%.1lf %%\n",n2);
    printf("C语言的不及格率为:%.1lf %%\n",n3);
    printf(lrj);
    printf("\n\t\t按回车键返回上一界面\n");
    shifang(head);
    getchar();
    getchar();
    tongji();
    exit(0);
}


void shifang(struct stu *head)//用于释放链表节点的函数
{
    struct stu *p,*c;
    p=head;
    c=p;
    while(c!=NULL)
    {
    p=c;
    c=c->next;
    free(p);
    }
}

void chakan()//查看所有信息
{
    system("cls");
    struct stu *pp,*head;
    FILE *fp=NULL;
    fp=fopen("D:\\student.dat","rb+");
    if(fp==NULL)
    {
        printf("\n\t文件没有打开!程序结束!");
        getchar();
        getchar();
        main();
        exit(0);
    }
    else
    {
    pp=(struct stu*)malloc(len);
    fread(pp,sizeof(stu),1,fp);
    while(!feof(fp))
    {
    printf(lrj);
    printf("学号:%.0lf    姓名:%s    学院:%s    班级:%s\n",pp->num,pp->name ,pp->xueyuan ,pp->banji);
    printf("高数成绩:%d\n英语成绩:%d\nC语言成绩:%d\n总分:%d\n平均分:%.2lf\n",pp->math ,pp->English ,pp->C ,pp->he,pp->ave );
    pp=(struct stu*)malloc(len);
    fread(pp,sizeof(stu),1,fp);
    }
    printf(lrj);
    printf("\n按回车键返回\n");
    getchar();
    getchar();
    main();
    exit(0);
}
}


2020-12-23 16:11



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-504357-1-1.html




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

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