学生成绩管理系统及源代码实现

  

由于系统功能比较大,实现代码量比较多,故只上传部分源代码,仅供参考!如有需要全部代码以及功能详解,请邮件:[email protected]。系统基于Linux环境。

 

学生成绩管理系统
 
1、用户管理功能
用户分为管理员、教师用户、学生用户三类。不论是管理员或教师用户,还是学生用户都需要通过用户名和口令进行登录,用户的注册信心,通过链表实现,保存到系统数据库中,每次登陆或者注册时,对用户名和密码进行核对,密码和用户名相符才可以登陆,注册时,用户名要是在数据库中已经存在,就提醒用户重新注册。
按学生角度管理教师可以看到学生信息和成绩信息。学生信息包括学号、姓名、班级、生日、性别、地址、电话和简历。当教师用键盘上对应的数字键选择某一学生信息时,可以显示出该课程的这个学生所有课程的学习成绩,并同时自动计算出这个学生的总分和平均分。在成绩信息中,教师可以对学习成绩进行增加、修改和删除。并能够打印报表。
 
2、学生对成绩的查看功能
 
学生用户登录后,学生可以看到自己的学生信息和成绩信息。学生信息包括学号、姓名、班级、生日、性别、地址、电话。成绩信息包括这个学生的所有课程的成绩信息,以及单科成绩排名和总成绩排名。
 

3、完成的功能如下:

1) 显示全部的记录(读取文件)

2) 删除记录(输入一个学生的学号,删除该学生的信息)

3) 插入记录(按约定的格式输入一个学生的信息将它插入)

4) 查找记录(输入一个学生学号,输出其各科成绩)

5) 计算总分和平均分

6) 排序(根据平均分排名,总分相同者名次一样)

7) 保存文件(插入或删除某个记录后,将文件保存)

8) 分类合计(分别统计100-90,90-80,80-70,70,60,60分一下的人数,并求出百分比)

 

4、全部程序代码以及代码实现功能:

Main.c

/*main函数实现主界面的打印输出*/

#include

#include"stu_base.h"

#include

#include

 

int main(int argc, const char *argv[])

{

    stu_scor head,he;

    int select,num;

    FILE *fp;

    fp = fopen("stu_scor.txt","a+");

    STU_SCOR  s, m;

    STU_INFO n;

    void print_scor(void);

    int log,k;

    int account;

    login Log,ret;

    while(1){

        printf("登录请按1 注册请按2\n");

        scanf("%d",&k);

        if(1 == k){

            printf("%s\n","请输入账户名:");

            scanf("%d",&account);

            printf("%s\n","请输入密码:");

            scanf("%d",&log);

            Log = list_log(fopen("stu_log.txt","a+"));

            ret = find_log(Log,account);

            if(ret == NULL){

                printf("用户名不存在,请重新登录!\n");   

            }

            else

                break;

        }

        if(2 == k){

            stu_register();

        }

    }

    if((account >= 100)&&(account < 200)&&(log == account)){

        printf("登录成功!\n");

        while(1){

            print_scor();

            scanf("%d",&select);

            switch(select){

                case 1:

                    printf("              -------------------------------------------------\n");

                    printf("              |  学号  |  姓名  |  成绩1  |  成绩2  |  成绩3  |\n");

                    printf("              -------------------------------------------------\n");

                    read_scor(&m);

                    break;

                case 2:

                    printf("%s\n","请输入要查看学生学号:");

                    scanf("%d",&s.num);

                    head = list_scor(fopen("stu_scor.txt","r"));

                    scor_check(head,s.num);

                    break;

                case 3:

                    stu_add_scor();

                    break;

                case 4:

                    head = list_scor(fopen("stu_scor.txt","r"));

                    printf("%s\n","请输入要修改的学号:");

                    scanf("%d",&s.num);

                    scor_mod(head,s.num);

                    break;

                case 5:

                    scor_sort();

                    break;

                case 6:

                    printf("%s\n","请输入要删除学生的学号:");

                    scanf("%d",&num);

                    head = scor_dele(num);

                    write_scor(head);

                    break;

                case 7:

                    head = list_scor(fopen("stu_scor.txt","r"));

                    he = sum(head);

                    write_scor_sta(he);

                    read_scor_sta(&m);

                    break;

                case 8:

                    sta_sort(fopen("stu_scor.txt","r"));

                    break;

                case 9:

                    printf("              -------------------------------------\n");

                    printf("              |  学号  |  姓名  |  性别  |  年龄  |\n");

                    printf("              -------------------------------------\n");

                    read_info(&n);  

                    break;

                case 10:

                    return 0;

                    break;

                default:

                    printf("▲ 输入错误请重新输入▲ :\n");

                    break;

            }

        }

    }

    if((account >= 200)&&(account < 300)&&(log == account))

    {

        int select,num;

        FILE *fp;

        fp = fopen("stu_info.txt","a+");

        STU_INFO s,m;

        STU_SCOR n;

        stu_info head;

        void print_info(void);

        printf("登录成功!\n");

        while(1){

            print_info();

            scanf("%d",&select);

            switch(select){

                case 1:

                    printf("              -------------------------------------\n");

                    printf("              |  学号  |  姓名  |  性别  |  年龄  |\n");

                    printf("              -------------------------------------\n");

                    read_info(&m);  

                    break;

                case 2:

                    printf("%s\n","请输入学号:");

                    scanf("%d",&s.num);

                    head = list_info(fp);

                    info_check(head,s.num);

                    break;

                case 3:

                    stu_add_info();

                    break;

                case 4:

                    head = list_info(fp);

                    printf("%s\n","请输入要修改信息的学号:");

                    scanf("%d",&s.num);

                    info_mod(head,s.num);

                    break;

                case 5:

                    info_sort();

                    break;

                case 6:

                    printf("%s\n","请输入要删除学生的学号:");

                    scanf("%d",&num);

                    head = info_dele(num);

                    write_info(head);

                    break;

                case 7:

                    printf("              -------------------------------------------------\n");

                    printf("              |  学号  |  姓名  |  成绩1  |  成绩2  |  成绩3  |\n");

                    printf("              -------------------------------------------------\n");

                    read_scor(&n);

                    break;

                case 8:

                    return 0;

                    break;

                default:

                    printf("▲ 输入错误请重新输入▲ :\n");

                    break;

            }

        }

    }

    if((account >= 300)&&(account <= 400)&&(account == log))

    {

        int select;

        stu_scor head;

        stu_info hed;

        printf("%s\n","请输入自己的学号:");

        printf("学号:");

        scanf("%d",&s.num);

        while(1){

            stu_print();

            scanf("%d",&select);

            switch(select){

                case 1:

                    sta_sort(fopen("stu_scor.txt","r"));

                    break;

                case 2:

                    head = list_scor(fopen("stu_scor.txt","r"));

                    stu_scor_check(head,s.num);

                    break;

                case 3:

                    hed = list_info(fopen("stu_info.txt","r"));

                    info_check(hed,s.num);

                    break;

                case 4:

                    return 0;

                    break;

                default:

                    printf("▲ 输入错误请重新输入▲ :\n");

                    break;

            }

        }

    }

    else if((account < 100)||(account > 400)||log!=account)

    {

        printf("%s\n","登陆失败!");

    }

    return 0;

}

 

void print_info(void)

{

    printf("\n");

    printf("\n");

    printf("              ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ \n");

    printf("              ☆                           |                         ☆ \n");

    printf("              ☆  ★ 按1键 显示全部信息     |   ★ 按2键 查看个人信息  ☆ \n");

    printf("              ☆---------------------------|-------------------------☆ \n");

    printf("              ☆  ★ 按3键 添加学生信息     |   ★ 按4键 修改学生信息  ☆ \n");

    printf("              ☆---------------------------|-------------------------☆ \n");

    printf("              ☆  ★ 按5键 学号排序         |   ★ 按6键 删除学生信息  ☆ \n");

    printf("              ☆---------------------------|-------------------------☆ \n");

    printf("              ☆  ★ 按7键 查看学生成绩     |   ★ 按8键 退出系统      ☆ \n");

    printf("              ☆-                          |                         ☆ \n");

    printf("              ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ \n");

    printf("※ 请按1~7键操作※ \n");

    printf("请按键:");

}

输出结果截图:

 

 

void print_scor(void)

{

    printf("\n");

    printf("\n");

    printf("              ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ \n");

    printf("              ☆                           |                         ☆ \n");

    printf("              ☆  ★ 按1键 显示全部信息     |   ★ 按2键 查看个人成绩  ☆ \n");

    printf("              ☆---------------------------|-------------------------☆ \n");

    printf("              ☆  ★ 按3键 添加学生成绩     |   ★ 按4键 修改学生成绩  ☆ \n");

    printf("              ☆---------------------------|-------------------------☆ \n");

    printf("              ☆  ★ 按5键 学生单科成绩排序 |   ★ 按6键 删除学生成绩  ☆ \n");

    printf("              ☆---------------------------|-------------------------☆ \n");

    printf("              ☆  ★ 按7键 计算个人总成绩   |   ★ 按8键 按总成绩排名  ☆ \n");

    printf("              ☆---------------------------|-------------------------☆ \n");

    printf("              ☆  ★ 按9键 查看学生信息     |   ★ 按10键 退出系统     ☆ \n");

    printf("              ☆                           |                         ☆ \n");

    printf("              ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ \n");

    printf("※ 请按1~9键操作※ \n");

    printf("请按键:");

}

 

输出结果截图:

void stu_print(void)

{

    printf("              ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ \n");

    printf("              ☆                           |                         ☆ \n");

    printf("              ☆  ★ 按1键 产看班级排名     |   ★ 按2键 查看个人成绩  ☆ \n");

    printf("              ☆---------------------------|-------------------------☆ \n");

    printf("              ☆  ★ 按3键 查看学生信息     |   ★ 按4键 退出系统      ☆ \n");

    printf("              ☆-                          |                         ☆ \n");

    printf("              ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ ☆ \n");

    printf("※ 请按1~3键操作※ \n");

    printf("请按键:");

}

Login.c

/*login函数实现用户登陆以及登陆信息与库里面信息的对比*/

#include

#include"stu_base.h"

#include

 

int stu_register()

{

    login head,ret;

    LOGIN s;

    int log;

    printf("请输入账户名(100~199)\n");

    scanf("%d",&s.account);

    printf("请输入密码\n");

    scanf("%d",&log);

    head = list_log(fopen("stu_log.txt","a+"));

    ret = find_log(head,s.account);

    if(ret == NULL){

        printf("注册成功!\n");

    }

    else{

        printf("该用户名已经存在!\n");

        return 0;

    }

    add_log(&s);

    return 0;

}

 

login list_log(FILE *fp)

{

    login p,q,head = NULL;

    int count = 1;

    rewind(fp);

    while(!feof(fp)){

        p = (login)malloc(sizeof(LOGIN));

        fread(p,sizeof(LOGIN),1,fp);

        if(1 == count){

            head = p;

            q = p;

            count++;

        }

        else{

            q->next = p;

            q = q->next;

             count++;

        }

    }

    return head;

}

 

login find_log(login head,int key)

{

    FILE *fp;

    login ret;

    fp = fopen("stu_log.txt","a+");

    ret = head;

     while(ret != NULL){

         if(ret->account == key){

             return ret;

         }

         else{

             ret = ret->next;

         }

     }

     fclose(fp);

     return NULL;

}

 

int add_log(login p)

{

    FILE *fp;

    fp = fopen("stu_log.txt","a+");

    fwrite(p,sizeof(LOGIN),1,fp);

    fclose(fp);

    return 0;

}

Stu_base.c

/*stu_base通过调用所需要函数实现学生基本信息的系统管理*/

#include

#include

#include"stu_base.h"

#include

 

int length1=sizeof(STU_INFO);

 

int add_info(stu_info p )

{

    if(!p){printf("%s\n",__func__);return 2;}

    FILE *fp;

    fp=fopen("stu_info.txt","a+");

    if(!fp){printf("%s open file error\n",__func__);return 3;}

    fwrite(p,length1,1,fp);

    fclose(fp);

    return 0;

}

 

int read_info(stu_info p)

{

    FILE*fp;

    fp=fopen("stu_info.txt","rb");

    if(!fp)

    {

        return 1;

    }

    while(!feof(fp)){

        if(fread(p,1,length1,fp)==length1){

            printf("              |%8d|%8s|%8c|%8d|\n",p->num,p->name,p->sex,p->age);

            printf("              -------------------------------------\n");

        }

    }

    

    fclose(fp);

    return 0;

}

 

stu_info list_info(FILE *fp)

{

    stu_info p,q,head = NULL;

    int count = 1;

    rewind(fp);

    while(!feof(fp)){

        p = (stu_info)malloc(sizeof(STU_INFO));

        fread(p,length1,1,fp);

        if(1 == count){

            head = p;

            q = p;

            count++;

        }

        else{

            q->next = p;

            q = q->next;

            count++;

        }

    }

    return head;

}

 

stu_info find_info(stu_info head,int k)

{

    FILE *fp;

    stu_info ret;

    fp = fopen("stu_info.txt","a+");

    ret = head;

    while(ret != NULL){

            if(ret->num == k){

                return ret;

            }

            else{

                ret = ret->next;

            }

        }

    fclose(fp);

    return NULL;

}

void write_info(stu_info head)

{

    stu_info p;

    p = head;

    FILE *fp;

    fp = fopen("stu_info.txt","w+");

    for(;p->next!=NULL;p=p->next)

    {

        fwrite(p,length1,1,fp);

    }

    fclose(fp);

}

void  info_check(stu_info head, int num)

{

    stu_info ret;

    ret = find_info(head,num);

    if(ret != NULL){

        printf("              -------------------------------------\n");

        printf("              |  学号  |  姓名  |  性别  |  年龄  |\n");

        printf("              -------------------------------------\n");

        printf("              |%8d|%8s|%8c|%8d|\n",ret->num,ret->name,ret->sex,ret->age);   

        printf("              -------------------------------------\n");

    }

    else

        printf("%s\n","该学号不存在!");

}

 

void stu_add_info()

{

    int i = 0;

    int j = 0;

    STU_INFO  s, m;

    stu_info ret,head;

    printf("请输入学生基本信息:\n");

    while(1){

        head = list_info(fopen("stu_info.txt","a+"));

        printf("继续录入按1  停止录入按2\n");

        scanf("%d",&i);

        if(2==i )

            break;

        scanf("%d %s %c %d",&s.num,s.name,&s.sex,&s.age);

        ret = find_info(head,s.num);

        if(ret != NULL){

            printf("输入的学号重复,是否继续输入:\n");

            printf("重新输入请按1,结束请按0:\n");

            scanf("%d",&j);

            if(1 == j){continue;}

            else if(0 == j){break;}

        }

        add_info(&s);

        list_info(fopen("stu_info.txt","a+"));

    }

    printf("              -------------------------------------\n");

    printf("              |  学号  |  姓名  |  性别  |  年龄  |\n");

    printf("              -------------------------------------\n");

    read_info(&m);

}

 

void info_mod(stu_info head, int num)

{

    int choice;

    STU_INFO s;

    stu_info ret;

    ret = find_info(head,num);

    if(ret != NULL){

        printf("              -------------------------------------\n");

        printf("              |  学号  |  姓名  |  性别  |  年龄  |\n");

        printf("              -------------------------------------\n");

        printf("              |%8d|%8s|%8c|%8d|\n",ret->num,ret->name,ret->sex,ret->age);

        printf("              -------------------------------------\n");

        printf("%s\n","请选择要修改项:姓名请按1,性别请按2,年龄请按3");

        scanf("%d",&choice);

        if(1 == choice){

            printf("%s\n","请输入正确的姓名:");

            scanf("%s",s.name);

            strcpy(ret->name,s.name);

        }

        if(2 == choice){

            printf("%s\n","请输入正确的性别:");

            getchar();

            scanf("%c",&s.sex);

            ret->sex = s.sex;

        }

        if(3 == choice){

            printf("%s\n","请输入正确的年龄:");

            scanf("%d",&s.age);

            ret->age = s.age;

        }

        printf("              -------------------------------------\n");

        printf("              |  学号  |  姓名  |  性别  |  年龄  |\n");

        printf("              -------------------------------------\n");

        printf("              |%8d|%8s|%8c|%8d|\n",ret->num,ret->name,ret->sex,ret->age);

        printf("              -------------------------------------\n");

        write_info(head);

    }

    else

        printf("%s\n","该学号不存在!");

}

你可能感兴趣的:(c语言,C语言编程,Linux)