成绩管理系统-C++作业


#define MATH 0
#define CHINESE 1
#define ENGLISH 2
#define HIGHMATH 3
#define BIGGESTSTUDENT 50
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <windows.h>
typedef struct
{
    int ID;
    char name[20];
    char sex[20];
    int score[4];
} Student;
//学生信息总表
Student student[BIGGESTSTUDENT] = {0};

//总课表
char AllCourse[4][100] = {"数学", "语文", "英语", "计算机"};
bool PasswordVerify();
//初始化程序读取数据总表
void ReadStudentAllTable();
//写入数据总表
void WriteStudentAllTable();

//输入学生信息
void InputStudent();
//通过姓名查找学生的信息结构体
Student *SeekStudent(char *name);
//通过ID查找学生的信息结构体
Student *SeekStudent(int ID);
//寻找总表空位
Student *SeekVoidTable();

//通过ID更改学生ID信息
void ModifyStudentID(int oldID, int newID);
//通过姓名更改学生ID信息
void ModifyStudentID(char *oldname, int newID);

//通过ID更改学生名字
void ModifyStudentName(int ID, char *name);
//通过名字更改学生名字
void ModifyStudentName(char *oldname, char *newname);

//通过ID更改更改学生性别
void ModifyStudentSex(int ID, char *sex);
//通过名字更改更改学生性别
void ModifyStudentSex(char *name, char *sex);

//通过ID更改更改成绩   课程参数
//MATH 数学     CHINESE 汉语    ENGLISH 英语     HIGHMATH 计算机
void ModifyStudentScore(int ID, int course, int score);
//通过名字更改更改成绩
void ModifyStudentScore(char *name, int course, int score);

//显示所有学生成绩
void ShowAllStudentScore();

//学生通过ID查询成绩
void ShowStudentScore(int ID);
//学生通过姓名查询成绩
void ShowStudentScore(char *name);

//查询成绩名次
void SeekStudentSort(int ID);

//成绩排序输出
//参数排序科目,4为总成绩排序
void SortAllScore(int course);

//统计各科分数段人数
//参数统计科目,分数段  min<分数<=max,5为总成绩统计
//返回该分数段人数
int StatsCourseScore(float max, float min, int course);

//统计杂七杂八的及格率什么的
//参数排序科目,5为总成绩排序
void StatsAll(int course);

//通过ID修改基础信息
void ModifyBaseInformation(int ID);

//通过名字修改基础信息
void ModifyBaseInformation(char *name);

//通过ID修改成绩
void ModifyScoreInformation(int ID);
//通过姓名修改成绩
void ModifyScoreInformation(char *name);

//显示所有学生基本信息
void ShowAllStudentInformation();

void toxy(int x, int y); //将光标移动到X,Y坐标处
void color(short x);     //设置颜色
void over();             //退出
//登陆
void Login();
//管理员菜单
void RootMenu();
//学生菜单
void StudentMenu();
//修改密码
bool ModifyPassword();

//修改学生个人或成绩信息
void ModifyStudentInformationMenu();

//初始化程序读取数据总表
void ReadStudentAllTable()
{
    FILE *fp;                          //文件指针
    fp = fopen("./mysocre.txt", "rb"); //以追加的方式打开名字为mybook的二进制文件
    if (fp != NULL)
    {
        if (fread(&student, sizeof(Student) * BIGGESTSTUDENT, 1, fp) != 1) //将p所指向的一段大小为N的内容存入fp所指向的文件中
        {
            printf("配置文件错误");
        }
    }
    else
    {
        printf("配置文件错误");
    }
    fclose(fp); //关闭文件
}
void color(short x)
{
    if (x >= 0 && x <= 15)
    {
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
    }
    else
    {
        SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), x);
    }
}

void toxy(int x, int y) //将光标移动到X,Y坐标处
{
    COORD pos = {x, y};
    HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleCursorPosition(Out, pos);
}
//写入数据总表
void WriteStudentAllTable()
{
    FILE *fp; //文件指针
    fp = fopen("./mysocre.txt", "wb");
    if (fp == NULL)
    {
        fclose(fp); //关闭文件
        fp = fopen("./mysocre.txt", "wb+");
    }

    if (fwrite(&student, sizeof(Student) * BIGGESTSTUDENT, 1, fp) != 1) //将p所指向的一段大小为N的内容存入fp所指向的文件中
    {
        printf("写入配置文件错误");
    }
    fclose(fp); //关闭文件
}

//寻找总表空位
Student *SeekVoidTable()
{
    for (int i = 0; i < 100; i++)
    {
        if (student[i].ID == 0)
        {
            return &student[i];
        }
    }
}

//输入学生信息
void InputStudent()
{
    //Student *tempstu = SeekVoidTable();
    char i;
    for (; i != 27;)
    {
        Student *tempstu = SeekVoidTable();
        printf("请输入学号:");
        scanf("%d", &tempstu->ID);
        printf("请输入姓名:");
        scanf("%s", tempstu->name);
        printf("请输入性别:");
        scanf("%s", tempstu->sex);
        printf("请输入数学:");
        scanf("%d", &tempstu->score[0]);
        printf("请输入语文:");
        scanf("%d", &tempstu->score[1]);
        printf("请输入英语:");
        scanf("%d", &tempstu->score[2]);
        printf("请输入计算机:");
        scanf("%d", &tempstu->score[3]);
        WriteStudentAllTable();
        printf("继续输入请按回车,结束输入请按Esc\n");
        i = getch();                //暂停程序当i接收后继续下一条指令
        for (; i != 13 && i != 27;) //保证只能是CR和ESC才能退出循环,输入其他字符无用,暂停程序,按'CR'继续。
            i = getch();
        //WriteStudentAllTable();
    }
}

//通过姓名查找学生的信息结构体
Student *SeekStudent(char *name)
{
    for (int i = 0; i < BIGGESTSTUDENT; i++)
    {
        if (strcmp(student[i].name, name) == 0)
        {
            return &student[i];
        }
    }
    return NULL;
}

//通过ID查找学生的信息结构体
Student *SeekStudent(int ID)
{
    for (int i = 0; i < BIGGESTSTUDENT; i++)
    {
        if (student[i].ID == ID)
        {
            return &student[i];
        }
    }
    return NULL;
}

//通过ID更改学生ID信息
void ModifyStudentID(int oldID, int newID)
{
    Student *tempstu = SeekStudent(oldID);
    if (tempstu != NULL)
    {
        tempstu->ID = newID;
        WriteStudentAllTable();
    }
}
//通过姓名更改学生ID信息
void ModifyStudentID(char *oldname, int newID)
{
    Student *tempstu = SeekStudent(oldname);
    if (tempstu != NULL)
    {
        tempstu->ID = newID;
        WriteStudentAllTable();
    }
}

//通过ID更改学生名字
void ModifyStudentName(int ID, char *name)
{
    Student *tempstu = SeekStudent(ID);
    if (tempstu != NULL)
    {
        memcpy(tempstu->name, name, sizeof(tempstu->name));
        WriteStudentAllTable();
    }
}
//通过名字更改学生名字
void ModifyStudentName(char *oldname, char *newname)
{
    Student *tempstu = SeekStudent(oldname);
    if (tempstu != NULL)
    {
        memcpy(tempstu->name, newname, sizeof(tempstu->name));
        WriteStudentAllTable();
    }
}

//通过ID更改更改学生性别
void ModifyStudentSex(int ID, char *sex)
{
    Student *tempstu = SeekStudent(ID);
    if (tempstu != NULL)
    {
        memcpy(tempstu->sex, sex, sizeof(tempstu->sex));
        WriteStudentAllTable();
    }
}
//通过名字更改更改学生性别
void ModifyStudentSex(char *name, char *sex)
{
    Student *tempstu = SeekStudent(name);
    if (tempstu != NULL)
    {
        memcpy(tempstu->name, name, sizeof(tempstu->name));
        WriteStudentAllTable();
    }
}

//通过ID更改更改成绩
void ModifyStudentScore(int ID, int course, int score)
{
    Student *tempstu = SeekStudent(ID);
    if (tempstu != NULL)
    {
        tempstu->score[course] = score;
        WriteStudentAllTable();
    }
    else
    {
        printf("学生不存在");
    }
}
//通过名字更改更改成绩
void ModifyStudentScore(char *name, int course, int score)
{
    Student *tempstu = SeekStudent(name);
    if (tempstu != NULL)
    {
        tempstu->score[course] = score;
        WriteStudentAllTable();
    }
    else
    {
        printf("学生不存在");
    }
}

//显示所有学生成绩
void ShowAllStudentScore()
{
    for (int i = 0; i < BIGGESTSTUDENT; i++)
    {
        if (student[i].ID != 0)
        {
            printf("学号ID:%d\t姓名:%s\t数学:%d\t汉语:%d\t英语:%d\t计算机:%d\t",
                   student[i].ID, student[i].name, student[i].score[0], student[i].score[1], student[i].score[2], student[i].score[3]);
        }
    }
}

//学生通过ID查询成绩
void ShowStudentScore(int ID)
{
    Student *tempstu = SeekStudent(ID);
    if (tempstu != NULL && tempstu->ID != 0)
    {
        printf("学号ID:%d\t姓名:%s\t数学:%d\t汉语:%d\t英语:%d\t计算机:%d\t总成绩:%d\t",
               tempstu->ID, tempstu->name, tempstu->score[0], tempstu->score[1], tempstu->score[2], tempstu->score[3],
               tempstu->score[0] + tempstu->score[1] + tempstu->score[2] + tempstu->score[3]);
    }
    else
    {
        printf("学生不存在");
    }
}
//学生通过姓名查询成绩
void ShowStudentScore(char *name)
{
    Student *tempstu = SeekStudent(name);
    if (tempstu != NULL && tempstu->ID != 0)
    {
        printf("学号ID:%d\t姓名:%s\t数学:%d\t汉语:%d\t英语:%d\t计算机:%d\t总成绩:%d\t",
               tempstu->ID, tempstu->name, tempstu->score[0], tempstu->score[1], tempstu->score[2], tempstu->score[3],
               tempstu->score[0] + tempstu->score[1] + tempstu->score[2] + tempstu->score[3]);
    }
    else
    {
        printf("学生不存在");
    }
}

//查询总成绩名次
void SeekStudentSort(int ID)
{

    int rank = 1;
    int score = 0;
    Student *tempstu = SeekStudent(ID);
    if (tempstu != NULL && tempstu->ID != 0)
    {
        for (int i = 0; i < 4; i++)
        {
            score += tempstu->score[i];
        }
        for (int i = 0; i < BIGGESTSTUDENT; i++)
        {
            int otherscore = 0;
            for (int j = 0; j < 4; j++)
            {
                otherscore += student[i].score[j];
            }
            if (score < otherscore)
            {
                rank++;
            }
        }
        printf("总名次为:%d", rank);
    }
    else
    {
        printf("学生不存在");
    }
}

//成绩排序输出
void SortAllScore(int course)
{
    int tempsort[BIGGESTSTUDENT] = {0};
    int tempscore[BIGGESTSTUDENT] = {0};
    for (int i = 0; i < BIGGESTSTUDENT; i++)
    {
        tempsort[i] = i;
        if (course != 4)
        {
            tempscore[i] = student[i].score[course];
        }
        else
        {
            for (int j = 0; j < 4; j++)
            {
                tempscore[i] += student[i].score[j];
            }
        }
    }
    for (int i = 0; i < BIGGESTSTUDENT; i++)
    {
        for (int j = 0; j < BIGGESTSTUDENT - i - 1; j++)
        {
            if (tempscore[j] < tempscore[j + 1])
            {
                int temp = tempscore[j];
                tempscore[j] = tempscore[j + 1];
                tempscore[j + 1] = temp;

                temp = tempsort[j];
                tempsort[j] = tempsort[j + 1];
                tempsort[j + 1] = temp;
            }
        }
    }
    for (int i = 0; i < BIGGESTSTUDENT; i++)
    {
        if (student[tempsort[i]].ID != 0)
        {

            printf("学号ID:%d\t姓名:%s\t数学:%d\t汉语:%d\t英语:%d\t计算机:%d\t总成绩:%d\t\n",
                   student[tempsort[i]].ID, student[tempsort[i]].name, student[tempsort[i]].score[0], student[tempsort[i]].score[1], student[tempsort[i]].score[2], student[tempsort[i]].score[3],
                   student[tempsort[i]].score[0] + student[tempsort[i]].score[1] + student[tempsort[i]].score[2] + student[tempsort[i]].score[3]);
            printf("------------------------------------------------------------------------------------------------------------------------\n");
        }
    }
}
//统计各科分数段人数
//参数统计科目,5为总成绩统计
int StatsCourseScore(float max, float min, int course)
{
    int number = 0;
    float tempscore = 0;
    for (int i = 0; i < BIGGESTSTUDENT; i++)
    {
        if (course != 5)
        {
            tempscore = student[i].score[course];
            if (tempscore <= max && tempscore > min)
            {
                number++;
            }
        }
        else
        {
            for (int j = 0; j < 4; j++)
            {
                tempscore = student[i].score[j];
            }
            if (tempscore <= max && tempscore > min)
            {
                number++;
            }
        }
    }
    return number;
}

//统计杂七杂八的及格率什么的
//参数排序科目,5为总成绩排序
void StatsAll(int course)
{
    float pass = 0, max = 0, min = 100, avg = 0, all = 0;
    int passpeople = 0;
    int allpeople = 0;
    if (course != 5)
    {
        for (int i = 0; i < BIGGESTSTUDENT; i++)
        {
            if (student[i].ID != 0)
            {
                allpeople++;
                if (student[i].score[course] > max)
                {
                    max = student[i].score[course];
                }
                if (student[i].score[course] < min)
                {
                    min = student[i].score[course];
                }
                if (student[i].score[course] >= 60)
                {
                    passpeople++;
                }
                all += student[i].score[course];
            }
        }
        pass = passpeople * 1.0 / allpeople;
        avg = all / allpeople;
        printf("科目:%s\t总分:%.2f\t及格率:%.2f\t最高分:%.2f\t最低分:%.2f\t平均分:%.2f\t\n\n", AllCourse[course], all, pass, max, min, avg);
    }
    else
    {
        printf("科目错误");
    }
}

//通过ID修改基础信息
void ModifyBaseInformation(int ID)
{
    Student *tempstu = SeekStudent(ID);
    if (tempstu != NULL)
    {
        printf("请输入学号:");
        scanf("%d", &tempstu->ID);
        printf("请输入姓名:");
        scanf("%s", tempstu->name);
        printf("请输入性别:");
        scanf("%s", tempstu->sex);
        WriteStudentAllTable();
    }
    else
    {
        printf("学生不存在");
    }
}

//通过姓名修改基础信息
void ModifyBaseInformation(char *name)
{
    Student *tempstu = SeekStudent(name);
    if (tempstu != NULL)
    {
        printf("请输入学号:");
        scanf("%d", &tempstu->ID);
        memset(tempstu->name, '\0', sizeof(tempstu->name));
        printf("请输入姓名:");
        scanf("%s", tempstu->name);
        memset(tempstu->sex, '\0', sizeof(tempstu->sex));
        printf("请输入性别:");
        scanf("%s", tempstu->sex);
        WriteStudentAllTable();
    }
    else
    {
        printf("学生不存在");
    }
}

//通过ID修改成绩
void ModifyScoreInformation(int ID)
{
    Student *tempstu = SeekStudent(ID);
    if (tempstu != NULL)
    {
        printf("请输入数学:");
        scanf("%d", &tempstu->score[0]);
        printf("请输入语文:");
        scanf("%d", &tempstu->score[1]);
        printf("请输入英语:");
        scanf("%d", &tempstu->score[2]);
        printf("请输入计算机:");
        scanf("%d", &tempstu->score[3]);
        WriteStudentAllTable();
    }
    else
    {
        printf("学生不存在");
    }
}

//通过姓名修改成绩
void ModifyScoreInformation(char *name)
{
    Student *tempstu = SeekStudent(name);
    if (tempstu != NULL)
    {
        printf("请输入数学:");
        scanf("%d", &tempstu->score[0]);
        printf("请输入语文:");
        scanf("%d", &tempstu->score[1]);
        printf("请输入英语:");
        scanf("%d", &tempstu->score[2]);
        printf("请输入计算机:");
        scanf("%d", &tempstu->score[3]);
        WriteStudentAllTable();
    }
    else
    {
        printf("学生不存在");
    }
}

//显示所有学生基本信息
void ShowAllStudentInformation()
{
    for (int i = 0; i < BIGGESTSTUDENT; i++)
    {
        if (student[i].ID != 0)
        {
            printf("学号:%d\t姓名:%s\t性别:%s\n", student[i].ID, student[i].name, student[i].sex);
            printf("-----------------------------------------------\n");
        }
    }
}

//登陆
void Login()
{
    system("cls"); //清屏
    color(15);     //设置一个好看的颜色
    toxy(50, 5);   //将光标移动到(50,5)坐标处
    printf("    成绩管理系统");
    toxy(48, 8);
    printf("|     1.管理登录       |");
    toxy(48, 10);
    printf("|     2.学生入口       |");
    toxy(48, 12);
    printf("|     3.退出系统       |");
    toxy(48, 14);
    printf("| 请按键选择,回车确定 |");
    printf("\n");
    char choose[10];
    char t;
    //选择表
    char choosetable[3][100] = {"1", "2", "3"};
    //选择是否合规
    bool judgechoose = false;
    do
    {
        toxy(48, 16);
        scanf("%s", choose);
        for (int i = 0; i < 3; i++)
        {
            if (strcmp(choose, choosetable[i]) == 0)
            {
                judgechoose = true;
                break;
            }
            if (i == 3)
            {
                printf("\n选择不合规,请重新输入功能选项:");
            }
        }
    } while (!judgechoose);
    switch (choose[0])
    {
    case '1':
        //管理员登录
        if (PasswordVerify())
        {
            while (true)
            {
                RootMenu();
            }
        }
        break;

    case '2':
        //学生入口
        while (true)
        {
            StudentMenu();
        }
        break;
    case '3':
        //退出
        over();
        break;
    }
}

//修改学生个人或成绩信息
void ModifyStudentInformationMenu()
{
    system("cls");
    printf("**************************************************");
    printf("\n 1.修改学生基本信息\n");
    printf("\n 2.修改学生成绩\n");
    printf("\n 3.返回上一层\n");
    printf("\n 请按键选择,回车确定\n");
    printf("*************************************************\n");
    //选择
    char choose[10];
    //选择表
    char choosetable[3][100] = {"1", "2", "3"};
    //选择是否合规
    bool judgechoose = false;
    do
    {
        scanf("%s", choose);
        for (int i = 0; i < 3; i++)
        {
            if (strcmp(choose, choosetable[i]) == 0)
            {
                judgechoose = true;
                break;
            }
            if (i == 3)
            {
                printf("\n选择不合规,请重新输入功能选项:");
            }
        }
    } while (!judgechoose);
    int tempID;
    switch (choose[0])
    {
    case '1':
        system("cls");
        printf("输入需要修改的ID:");
        scanf("%d", &tempID);
        ModifyBaseInformation(tempID);
        printf("\n\n\n******按任意键继续******\n\n");
        system("pause");
        system("cls");
        break;
    case '2':
        system("cls");
        printf("输入需要修改的ID:");
        scanf("%d", &tempID);
        ModifyScoreInformation(tempID);
        printf("\n\n\n******按任意键继续******\n\n");
        system("pause");
        system("cls");
        break;
    case '3':
        break;
    }
}

//管理员菜单
void RootMenu()
{
    system("cls");
    printf("**************************************************");
    printf("\n 1.输入学生成绩\n");
    printf("\n 2.更改学生信息\n");
    printf("\n 3.显示学生基本信息\n");
    printf("\n 4.成绩统计分析\n");
    printf("\n 5.统计各科各分数段人数\n");
    printf("\n 6.学生成绩排名\n");
    printf("\n 7.修改密码\n");
    printf("\n 8.返回上一层\n");
    printf("\n 请按键选择,回车确定\n");
    printf("*************************************************\n");
    //选择
    char choose[10];
    //选择表
    char choosetable[8][100] = {"1", "2", "3", "4", "5", "6", "7", "8"};
    //选择是否合规
    bool judgechoose = false;
    do
    {
        scanf("%s", choose);
        for (int i = 0; i < 8; i++)
        {
            if (strcmp(choose, choosetable[i]) == 0)
            {
                judgechoose = true;
                break;
            }
            if (i == 8)
            {
                printf("\n选择不合规,请重新输入功能选项:");
            }
        }
    } while (!judgechoose);
    switch (choose[0])
    {
    case '1':
        //输入学生信息
        system("cls");
        InputStudent();
        break;
    case '2':
        //修改学生信息
        system("cls");
        ModifyStudentInformationMenu();
        //printf("\n\n\n******按任意键继续******\n\n");
        system("pause");
        system("cls");
        break;
    case '3':
        //显示所有学生基本信息
        system("cls");
        ShowAllStudentInformation();
        // printf("\n\n\n******按任意键继续******\n\n");
        system("pause");
        system("cls");
        break;
    case '4':
        system("cls");
        for (int i = 0; i < 4; i++)
        {
            StatsAll(i);
        }
        //printf("\n\n\n******按任意键继续******\n\n");
        system("pause");
        system("cls");
        break;
    case '5':
        system("cls");
        for (int i = 0; i < 4; i++)
        {
            for (int j = 0, k = 0; j < 5; j++, k += 20)
            {
                printf("%s\t%d~%d\t人数%d\t\t", AllCourse[i], k, k + 20, StatsCourseScore(k + 20, k, i));
            }
            printf("\n");
        }
        // printf("\n\n\n******按任意键继续******\n\n");
        system("pause");
        system("cls");
        break;
    case '6':
        //显示总成绩排名
        system("cls");
        printf("总成绩:\n");
        SortAllScore(4);
        printf("\n\n\n");
        system("pause");
        system("cls");
        break;
    case '7':
        system("cls");
        if (ModifyPassword())
        {
            printf("\n修改完成\n");
        }
        else
        {
            printf("\n修改失败\n");
        }
        system("pause");
        break;
    case '8':
        Login();
        break;
    }
}
//学生菜单
void StudentMenu()
{
    system("cls");
    printf("**************************************************");
    printf("\n 1.查找成绩\n");
    printf("\n 2.成绩排名\n");
    printf("\n 3.返回上一层\n");
    printf("\n 请按键选择,回车确定\n");
    printf("*************************************************\n");
    char choose[10];                            //选择
    char choosetable[3][100] = {"1", "2", "3"}; //选择表
    bool judgechoose = false;                   //选择是否合规
    do
    {
        scanf("%s", choose);
        for (int i = 0; i < 3; i++)
        {
            if (strcmp(choose, choosetable[i]) == 0)
            {
                judgechoose = true;
                break;
            }
            if (i == 3)
            {
                printf("\n选择不合规,请重新输入功能选项:");
            }
        }
    } while (!judgechoose);
    char temp[20];
    int ID;
    int tempID;
    int tempbit = 0;
    ;
    switch (choose[0])
    {
    case '1':
        system("cls");
        printf("请输入要查询的学号或姓名:");
        scanf("%s", temp);
        ID = atoi(temp);
        tempID = ID;
        while (tempID > 0)
        {
            tempID = tempID / 10;
            tempbit++;
        }
        if (tempbit == strlen(temp))
        {
            ShowStudentScore(ID);
        }
        else
        {
            ShowStudentScore(temp);
        }

        printf("\n");
        system("pause");
        system("cls");
        break;
    case '2':
        system("cls");
        printf("请输入要查询的学号:");
        scanf("%d", &tempID);
        SeekStudentSort(tempID);
        printf("\n");
        system("pause");
        system("cls");
        break;
    case '3':
        Login();
        break;
    }
}

//密码验证
bool PasswordVerify()
{
    system("cls");
    //读出密码文件中的密码
    char password_buff[255];
    //输入的密码缓存区
    char inputpassword[255];
    FILE *fp;
    fp = fopen("PassWord.txt", "r"); //以追加的方式打开名字为mybook的二进制文件
    if (fp != NULL)
    {
        fgets(password_buff, 255, fp);
    }
    else
    {
        printf("配置文件错误");
    }
    fclose(fp); //关闭文件

    bool judgepassword = false;
    //获取输入的密码
    //printf("如若终止验证请输入'#'并回车\n请输入密码:");
    printf("%s", "请输入账号:\n");
    char number[255];
    scanf("%s", &number);
    printf("请输入密码:\n");
    //当前读取到的密码位数
    int passwordBit = 0;
    while (true)
    {
        while (true)
        {
            char temp;
            temp = getch();
            //回退按钮为8
            if (temp != 8)
            {
                if (temp != '\r')
                {
                    inputpassword[passwordBit] = temp;
                }
                else
                {
                    inputpassword[passwordBit] = '\0';
                    break;
                }
                passwordBit++;
                printf("*");
            }
            if (temp == 8 && passwordBit > 0)
            {
                printf("\b \b");
                passwordBit--;
            }
        }

        if (strcmp(inputpassword, password_buff) == 0)
        {
            return true;
        }
        else if (inputpassword[0] == '#' && inputpassword[1] == '\0')
        {
            return false;
        }
        printf("\n密码错误,请重新输入:");
        passwordBit = 0;
    }
}

void over() //退出软件
{
    char t;
    toxy(48, 11);
    printf("-----------------------");
    toxy(48, 12);
    printf("|   您确定要退出吗?  |");
    toxy(48, 14);
    printf("| 1.确定     2.取消   |");
    toxy(48, 15);
    printf("-----------------------");
    while (1)
    {
        t = getch(); //输入t
        switch (t)
        {
        case '1':
            system("cls");
            color(6);
            toxy(48, 10);
            printf("正在安全退出....");
            Sleep(1000); //暂停1秒
            system("cls");
            color(8);
            toxy(48, 10);
            printf("已安全退出软件");
            toxy(48, 12);
            printf("谢谢使用!");
            toxy(48, 14);
            printf("by-by^_^");
            exit(0);
            break; //终止程序
        case '2':
            Login();
            break; //调用函数,进入菜单
        default:
            break;
        }
    }
}

//修改密码
bool ModifyPassword()
{
    char inputPassword1[255];
    char inputPassword2[255];
    char *inputpassword;
    if (PasswordVerify())
    {

        int passwordBit = 0;
        while (true)
        {
            for (int k = 0; k < 2; k++)
            {
                if (k == 0)
                {
                    inputpassword = inputPassword1;
                    printf("\n请输入新密码,或输入#退出修改:");
                }
                else
                {
                    inputpassword = inputPassword2;
                    printf("\n请输入第二次输入新密码:");
                }
                while (true)
                {

                    char temp;
                    temp = getch();
                    //回退按钮为8
                    if (temp != 8)
                    {
                        if (temp != '\r')
                        {
                            inputpassword[passwordBit] = temp;
                        }
                        else
                        {
                            inputpassword[passwordBit] = '\0';
                            break;
                        }
                        passwordBit++;
                        printf("*");
                    }
                    if (temp == 8 && passwordBit > 0)
                    {
                        printf("\b \b");
                        passwordBit--;
                    }
                    if (k == 0 && inputPassword1[0] == '#' && inputPassword1[1] == '\0')
                    {
                        return false;
                    }
                }
                passwordBit = 0;
            }
            if (strcmp(inputPassword1, inputPassword2) == 0)
            {
                break;
            }
            printf("\n两次密码不一致,请重新输入:");
        }
        printf("\n修改成功!");

        FILE *fp;
        fp = fopen("PassWord.txt", "w+");
        if (fp != NULL)
        {
            fputs(inputPassword1, fp);
        }
        else
        {
            printf("配置文件错误");
        }
        fclose(fp); //关闭文件
        return true;
    }
    return false;
}

int main(int argc, char const *argv[]) //主函数
{
	//调整控制台编码,如果输出乱码,可选择是否执行
    system("chcp 65001");
    system("cls");
    ReadStudentAllTable();
    while (1)
    {
        Login();
    }
    return 0;
}

相当不错的一个成绩管理系统 #include #include #include #include using namespace std; enum {SUBJECT=5};//一共五门 typedef struct { char subject[10];//科目名称 int score;//科目成绩 }markinfo; typedef struct studentnode { markinfo mark[SUBJECT]; int totalmark; char name[10];//学生姓名 studentnode * next; }studentnode; class student { studentnode * head; public: student(); int addstudent(); ~student(); int countmark(); int sortbymark(); int save(); int show(); int display(); int readfiletolist(); int searchbyname(); }; student::student() //用构造函数来初始化。 { head=new studentnode; head->next=NULL; } //1.输入学生姓名、成绩等数据,并保存在链表中。 int student::addstudent() { studentnode * p; int i; char check; system("cls"); cout<<"**********************"<<endl; cout<<"输入学生信息:"<<endl; do { p=new studentnode; cin.ignore(); cout<name); i=0; p->totalmark=0; do { cout<mark[i].subject); cout<>p->mark[i].score; } while(p->mark[i].score>100||p->mark[i].scoretotalmark=p->totalmark+p->mark[i].score; getchar(); } while(++i!=SUBJECT); if(head->next==NULL) { head->next=p;p->next=NULL; } else { p->next=head->next; head->next=p; } cout<next; if(p==NULL) { cout<<"没有学生重新输入"<<endl;system("pause");return 0; } else { cout<<"***************"<<endl; cout<<"学生成绩汇总:"<<endl; while(p) { cout<<"姓名:"<name<<" 总成绩:"<totalmark<next; } } system("pause"); return 0; } //4.输出所有学生成绩一个文件中。 int student::save() { char address[35]; int i; studentnode * p=head->next; cout<<"输入保存的地址"<<endl; cin.ignore(); gets(address); ofstream fout; fout.open(address,ios::app|ios::out); while(p) { fout<<"*"; fout<name<<"*"; i=0; while(i!=SUBJECT) { fout<mark[i].subject<<"*"; fout<mark[i].score; i++; } //fout<next; } fout.flush(); fout.close(); cout<next; while(p) { s=p->next; delete p; p=s; } delete head; } //3.按照总成绩大小对记录进行排序 int student::sortbymark() { studentnode *move1=head->next; studentnode *move2,*max,*pre1,*pre2,*maxpre,*s=move1; if(head->next==NULL) { cout<<"没有记录,添加"<next!=NULL;pre1=move1,maxpre=pre1,move1=move1->next,max=move1) { for(pre2=move1,move2=move1->next;move2!=NULL;pre2=move2,move2=move2->next) if(move2->totalmark>max->totalmark) { maxpre=pre2; max=move2; } if(move1->next==max) //交换max和move1。 { pre1->next=max; move1->next=max->next; max->next=move1; move1=max; } else { s=move1->next; move1->next=max->next; max->next=s; maxpre->next=move1; pre1->next=max; move1=max; } } cout<<"已经按照从大到小排序"<next; int i; if(head->next==NULL){cout<<"没有学生记录,添加"<<endl;system("pause"); return 0;} else { while(p) { cout<<"姓名:"<name; i=1; while(i!=SUBJECT+1) { cout<<"科目:"<mark[i-1].subject; cout<<" 成绩:"<mark[i-1].score; i++; } cout<next; } } system("pause"); return 0; } //6:从文件按读取记录 int student::display() { ifstream fin; char buf[100]; char str[25]; cout<<"输入路径及文件名:"<<endl; cin.ignore(); gets(str); fin.open(str); if(!fin) { cout<<"没有此文件"<<endl; system("pause"); return 0; } while(fin) { fin.getline(buf,sizeof(buf)); cout<<buf<<endl; } system("pause"); return 0; } //8从文件中读取数据,并将数据保存在链表中 int student::readfiletolist() { ifstream fin; int i; char str[25]; cout<<"输入路径及文件名:"<<endl; cin.ignore(); gets(str); fin.open(str); if(!fin) { cout<<"没有此文件"<totalmark=0; fin.getline(p->name,100,'*'); i=0; while(i!=SUBJECT) { fin.getline(p->mark[i].subject,100,'*'); fin>>p->mark[i].score; p->totalmark+=p->mark[i].score; i++; } if(head->next==NULL) { head->next=p; p->next=NULL; } else { p=head->next; head->next=p; } } cout<<"信息已经保存在链表中"<next==NULL) { cout<<"没有学生添加或者从文件中读取"<next; char findname[10]; int i; cout<name,findname)) { cout<<"经查找,找到该生信息如下:"<<endl<<endl; cout<<"姓名:"<name; i=1; while(i!=SUBJECT+1) { cout<<"科目:"<mark[i-1].subject; cout<<" 成绩:"<mark[i-1].score; i++; } cout<next; } cout<<"没有此学生添加或者从文件中读取"<<endl; system("pause"); return 0; } int showmenu() { int choice; char * menu[9]={ "1:输入学生成绩保存到链表\n", "2:计算每位学生成绩\n", "3:按照总成绩大小对记录进行排序\n", "4:输出所有学生成绩一个文件中\n", "5:显示新输入的学生信息\n", "6:从文件中读取信息\n", "7:将文件信息保存在链表中\n", "8:根据姓名查找学生记录\n", "9:结束程序\n" }; cout<<" "<<"*****************************************************"<<endl; cout<<" *"<<" "<<"学生成绩管理系统"<<" *"<<endl; cout<<" "<<"*****************************************************"<<endl; for(choice=0;choice<9;choice++) cout<<" "<<menu[choice]; cout<<" "<<"*****************************************************"<<endl; cout<<"please choose to continue"<>choice; } while(choice>9||choice<1); return choice; } int main() { int menuitem,flag=1; student stu; while(flag) { system("cls"); menuitem=showmenu(); switch(menuitem) { case 1:{stu.addstudent();break;} case 2:{stu.countmark();break;} case 3:{stu.sortbymark();break;} case 4:{stu.save();break;} case 5:{stu.show();break;} case 6:{stu.display();break;} case 7:{stu.readfiletolist();break;} case 8:{stu.searchbyname();break;} case 9:{flag=0;break;} } } return 0; }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值