学生成绩管理系统C语言版

#include
#include
#include
#define MAX 10000
void add_student();
void edit_student();
void del_student();
void select_student_by_name();
void select_student_by_score();
void query_student();
void print_student();
void IO_write();
void IO_read();
void config_write();
void config_read();
//返回此学生学号对应的索引
int verify_sno();
typedef struct stu{
    char sno[40];//10大小
    char name[40];//20大小
    float math_score;//4
    float englist_score;//4
    long age;
    float avg_score;
}Stu;
char is_continue[0];
char sno[10];char  name[20];
float math_score,englist_score,avg_score;
int num=0;//学生数量
int res;
FILE * fp;
int main(){
    int choose_num;//选择方式
    Stu * student;
    student = (Stu *)malloc(10*(sizeof(Stu)));
    if(student==NULL){
        printf("动态分配内存失败\n");
    }
    if(num==0){//刚启动
        config_read();
    }
    while(1){
        printf("\n------ 学生成绩管理系统------\n");  
        printf("1. 增加学生记录\n");  
        printf("2. 修改学生记录\n");  
        printf("3. 删除学生记录\n");  
        printf("4. 显示所有学生信息\n");  
        printf("5. 按姓名查询学生记录\n");  
        printf("6. 按平均成绩排序\n");  
        printf("7. 退出\n");  
        printf("请选择(1-7):");
        scanf("%d",&choose_num);
        switch(choose_num){
            case 1://增加学生
                add_student(student);
                break;
            case 2://修改学生
                edit_student(student);
                break;
            case 3://删除学生记录
                del_student(student);
                break;
            case 4://显示所有学生信息
                query_student(student);
                break;
            case 5://按照学生姓名查询学生记录
                select_student_by_name(student);
                break;
            case 6://按照平均成绩查询学生记录
                select_student_by_score(student);
                break;
            default:
                exit(0);
                break;
        }
    }
}

void add_student(Stu * student){
    while(1){
        printf("请输入学生学号:");
        scanf("%s",sno);
        res = verify_sno(student);
        if(res != -1){
            printf("已经具有这个学号的学生了\n");
            printf("请重新输入\n");
            continue;
        }
        printf("请输入学生姓名:");
        scanf("%s",name);
        printf("请输入数学成绩:");
        scanf("%f",&math_score);
        printf("请输入英语成绩:");
        scanf("%f",&englist_score);
        memcpy(student[num].sno,sno,50);
        memcpy(student[num].name,name,50);
        student[num].math_score = math_score;
        student[num].englist_score = englist_score;
        student[num].avg_score = (math_score+englist_score)/2;
        num++;
        
        IO_write(student);
        printf("是否继续,请输入Y/N\n");
        scanf("%s",is_continue);
        getchar();//清除缓冲区中的欢迎符号
        if(strcmp(is_continue,"N")==0){
            break;
        }
    }
    
}

void query_student(Stu * student){
    while(1){
        IO_read(student);
        print_student(student);
        printf("是否继续,请输入Y/N\n");
        scanf("%s",is_continue);
        getchar();//清除缓冲区中的欢迎符号
        if(strcmp(is_continue,"N")==0){
            break;
        }
    }
}

void edit_student(Stu * student){
    while(1){
        int index;
        printf("输入要修改的学生的编号\n");
        scanf("%d",&index);
        if(index<1 || index>num){
            printf("输入的编号不存在\n");
            break;
        }
        printf("请输入学生学号:");
        scanf("%s",sno);
        res = verify_sno(student);
        if(res != -1){
            printf("已经具有这个学号的学生了\n");
            printf("请重新输入\n");
            continue;
        }
        printf("请输入学生姓名:");
        scanf("%s",name);
        printf("请输入数学成绩:");
        scanf("%f",&math_score);
        printf("请输入英语成绩:");
        scanf("%f",&englist_score);
        memcpy(student[index-1].sno,sno,50);
        memcpy(student[index-1].name,name,50);
        student[index-1].math_score = math_score;
        student[index-1].englist_score = englist_score;
        student[index-1].avg_score = (math_score+englist_score)/2;
        IO_write(student);
        printf("是否继续,请输入Y/N\n");
        scanf("%s",is_continue);
        getchar();//清除缓冲区中的欢迎符号
        if(strcmp(is_continue,"N")==0){
            break;
        }
        
    }
}

void del_student(Stu * student){
    IO_read(student);
    while(1){
        int i;
        int res;
        printf("输入要删除的学生的学号\n");
        scanf("%s",sno);
        res = verify_sno(student);
        if(res==-1){
            printf("没有此学生\n");
            printf("请重新输入\n");
            continue;
        }
        if((res+1)==num){//删除的学生是最后一位
            num--;
            IO_write(student);
        }else{//不是最后一位
            num--;
            for(i=res;i=student[j+1].avg_score){
                    memcpy(sno,student[j].sno,50);
                    memcpy(name,student[j].name,50);
                    math_score = student[j].math_score;
                    englist_score = student[j].englist_score;
                    avg_score = student[j].avg_score;
                    
                    
                    memcpy(student[j].sno,student[j+1].sno,50);
                    memcpy(student[j].name,student[j+1].name,50);
                    student[j].math_score = student[j+1].math_score;
                    student[j].englist_score = student[j+1].englist_score;
                    student[j].avg_score = student[j+1].avg_score;
                    
                    
                    memcpy(student[j+1].sno,sno,50);
                    memcpy(student[j+1].name,name,50);
                    student[j+1].math_score = math_score;
                    student[j+1].englist_score = englist_score;
                    student[j+1].avg_score = avg_score;
                }
            }
        }
        printf("    编号      学生学号        学生姓名       数学成绩       英语成绩\n");
        for(i=0;i

你可能感兴趣的:(学生成绩管理系统C语言版)