利用C语言实现学生成绩管理系统

利用C语言实现学生成绩管理系统

学完了C ,要及时学以致用,将学到的知识点加以运用。下面是我在学完C后写的小项目:学生成绩管理系统。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_STUDENT_SUM 100
int student_sum=0;

//学生成绩管理系统 包含的成员
struct student{
    char name[1024];
    char c1ass[1024];
    int chinese;
    int Math;
    int English;
    } ;
struct student *student_arry=NULL;//定义一个结构体 指针
//加入已有的学生信息
void student_join()
{
    printf("请输入加入已有的学生个数:\n");
    scanf("%d",&student_sum);
    
    printf("加入已有的学生信息\n格式:姓名\t班级\t语文成绩\t数学成绩\t英语成绩\n");
    for(int i=0;i < student_sum;i++)
    {
        scanf("%s",student_arry[i] .name);
        scanf("%s",student_arry[i] .c1ass);
        scanf("%d%d%d",&student_arry[i] .chinese,&student_arry[i] .Math,&student_arry[i] .English);     
    }    
  
    return ;  
}
//显示学生信息
void student_play()
{
    printf("显示已有的学生信息\n格式:姓名\t班级\t语文成绩\t数学成绩\t英语成绩\n");
    for(int i=0;i < student_sum;i++)
    {
        printf("%s\t%s\t%d\t%d\t%d\n",student_arry[i].name,student_arry[i].c1ass,student_arry[i] .chinese,student_arry[i] .Math,student_arry[i] .English); 
        printf("\n");
    }
    return ;
}
//增加
void student_add()
{
    printf("请输入需要增加的学生的个数\n");
    int sum=0;
    scanf("%d",&sum);
    printf("请输入需要增加的学生的信息\n格式:姓名\t班级\t语文成绩\t数学成绩\t英语成绩\n");
    student_sum+=sum;
    for(int i=student_sum-sum;i < student_sum;i++)
    {
        scanf("%s",student_arry[i] .name);
        scanf("%s",student_arry[i] .c1ass);
        scanf("%d%d%d",&student_arry[i] .chinese,&student_arry[i] .Math,&student_arry[i] .English);           
    }
    return ;
}
//删除
void student_del(char *name)
{
    for(int i=0;i<student_sum;i++)
    {
        if(strcmp(student_arry[i] .name,name)==0)
        {
            strcpy(student_arry[i] .name,"0");
            strcpy(student_arry[i] .c1ass,"0");
            student_arry[i] .chinese=0;
            student_arry[i] .Math=0;
            student_arry[i] .English=0;
            for(int j=i;j<student_sum;j++)
            {
                strcpy(student_arry[j] .name,student_arry[j+1] .name);
                strcpy(student_arry[j] .c1ass,student_arry[j+1] .c1ass);
                student_arry[j] .chinese=student_arry[j+1] .chinese;
                student_arry[j] .Math=student_arry[j+1] .Math;
                student_arry[j] .English=student_arry[j+1] .English;
                
            }
            student_sum--;
            return ;
        }
    }
}
//改
void student_change(char *name1)
{
    for(int i=0;i<student_sum;i++)
    {
        if(strcmp(student_arry[i] .name,name1)==0)
        {
            scanf("%s",student_arry[i] .c1ass);
            scanf("%d%d%d",&student_arry[i] .chinese,&student_arry[i] .Math,&student_arry[i] .English); 
            return ;
        }
    }   
}
//查
void student_check(char *name1)
{
    for(int i=0;i<student_sum;i++)
    {
        if(strcmp(student_arry[i] .name,name1)==0)
        {

            printf("要查找的学生的信息:\n%s\t%s\t%d\t%d\t%d\n",student_arry[i].name,student_arry[i].c1ass,student_arry[i] .chinese,student_arry[i] .Math,student_arry[i] .English); 
            printf("\n");
            return ;
        }
    }
    printf("查无此学生!\n");   
}

//按语文成绩排序
void student_sort_Chinese()
{
    for(int i=0;i<student_sum;i++)
    {
        for(int j=0;j<student_sum;j++)
        {
            if(student_arry[i] .chinese > student_arry[j] .chinese)
            {
                char str[1024];
                strcpy(str,student_arry[j] .name);
                strcpy(student_arry[j] .name,student_arry[i] .name);
                strcpy(student_arry[i] .name,str);

                char str1[1024];
                strcpy(str1,student_arry[j] .c1ass);
                strcpy(student_arry[j] .c1ass,student_arry[i] .c1ass);
                strcpy(student_arry[i] .c1ass,str1);
                int tmp;
                tmp=student_arry[j] .chinese;
                student_arry[j] .chinese=student_arry[i] .chinese;
                student_arry[i] .chinese=tmp;

                tmp=student_arry[j] .Math;
                student_arry[j] .Math=student_arry[i] .Math;
                student_arry[i] .Math=tmp;

                                tmp=student_arry[j] .English;
                student_arry[j] .English=student_arry[i] .English;
                student_arry[i] .English=tmp;
            }
        }
    }
    return ;
}
//按数学成绩排序
void student_sort_Math()
{
    for(int i=0;i<student_sum;i++)
    {
        for(int j=0;j<student_sum;j++)
        {
            if(student_arry[i] .Math > student_arry[j] .Math)
            {
                char str[1024];
                strcpy(str,student_arry[j] .name);
                strcpy(student_arry[j] .name,student_arry[i] .name);
                strcpy(student_arry[i] .name,str);

                char str1[1024];
                strcpy(str1,student_arry[j] .c1ass);
                strcpy(student_arry[j] .c1ass,student_arry[i] .c1ass);
                strcpy(student_arry[i] .c1ass,str1);
                int tmp;
                tmp=student_arry[j] .chinese;
                student_arry[j] .chinese=student_arry[i] .chinese;
                student_arry[i] .chinese=tmp;

                tmp=student_arry[j] .Math;
                student_arry[j] .Math=student_arry[i] .Math;
                student_arry[i] .Math=tmp;

                                tmp=student_arry[j] .English;
                student_arry[j] .English=student_arry[i] .English;
                student_arry[i] .English=tmp;
            }
        }
    }
    return ;
}
//按英语成绩排序
void student_sort_English()
{
    for(int i=0;i<student_sum;i++)
    {
        for(int j=0;j<student_sum;j++)
        {
            if(student_arry[i] .English > student_arry[j] .English)
            {
                char str[1024];
                strcpy(str,student_arry[j] .name);
                strcpy(student_arry[j] .name,student_arry[i] .name);
                strcpy(student_arry[i] .name,str);

                char str1[1024];
                strcpy(str1,student_arry[j] .c1ass);
                strcpy(student_arry[j] .c1ass,student_arry[i] .c1ass);
                strcpy(student_arry[i] .c1ass,str1);
                int tmp;
                tmp=student_arry[j] .chinese;
                student_arry[j] .chinese=student_arry[i] .chinese;
                student_arry[i] .chinese=tmp;

                tmp=student_arry[j] .Math;
                student_arry[j] .Math=student_arry[i] .Math;
                student_arry[i] .Math=tmp;

                                tmp=student_arry[j] .English;
                student_arry[j] .English=student_arry[i] .English;
                student_arry[i] .English=tmp;
            }
        }
    }
    return ;
}
//选择排序的标志
void student_sort()
{
    int i;
    while(1)
    {
    printf("请输入要排序的标志:\n-0-语文成绩\n-1-数学成绩\n-2-英语成绩\n-3-退出成绩排序\n");
    scanf("%d",&i);
    switch(i)
    {
        case 0:
        {
            student_sort_Chinese();
            
            break;
        }
        case 1:
        {
            student_sort_Math();
            
            break;
        }
        case 2:
        {
            student_sort_English();
            
            break;
        }
        case 3:
        {
            return ;
        }
        default:
        {
            printf("输入错误!\n");
            break;
        }
    }
    }
}
int main()
{
    student_arry=(struct student *)malloc(sizeof(struct student));
    student_join();
while(1)
{
    printf("-0-用来显示所有学生信息\n");
    printf("-1-用来添加学生信息\n");
    printf("-2-用来查询学生信息\n");
    printf("-3-用来修改学生信息\n");
    printf("-4-用来删除学生信息\n");
    printf("-5-用来学生成绩排序\n");
    printf("-6-退出程序、\n");
    printf("请输入要操作的功能的代号  <0~4>  :\n");
    printf("————————————————————————————————————————————————————————————\n");
    int tmp;
    scanf("%d",&tmp);
    switch(tmp)
    {
        case 0:
        {
            student_play();
            break;
        }
        case 1:
        {
            student_add();
            break;
        }
        case 2:
        {
            printf("请输入要查找的学生的姓名:\n");
            char name2[1024];
            scanf("%s",name2);
            student_check(name2); 
            break;          
        }
        case 3:
        {
            printf("请输入要修改的学生的姓名及修改后的信息:\n");
            char name1[1024];
            scanf("%s",name1);
            student_change(name1);
            break;            
        }
        case 4:
        {
            printf("请输入要删除的学生的姓名及修改后的信息:\n");
            char name[1024];
            scanf("%s",name);
            student_del(name);
            break;            
        }
        case 5:
        {
            student_sort();
            break;
            return 0;
        }
        case 6:
        {

            return 0;
        }
        default:
        {
            printf("输入错误!");
            break;
        }
    }
}}

运行结果:

运行结果

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

NOREAD

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值