20-01-06至20-01-10培训内容


#include

#include

#include

#include

struct sd

{

    int number; //学号

    char name[10]; //姓名

    float s[4]; //数语外+求和

};

struct sd student[101]={};

int num=0; //学生个数

int key0();

int key1();

void displayMenu(); //主菜单

void displayMenu1(); //-1

int inputScore(); //成绩录入

void outputScore(); //输出成绩

void outputScore1(); //-1

void queryScore(); //成绩查询

void queryScore1(); //-1

void sortScore(); //成绩排序

void sortScore1(); //-1

void fun(int j); //冒泡互换

void fun1(int j); //-1

void ReviseScore(); //修改成绩

int main()

    system("color F0");

    printf("\n\n\n\n\n\n\n ---------------------欢迎使用学生管理系统---------------------\n\n\n\n\n\n");

    _sleep(2000);

    system("cls");

    printf("\n用户名:");

    int b;

    char a[8];

    char a0[8]={"teacher"};

    char a1[8]={"student"};

    read:

    fflush(stdin);

    gets(a);

    if(strcmp(a,a0)==0)

    {

        b=0; //教师

    }

    else if(strcmp(a,a1)==0)

    {

        b=1; //学生

    }

    else

    {

        printf("\n未识别到用户名,请重新输入:");

        goto read;

    }

    switch(b)

    {

        case 0:key0();break;

        case 1:key1();break;

        default:break;

    }

}

int key0() //教师端口

{

    printf("\n密码:");

    char key0[7]={"123456"}; //教师账号密码

    char b[7];

    read:

    int i=0,j=0;

    while(j<4)

    {

        for(i=0;i<7;i++)

        {

            b[i]=getch();

            printf("*");

            if(b[i]=='\r')

            {

                b[i]='\0';

                break;

            }

        }

        if(strcmp(b,key0)==0)

        {

            printf("\n密码正确!\n");

            break;

        }

        else

        {

            j++;

            if(j<3)

            {

                printf("\n密码错误,还能输入%d次,请重输:",3-j);

            }

            else if(j>=3)

            {

                printf("\n输入已达上限,请3分钟后重试\n");

                _sleep(180000);

                system("cls");

                printf("用户名:teacher");

                goto read;

            }

        }

    }

    displayMenu();

}

void displayMenu() //主菜单

{

    system("cls");

    printf("******************************************************\n");

    printf("*                  学生管理系统1.0                  *\n");

    printf("* 主菜单(输入数字进入该程序)                        *\n");

    printf("* 1.成绩输入                                        *\n");

    printf("* 2.成绩输出                                        *\n");

    printf("* 3.成绩查询                                        *\n");

    printf("* 4.成绩排序                                        *\n");

    printf("* 5.修改成绩                                        *\n");

    printf("* 6.注销                                            *\n");

    printf("* 7.退出                                            *\n");

    printf("******************************************************\n");

    char a;

    a=getch();

    switch(a)

    {

        case '1':inputScore();break;

        case '2':outputScore();break;

        case '3':queryScore();break;

        case '4':sortScore();break;

        case '5':ReviseScore();break;

        case '6':system("cls");main();break;

        case '7':system("cls");exit(0);break;

        default:break;

    }

    displayMenu();

}

int inputScore() //输入成绩

{

    system("cls");

    int i=0;

    char a;

    while(1)

    {

         read:

         printf("请输入第%d个学生的学号:",i+1);

         scanf("%d",&student[i].number);

         printf("请输入第%d个学生的姓名:",i+1);

         scanf("%s",student[i].name);

         printf("请输入第%d个学生的三科成绩:",i+1);

         scanf("%f%f%f",&student[i].s[0],&student[i].s[1],&student[i].s[2]);

         student[i].s[3]=student[i].s[0]+student[i].s[1]+student[i].s[2];

         i++;

        printf("按任意键确认,按1重置,按2退出\n");

        a=getch();

/*

        if(a=='0')

        {

            goto read;

        }*/

        if(a=='1')

        {

             i--;

            goto read;

        }

        else if(a=='2')

        {

            break;

        }

    }

    num=i;

    printf("成绩录入完成,三秒后回到主菜单\n");

     _sleep(3000);

    displayMenu();

}

void outputScore() //输出成绩

{

    system("cls");

    int i;

    char a;

    for(i=0;i

    {

        printf("第%d名,学号:%d,姓名:%s,数学:%.1f,语文:%.1f,外语:%.1f,总成绩:%.1f\n",

        i+1,student[i].number,student[i].name,student[i].s[0],student[i].s[1],student[i].s[2],student[i].s[3]);

    }

    printf("\n按0回到主菜单,按1到成绩排序");

    a=getch();

    if(a=='0')

    {

        displayMenu();

    }

    else if(a=='1')

    {

        sortScore();

    }

}

void queryScore() //成绩查询

{

    system("cls");

    printf("***************************************\n");

    printf("*  成绩查询(按数字进入相应功能)      *\n");

    printf("*1.学号查询                          *\n");

    printf("*2.姓名查询                          *\n");

    printf("*3.回到主菜单                        *\n");

    printf("***************************************\n");

    int i;

    char a;

    a=getch();

    switch(a)

    {

        case '1':

        {

            system("cls");

            printf("请输入学号:");

            int b;

            scanf("%d",&b);

            for(i=0;i

            {

                if(b==student[i].number)

                {

                    printf("\n第%d名,学号:%d,姓名:%s,数学:%.1f,语文:%.1f,外语:%.1f,总成绩:%.1f\n",

                    i+1,student[i].number,student[i].name,student[i].s[0],student[i].s[1],student[i].s[2],student[i].s[3]);

                    break;

                }

                else if(i==num-1)

                {

                    printf("未找到该学生,即将返回到成绩查询界面");

                    _sleep(3000);

                    queryScore();

                }

            }

            break;

        }

        case '2':

        {

            system("cls");

            char c[10];

            printf("请输入姓名:");

            scanf("%s",c);

            for(i=0;i

            {

                if(strcmp(c,student[i].name)==0)

                {

                    printf("\n第%d名,学号:%d,姓名:%s,数学:%.1f,语文:%.1f,外语:%.1f,总成绩:%.1f\n",

                    i+1,student[i].number,student[i].name,student[i].s[0],student[i].s[1],student[i].s[2],student[i].s[3]);

                    break;

                }

                else if(i==num-1)

                {

                    printf("未找到该学生,即将返回到成绩查询界面");

                    _sleep(3000);

                    queryScore();

                }

            }

            break;

        }

        case '3':

        {

            displayMenu();

            break;

        }

        default:break;

    }

    printf("\n三秒后回到成绩查询界面\n");

    _sleep(3000);

    queryScore();

}

void sortScore() //成绩排序

{

    system("cls");

    printf("********************************************\n");

    printf("* 成绩排序(按数字进入相应功能)            *\n");

    printf("*1.数学成绩排序                            *\n");

    printf("*2.语文成绩排序                            *\n");

    printf("*3.英语成绩排序                            *\n");

    printf("*4.总成绩排序                              *\n");

    printf("*5.学号排序                                *\n");

    printf("*6.回到主程序                              *\n");

    printf("********************************************\n");

    char a;

    a=getch();

    switch(a)

    {

        case '1':

        {

            int i,j;

            system("cls");

            for(i=0;i

            {

                for(j=0;j

                {

                    if(student[j+1].s[0]>student[j].s[0])

                    {

                        fun(j);

                    }

                }

            }

            outputScore();

            break;

        }

        case '2':

        {

             int i,j;

            system("cls");

            for(i=0;i

            {

                for(j=0;j

                {

                    if(student[j+1].s[1]>student[j].s[1])

                    {

                        fun(j);

                    }

                }

            }

            outputScore();

            break;

        }

        case '3':

        {

            int i,j;

            system("cls");

            for(i=0;i

            {

                for(j=0;j

                {

                    if(student[j+1].s[2]>student[j].s[2])

                    {

                        fun(j);

                    }

                }

            }

            outputScore();

            break;

        }

        case '4':

        {

            int i,j;

            system("cls");

            for(i=0;i

            {

                for(j=0;j

                {

                    if(student[j+1].s[3]>student[j].s[3])

                    {

                        fun(j);

                    }

                }

            }

            outputScore();

            break;

        }

        case '5':

        {

            int i,j;

            system("cls");

            for(i=0;i

            {

                for(j=0;j

                {

                    if(student[j+1].number>student[j].number)

                    {

                        fun(j);

                    }

                }

            }

            outputScore();

            break;

        }

        case '6':

        {

            displayMenu();

            break;

        }

        default:break;

    }

}

void fun(int j) //互换

{

    int a;

    char b[10];

    float c;

    a=student[j+1].number; //学号互换

    student[j+1].number=student[j].number;

    student[j].number=a;

    strcpy(b,student[j+1].name); //名字互换

    strcpy(student[j+1].name,student[j].name);

    strcpy(student[j].name,b);

    c=student[j+1].s[0]; //数学互换

    student[j+1].s[0]=student[j].s[0];

    student[j].s[0]=c;

    c=student[j+1].s[1]; //语文互换

    student[j+1].s[1]=student[j].s[1];

    student[j].s[1]=c;

    c=student[j+1].s[2]; //英语互换

    student[j+1].s[2]=student[j].s[2];

    student[j].s[2]=c;

    c=student[j+1].s[3]; //总成绩互换

    student[j+1].s[3]=student[j].s[3];

    student[j].s[3]=c;

}

void ReviseScore() //修改成绩

{

    system("cls");

    printf("*****************************************\n");

    printf("*  修改成绩(按数字进入相应功能)        *\n");

    printf("*1.修改学生姓名        6.新增学生成绩  *\n");

    printf("*2.修改数学成绩        7.删除学生成绩  *\n");

    printf("*3.修改语文成绩                        *\n");

    printf("*4.修改英语成绩                        *\n");

    printf("*5.返回主界面                          *\n");

    printf("*****************************************\n");

    char a;

    a=getch();

    switch(a)

    {

        case '1':

        {

            system("cls");

            printf("请输入需要修改学生的学号:");

            int i,j;

            char b[10];

            scanf("%d",&j);

            for(i=0;i

            {

                if(j==student[i].number)

                {

                    printf("\n请输入需要修改学生的姓名:");

                    scanf("%s",b);

                    strcpy(student[i].name,b);

                    printf("\n修改完成!3秒后回到修改成绩界面");

                    printf("\n学号:%d,姓名:%s,数学:%.1f,语文:%.1f,外语:%.1f,总成绩:%.1f\n",

                    student[i].number,student[i].name,student[i].s[0],student[i].s[1],student[i].s[2],student[i].s[3]);

                    _sleep(3000);

                    break;

                }

                else if(i==num-1)

                {

                    printf("未找到该学生,即将返回到修改成绩界面");

                    _sleep(3000);

                    ReviseScore();

                }

            }

            ReviseScore();

            break;

        }

        case '2':

        {

            system("cls");

            printf("请输入需要修改学生的学号:");

            int i,j;

            int b;

            scanf("%d",&j);

            for(i=0;i

            {

                if(j==student[i].number)

                {

                    printf("\n请输入需要修改学生的数学成绩:");

                    scanf("%d",&b);

                    student[i].s[0]=b;

                    printf("\n修改完成!3秒后回到修改成绩界面");

                    student[i].s[3]=student[i].s[0]+student[i].s[1]+student[i].s[2];

                    printf("\n学号:%d,姓名:%s,数学:%.1f,语文:%.1f,外语:%.1f,总成绩:%.1f\n",

                    student[i].number,student[i].name,student[i].s[0],student[i].s[1],student[i].s[2],student[i].s[3]);

                    _sleep(3000);

                    ReviseScore();

                    break;

                }

                else if(i==num-1)

                {

                    printf("未找到该学生,即将返回到修改成绩界面");

                    _sleep(3000);

                    ReviseScore();

                }

            }

            break;

        }

        case '3':

        {

            system("cls");

            printf("请输入需要修改学生的学号:");

            int i,j;

            int b;

            scanf("%d",&j);

            for(i=0;i

            {

                if(j==student[i].number)

                {

                    printf("\n请输入需要修改学生的语文成绩:");

                    scanf("%d",&b);

                    student[i].s[1]=b;

                    printf("\n修改完成!3秒后回到修改成绩界面");

                    student[i].s[3]=student[i].s[0]+student[i].s[1]+student[i].s[2];

                    printf("\n学号:%d,姓名:%s,数学:%.1f,语文:%.1f,外语:%.1f,总成绩:%.1f\n",

                    student[i].number,student[i].name,student[i].s[0],student[i].s[1],student[i].s[2],student[i].s[3]);

                    _sleep(3000);

                    ReviseScore();

                    break;

                }

                else if(i==num-1)

                {

                    printf("未找到该学生,即将返回到修改成绩界面");

                    _sleep(3000);

                    ReviseScore();

                }

            }

            break;

        }

        case '4':

        {

            system("cls");

            printf("请输入需要修改学生的学号:");

            int i,j;

            int b;

            scanf("%d",&j);

            for(i=0;i

            {

                if(j==student[i].number)

                {

                    printf("\n请输入需要修改学生的英语成绩:");

                    scanf("%d",&b);

                    student[i].s[2]=b;

                    printf("\n修改完成!3秒后回到修改成绩界面");

                    student[i].s[3]=student[i].s[0]+student[i].s[1]+student[i].s[2];

                    printf("\n学号:%d,姓名:%s,数学:%.1f,语文:%.1f,外语:%.1f,总成绩:%.1f\n",

                    student[i].number,student[i].name,student[i].s[0],student[i].s[1],student[i].s[2],student[i].s[3]);

                    _sleep(3000);

                    ReviseScore();

                    break;

                }

                else if(i==num-1)

                {

                    printf("未找到该学生,即将返回到修改成绩界面");

                    _sleep(3000);

                    ReviseScore();

                }

            }

            break;

        }

        case '5':

        {

            displayMenu();

            break;

        }

        case '6':

        {

            system("cls");

            int i;

            i=num;

            char a;

            while(1)

            {

                read:

                printf("请输入第%d个学生的学号:",i+1);

                scanf("%d",&student[i].number);

                printf("请输入第%d个学生的姓名:",i+1);

                scanf("%s",student[i].name);

                printf("请输入第%d个学生的三科成绩:",i+1);

                scanf("%f%f%f",&student[i].s[0],&student[i].s[1],&student[i].s[2]);

                student[i].s[3]=student[i].s[0]+student[i].s[1]+student[i].s[2];

                i++;

                printf("按任意键确认,按1重置,按2退出\n");

                a=getch();

                if(a=='0')

                {

                    goto read;

                }

                else if(a=='1')

                {

                    i--;

                    goto read;

                }

                else if(a=='2')

                {

                    break;

                }

            }

            num=i;

             printf("成绩录入完成,三秒后回到修改成绩页面\n");

            _sleep(3000);

            ReviseScore();

            break;

         }

        case '7':

        {

            system("cls");

            printf("请输入需要删除学生的学号:");

            int i,j,k;

            int b;

            scanf("%d",&j);

            for(i=0;i

            {

                if(j==student[i].number)

                {

                    for(k=i;k<=num;k++)

                    {

                        student[k].number=student[k+1].number; //学号互换

                        strcpy(student[k].name,student[k+1].name); //名字互换

                        student[k].s[0]=student[k+1].s[0]; //数学互换

                        student[k].s[1]=student[k+1].s[1]; //语文互换

                        student[k].s[2]=student[k+1].s[2]; //英语互换

                        student[k].s[3]=student[k+1].s[3]; //总成绩互换

                    }

                    num--;

                    printf("\n修改完成!3秒后回到修改成绩界面");

                    _sleep(3000);

                    ReviseScore();

                    break;

                }

                else if(i==num-1)

                {

                    printf("未找到该学生,即将返回到修改成绩界面");

                    _sleep(3000);

                    ReviseScore();

                }

            }

            break;

        }

        default:break;

    }

}

int key1() //学生端口

{

    printf("\n密码:");

    char key0[7]={"123456"}; //学生账号密码

    char b[7];

    read:

    int i=0,j=0;

    while(j<4)

    {

        for(i=0;i<7;i++)

        {

            b[i]=getch();

            printf("*");

            if(b[i]=='\r')

            {

                b[i]='\0';

                break;

            }

        }

        if(strcmp(b,key0)==0)

        {

            printf("\n密码正确!\n");

            break;

        }

        else

        {

            j++;

            if(j<3)

            {

                printf("\n密码错误,还能输入%d次,请重输:",3-j);

            }

            else if(j>=3)

            {

                printf("\n输入已达上限,请3分钟后重试\n");

                _sleep(180000);

                system("cls");

                printf("用户名:teacher");

                goto read;

            }

        }

    }

    displayMenu1();

}

void displayMenu1() //学生主菜单

{

    system("cls");

    printf("******************************************************\n");

    printf("*                  学生管理系统1.0                  *\n");

    printf("* 主菜单(输入数字进入该程序)                        *\n");

    printf("* 1.输出成绩                                        *\n");

    printf("* 2.成绩查询                                        *\n");

    printf("* 3.成绩排序                                        *\n");

    printf("* 4.注销                                            *\n");

    printf("* 5.退出                                            *\n");

    printf("******************************************************\n");

    char a;

    a=getch();

    switch(a)

    {

        case '1':outputScore1();break;

        case '2':queryScore1();break;

        case '3':sortScore1();break;

        case '4':system("cls");main();break;

        case '5':system("cls");exit(0);break;

        default:break;

    }

}

void outputScore1() //学生输出成绩

{

    system("cls");

    int i;

    char a;

    for(i=0;i

    {

        printf("第%d名,学号:%d,姓名:%s,数学:%.1f,语文:%.1f,外语:%.1f,总成绩:%.1f\n",

        i+1,student[i].number,student[i].name,student[i].s[0],student[i].s[1],student[i].s[2],student[i].s[3]);

    }

    printf("\n按0回到主菜单,按1到成绩排序");

    a=getch();

    if(a=='0')

    {

        displayMenu1();

    }

    else if(a=='1')

    {

        sortScore1();

    }

}

void queryScore1() //成绩查询

{

    system("cls");

    printf("***************************************\n");

    printf("*  成绩查询(按数字进入相应功能)      *\n");

    printf("*1.学号查询                          *\n");

    printf("*2.姓名查询                          *\n");

    printf("*3.回到主菜单                        *\n");

    printf("***************************************\n");

    int i;

    char a;

    a=getch();

    switch(a)

    {

        case '1':

        {

            system("cls");

            printf("请输入学号:");

            int b;

            scanf("%d",&b);

            for(i=0;i

            {

                if(b==student[i].number)

                {

                    printf("\n第%d名,学号:%d,姓名:%s,数学:%.1f,语文:%.1f,外语:%.1f,总成绩:%.1f\n",

                    i+1,student[i].number,student[i].name,student[i].s[0],student[i].s[1],student[i].s[2],student[i].s[3]);

                    break;

                }

                else if(i==num-1)

                {

                    printf("未找到该学生,即将返回到成绩查询界面");

                    _sleep(3000);

                    queryScore1();

                }

            }

            break;

        }

        case '2':

        {

            system("cls");

            char c[10];

            printf("请输入姓名:");

            scanf("%s",c);

            for(i=0;i

            {

                if(strcmp(c,student[i].name)==0)

                {

                    printf("\n第%d名,学号:%d,姓名:%s,数学:%.1f,语文:%.1f,外语:%.1f,总成绩:%.1f\n",

                    i+1,student[i].number,student[i].name,student[i].s[0],student[i].s[1],student[i].s[2],student[i].s[3]);

                    break;

                }

                else if(i==num-1)

                {

                    printf("未找到该学生,即将返回到成绩查询界面");

                    _sleep(3000);

                    queryScore1();

                }

            }

            break;

        }

        case '3':

       {

            displayMenu1();

            break;

        }

       default:break;

    }

    printf("\n三秒后回到主程序\n");

    _sleep(3000);

    displayMenu1();

}

void sortScore1() //成绩排序

{

    system("cls");

    printf("********************************************\n");

    printf("* 成绩排序(按数字进入相应功能)            *\n");

    printf("*1.数学成绩排序                            *\n");

    printf("*2.语文成绩排序                            *\n");

    printf("*3.英语成绩排序                            *\n");

    printf("*4.总成绩排序                              *\n");

    printf("*5.学号排序                                *\n");

    printf("*6.回到主程序                              *\n");

    printf("********************************************\n");

    char a;

    a=getch();

    switch(a)

    {

        case '1':

        {

            int i,j;

            system("cls");

            for(i=0;i

            {

                for(j=0;j

                {

                    if(student[j+1].s[0]>student[j].s[0])

                    {

                        fun1(j);

                    }

                }

            }

            outputScore1();

            break;

        }

        case '2':

        {

            int i,j;

            system("cls");

            for(i=0;i

            {

                for(j=0;j

                {

                    if(student[j+1].s[1]>student[j].s[1])

                    {

                        fun1(j);

                    }

                }

            }

            outputScore1();

            break;

        }

        case '3':

        {

            int i,j;

            system("cls");

            for(i=0;i

            {

                for(j=0;j

                {

                    if(student[j+1].s[2]>student[j].s[2])

                    {

                        fun1(j);

                    }

                }

            }

            outputScore1();

            break;

        }

        case '4':

        {

            int i,j;

            system("cls");

            for(i=0;i

            {

                for(j=0;j

                {

                    if(student[j+1].s[3]>student[j].s[3])

                    {

                        fun1(j);

                    }

                }

            }

            outputScore1();

            break;

        }

        case '5':

        {

            int i,j;

            system("cls");

            for(i=0;i

            {

                for(j=0;j

                {

                    if(student[j+1].number>student[j].number)

                    {

                        fun1(j);

                    }

                }

            }

            outputScore1();

            break;

        }

        case '6':

        {

            displayMenu1();

            break;

        }

        default:break;

    }

}

void fun1(int j) //互换

{

    int a;

    char b[10];

    float c;

    a=student[j+1].number; //学号互换

    student[j+1].number=student[j].number;

    student[j].number=a;

    strcpy(b,student[j+1].name); //名字互换

    strcpy(student[j+1].name,student[j].name);

    strcpy(student[j].name,b);

    c=student[j+1].s[0]; //数学互换

    student[j+1].s[0]=student[j].s[0];

    student[j].s[0]=c;

    c=student[j+1].s[1]; //语文互换

    student[j+1].s[1]=student[j].s[1];

    student[j].s[1]=c;

    c=student[j+1].s[2]; //英语互换

    student[j+1].s[2]=student[j].s[2];

    student[j].s[2]=c;

    c=student[j+1].s[3]; //总成绩互换

    student[j+1].s[3]=student[j].s[3];

    student[j].s[3]=c;

}

你可能感兴趣的:(20-01-06至20-01-10培训内容)