c++学籍管理程序

#include "stdafx.h"
#include<stdio.h>
#include <stdlib.h>
#include<Windows.h>
#include<conio.h>

#include<string.h>
struct TEACHER
{
    char ID[20];
    char Name[20];
    char lesson[20];

}teacher[10];
struct ZHMM
{
    char zh[20];
    char mm[20];
    char name[20];
}zhmm[100];
struct Student
{
    char ID[20];
    char Name[20];
    char major[20];
    char grade[10];
}student[100];
struct LESSON
{
    char id[20];
    char name[20];
    char teacher[20];
    int stu;
}lesson[20];
struct SCORE
{
    char id[20];
    char lesson[20];
    int value;
}score[10];
int passcheck(int x)
{
    int i = 0; char pw[40]; char ch;
    while (1) {

        ch = getch();
        if (ch == 13 || i >= 39) break;
        switch (ch) {
        case 8:
            if (i>0) {
                i--;
                pw[i] = 0;
                printf("\b \b");
            }
            break;
        default:
            pw[i] = ch;
            i++;
            pw[i] = 0;
            printf("*");
            break;
        }
    }

    FILE *fp; int index = -1;
    if ((fp = fopen("zhmm.txt", "r")) == NULL);

    else {

        if (fread(&zhmm[index + 1], sizeof(struct ZHMM), 1, fp) == 1)
        {
            index++;
        }
        fclose(fp);
    }
    if (strcmp(zhmm[x].mm, pw) == 0) return 1; else return 0;

}
void lesso(void)
{

    FILE *fp;
    
    while (1)//控制退出
    {
        system("cls");
        for (int i = 0; i < 20; i++) lesson[i].stu = 0;
        int index = -1;
        printf("现有的课程如下:\n");
        printf("*******************************************************************\n");
        if ((fp = fopen("lesson.txt", "r")) == NULL)
            printf("课程编号 \t课程名  \t任课老师 \t学生人数\n");
        else
        {
            while (fread(&lesson[index + 1], sizeof(struct LESSON), 1, fp) == 1)
            {
                index++;
            }
            printf("课程编号 \t课程名  \t任课老师 \t学生人数\n");
            for (int i = 0; i <= index; i++)
            {
                printf("%4s%17s%17s%17d\n", lesson[i].id, lesson[i].name, lesson[i].teacher, lesson[i].stu);
            }
            fclose(fp);
        }
        printf("*******************************************************************\n\n");

        printf("1.增添   2.删除  3.返回\n");
        char t = getch();
        if (t == '1')
        {
            printf("课程编号:");
            scanf("%s", lesson[index + 1].id);
            printf("课程名:");
            scanf("%s", lesson[index + 1].name);
            printf("任课老师:");
            scanf("%s", lesson[index + 1].teacher);
            ///////////////////////////////////////////
            FILE *FP; int index2=-1;
            if ((FP = fopen("teacher.txt", "r")) == NULL);
            else
            {
                
                while (fread(&teacher[index2 + 1], sizeof(struct TEACHER), 1, FP) == 1)
                {
                    index2++;
                }
                fclose(FP);
            }
            int finded = 0;
            for (int i = 0; i <= index2; i++)
            {
                if (strcmp(lesson[index + 1].teacher, teacher[i].Name) == 0)
                {
                    finded=1;  
                }
            }
            if (finded == 0) { printf("该教师不存在"); index--; getchar(); getchar(); }
            
        }
        else if (t == '2')
        {
            char temp[20]; int t=0;
            printf("请输入要删除课程编号:");
            scanf("%s", temp);
            for (int i = 0; i <= index; i++)
            {

                if (strcmp(lesson[i].id,temp)==0)
                {
                    for (int j = i; j <= index; j++)
                    {
                        lesson[j] = lesson[j + 1];
                    }
                    index--; t =1;//是否有该课程
                    break;
                }
            }
            
            index--;//迎合下面文件写入的方式
            if (t ==0)
            {
                printf("该课程不存在");
                getchar(); getchar();
            }//停顿;
        }
        else if (t == '3') break;//退出课程管理;
        else index--;
        fp = fopen("lesson.txt", "w");
        for (int i = 0; i <= index + 1; i++)
            fwrite(&lesson[i], sizeof(struct LESSON), 1, fp);
        fclose(fp);
    }
}
void stusso(int x)
{
    FILE *fp;
    while (1)
    {
        int index1 = -1;
        if ((fp = fopen("score.txt", "r")) == NULL);
        else
        {
            while (fread(&score[index1 + 1], sizeof(struct SCORE), 1, fp) == 1)
            {
                index1++;
            }
            fclose(fp);
        }
        system("cls");
        for (int i = 0; i < 20; i++) lesson[i].stu = 0;
        int index = -1;
        printf("现有的课程如下:\n");
        printf("*******************************************************************\n");
        if ((fp = fopen("lesson.txt", "r")) == NULL)
            printf("课程编号 \t课程名  \t任课老师 \t学生人数\n");
        else
        {
            while (fread(&lesson[index + 1], sizeof(struct LESSON), 1, fp) == 1)
            {
                index++;
            }
            printf("课程编号 \t课程名  \t任课老师 \t学生人数\n");
            for (int i = 0; i <= index; i++)
            {
                printf("%4s%17s%17s%17d\n", lesson[i].id, lesson[i].name, lesson[i].teacher, lesson[i].stu);
            }
            fclose(fp);
        }
        printf("*******************************************************************\n\n");
        printf("1.选择   2.取消  3.返回\n");
        char t = getch();
        if (t == '1')
        {
            printf("课程编号:");
            scanf("%s", score[index1+1].lesson);
            int finded = 0; int i;
            for (i=0; i <= index; i++)
            {
                if (strcmp(score[index1+1].lesson, lesson[i].id) == 0)
                {
                    finded = 1; break;
                }
            }
            if (finded)
            {
                strcpy(score[index1+1].id, zhmm[x].zh);
                lesson[i].stu++; index1++;
                printf("成功\n"); system("pause");
            }
            else { printf("课程不存在\n"); system("pause"); }
        }
        else if (t == '2')
        {
            printf("课程编号:");
            char temp[20];
            scanf("%s", temp);
            int finded = 0; int k;
            for (k = 0; k <= index1; k++)
            {
                if (strcmp(temp,score[k].lesson) == 0)
                {
                    finded = 1; break;
                }
            }
            if (finded)
            {
                //锁定取消的课程id;
                int i;
                for (i = 0; i <= index; i++)
                {
                    if (strcmp(score[k].lesson, lesson[i].id) == 0)
                    {
                        break;
                    }
                }
                lesson[i].stu--;
                for (int j = k; j <= index1; j++)
                {
                    score[j] = score[j + 1];
                }
                index1--; 
                printf("成功\n"); system("pause");
            }
            else { printf("尚未选择该课程\n"); system("pause"); }
        }
        else if (t == '3') break;
        fp = fopen("lesson.txt", "w");
        for (int i = 0; i <= index; i++)
            fwrite(&lesson[i], sizeof(struct LESSON), 1, fp);
        fclose(fp);
        fp = fopen("score.txt", "w");
        for (int i = 0; i <= index1; i++)
            fwrite(&score[i], sizeof(struct SCORE), 1, fp);
        fclose(fp);
    }
}
void sturefer(int x)
{
    FILE *fp;
    
        int index1 = -1;
        if ((fp = fopen("score.txt", "r")) == NULL);
        else
        {
            while (fread(&score[index1 + 1], sizeof(struct SCORE), 1, fp) == 1)
            {
                index1++;
            }
            fclose(fp);
        }
        system("cls");
        for (int i = 0; i < 20; i++) lesson[i].stu = 0;
        int index = -1;
        printf("你选择的课程如下:\n");
        printf("*******************************************************************\n");
        if ((fp = fopen("lesson.txt", "r")) == NULL)
            printf("课程编号 \t课程名  \t任课老师 \t总成绩\n");
        else
        {
            while (fread(&lesson[index + 1], sizeof(struct LESSON), 1, fp) == 1)
            {
                index++;
            }
            fclose(fp);
            printf("课程编号 \t课程名  \t任课老师 \t总成绩\n");
            int i,j;
            for (i=0;i<=index1;i++)
                if (strcmp(zhmm[x].zh, score[i].id) == 0) 
                { 
                    j = 0;
                    for (j = 0; j <= index; j++)
                    {
                        if (strcmp(score[i].lesson, lesson[j].id) == 0)
                        {
                            printf("%4s%17s%17s%17d\n", lesson[j].id, lesson[j].name, lesson[j].teacher,score[i].value);
                        }
                    }
                }//找到该学生id对应的索引值,从而找到课程名
        }            
        printf("*******************************************************************\n\n");
        system("pause");
    
}

void stud(void)
{
    
    FILE *fp;

    while (1)
    {
        system("cls"); int index = -1;
        if ((fp = fopen("student.txt", "r")) == NULL)
            printf("目前尚未录入学生\n");
        else
        {
            while (fread(&student[index + 1], sizeof(struct Student), 1, fp) == 1)
            {
                index++;
            }
            fclose(fp);
        }
        printf("1.查询/清除\n2.录入\n3.返回\n");
        char t = getch(); int search[20] = { 0 }; int s;//记录查询的索引值
        if (t == '1')
        {
            while (1)
            {
                system("cls");
                printf("1.按年级查询\n2.按姓名查询\n3.按学号查询\n4.按专业查询\n5.全部查询\n6.返回\n");
                char t = getch();
                if (t == '1')
                {
                    printf("请输入年级:");
                    char temp[10]; s = 0;
                    scanf("%s", temp);
                    for (int i = 0; i <= index; i++)
                    {
                        if (strcmp(student[i].grade, temp) == 0) { search[s] = i; s++; }
                    }
                }
                else if (t == '2')
                {
                    printf("请输入姓名:");
                    char temp[10]; s = 0;
                    scanf("%s", temp);
                    for (int i = 0; i <= index; i++)
                    {
                        if (strcmp(student[i].Name, temp) == 0) { search[s] = i; s++; }
                    }
                }
                else if (t == '3')
                {
                    printf("请输入姓名:");
                    char temp[10]; s = 0;
                    scanf("%s", temp);
                    for (int i = 0; i <= index; i++)
                    {
                        if (strcmp(student[i].ID, temp) == 0) { search[s] = i; s++; }
                    }
                }
                else if (t == '4')
                {
                    printf("请输入姓名:");
                    char temp[10]; s = 0;
                    scanf("%s", temp);
                    for (int i = 0; i <= index; i++)
                    {
                        if (strcmp(student[i].major, temp) == 0) { search[s] = i; s++; }
                    }
                }
                else if (t == '5')
                {
                    s = 0;
                    for (int i = 0; i <= index; i++)
                    {
                        search[s] = i; s++;
                    }
                }
                else if (t == '6') break;
                printf("\n\n");
                printf("查询结果:\n");
                printf("**************************************************************\n");
                printf("年级         姓名       学号        专业\n");
                for (int i = 0; i <= s - 1; i++)
                {
                    printf("%s%15s%10s%15s\n", student[search[i]].grade, student[search[i]].Name, student[search[i]].ID, student[search[i]].major);
                }
                getchar();
                printf("需要删除学生信息?(y/n)\n");
                char tyn;
                tyn = getch();
                while (1)
                {
                    char temp[10]; int tp = 0;
                    if (tyn == 'y' || tyn == 'Y')
                    {
                        printf("请输入学号:");
                        scanf("%s", temp); getchar();
                        for (int i = 0; i <= index; i++)
                        {
                            if (strcmp(student[i].ID, temp) == 0)
                            {
                                for (int j = i; j <= index; j++)
                                {
                                    student[j] = student[j + 1];
                                }
                                index--; tp = -1;//是否有该学生
                                break;
                            }

                        }
                        if (tp != -1) printf("该学生不存在\n");
                        printf("continue?y/n\n"); tyn = getch();
                    }
                    else if (tyn == 'n' || tyn == 'N')break;
                }

            }
            fp = fopen("student.txt", "w");
            for (int i = 0; i <= index; i++)
                fwrite(&student[i], sizeof(struct Student), 1, fp);
            fclose(fp);
        }
        else if (t == '2')
        {
            printf("请输入年级:"); scanf("%s", student[index + 1].grade);
            printf("请输入姓名:"); scanf("%s", student[index + 1].Name);
            printf("请输入学号:"); scanf("%s", student[index + 1].ID);
            printf("请输入专业:"); scanf("%s", student[index + 1].major);
            fp = fopen("student.txt", "w");
            for (int i = 0; i <= index + 1; i++)
                fwrite(&student[i], sizeof(struct Student), 1, fp);
            fclose(fp);
        }
        else if (t == '3') break;

    }//while
}
void teach(void)
{
    
    FILE *fp;

    while (1)
    {
        system("cls"); int index = -1;
        if ((fp = fopen("teacher.txt", "r")) == NULL)
            printf("目前尚未录入教师\n");
        else
        {
            while (fread(&teacher[index + 1], sizeof(struct TEACHER), 1, fp) == 1)
            {
                index++;
            }
            fclose(fp);
        }
        printf("1.查询/清除\n2.录入\n3.返回\n");
        char t = getch();
        if (t == '1')
        {
            while (1)
            {
                system("cls");
                printf("查询结果:\n");
                printf("**************************************************************\n");
                printf("教师号       姓名        \n");
                for (int i = 0; i <= index; i++)
                {
                    printf("%s%15s\n", teacher[i].ID, teacher[i].Name);
                }
                printf("需要删除教师信息?(y/n)\n");
                char tyn;
                
                    tyn = getch();
                    char temp[10]; int tp = 0;
                    if (tyn == 'y' || tyn == 'Y')
                    {
                        printf("请输入教师号:");
                        scanf("%s", temp); getchar();
                        for (int i = 0; i <= index; i++)
                        {
                            if (strcmp(teacher[i].ID, temp) == 0)
                            {
                                for (int j = i; j <= index; j++)
                                {
                                    teacher[j] = teacher[j + 1];
                                }
                                index--; tp = -1;//是否有该教师
                                break;
                            }
                        }
                        if (tp != -1) printf("该教师不存在\n");
                        printf("continue?y/n\n"); tyn = getch();
                    }
                    else if (tyn == 'n' || tyn == 'N')break;
                    
                    
            }
            fp = fopen("teacher.txt", "w");
            for (int i = 0; i <= index; i++)
                fwrite(&teacher[i], sizeof(struct TEACHER), 1, fp);
            fclose(fp);
        }
        else if (t == '2')
        {

            printf("请输入教师号:"); scanf("%s", teacher[index + 1].ID);
            printf("请输入姓名:"); scanf("%s", teacher[index + 1].Name);

            fp = fopen("teacher.txt", "w");
            for (int i = 0; i <= index + 1; i++)
                fwrite(&teacher[i], sizeof(struct TEACHER), 1, fp);
            fclose(fp);
        }
        else if (t == '3') break;

    }//while
}
void teasson(int x)
{
    FILE *fp;
    while (1)
    {
        system("cls");
        for (int i = 0; i < 20; i++) lesson[i].stu = 0;
        FILE *fp;
        int index1 = -1;
        if ((fp = fopen("score.txt", "r")) == NULL);
        else
        {
            while (fread(&score[index1 + 1], sizeof(struct SCORE), 1, fp) == 1)
            {
                index1++;
            }
            fclose(fp);
        }
        int index = -1;
        if ((fp = fopen("lesson.txt", "r")) == NULL);
        else {
            while (fread(&lesson[index + 1], sizeof(struct LESSON), 1, fp) == 1)
            {
                index++;
            }
            fclose(fp);
        }
        int index2 = -1;
        if ((fp = fopen("student.txt", "r")) == NULL);
        else {
            while (fread(&student[index2 + 1], sizeof(struct Student), 1, fp) == 1)
            {
                index2++;
            }
            fclose(fp);
        }

        printf("您的课程:\n");
        printf("*******************************************************************\n");
        printf("课程编号 \t课程名\n");
        for (int i = 0; i <= index; i++)
        {
            if (strcmp(lesson[i].teacher, zhmm[x].name) == 0)
            {
                printf("%4s%17s\n", lesson[i].id, lesson[i].name);
            }
        }
        printf("*******************************************************************\n");
        printf("1.选择\n2.返回\n");
        int t = getch();
        if (t == '1')
        {
            printf("课程编号:");
            char temp[20]; int finded = 0;
            scanf("%s", temp); getchar();
            int i;
            for (i = 0; i <= index; i++)
            {
                if (strcmp(temp, lesson[i].id) == 0)
                {
                    finded = 1; break;
                }

            }
            while (1)
            {
                system("cls");
                printf("课程编号:%s\t课程名%s\n", lesson[i].id, lesson[i].name);
                if (finded)
                {
                    printf("1.批量输入\n2.单个修改\n3.返回\n");
                    char t = getch();
                    if (t == '1')
                    {
                        printf("*******************************************************************\n");
                        printf("学生学号 \t学生姓名  \t成绩:\n");
                        for (i = 0; i <= index1; i++)
                        {
                            if (strcmp(score[i].lesson, temp) == 0)
                            {
                                int j;//学生索引值
                                for (j = 0; j <= index2; j++)
                                {
                                    if (strcmp(score[i].id, student[j].ID) == 0)
                                    {
                                        break;
                                    }
                                }
                                printf("%4s%17s \t\t", student[j].ID, student[j].Name);
                                scanf("%d", &score[i].value);
                                if (score[i].value == -1) { break; }
                            }
                        }
                        printf("结束\n"); system("pause");
                    }

                    else if (t == '2')
                    {
                        while (1)
                        {
                            char tem[20];
                            printf("学生学号:"); scanf("%s", tem);
                            for (i = 0; i <= index1; i++)
                            {
                                if (strcmp(score[i].lesson, temp) == 0)
                                {
                                    if (strcmp(score[i].id, tem) == 0)
                                    {
                                        printf("    成绩:");
                                        scanf("%d", &score[i].value); getchar();
                                    }
                                    else printf("该学生不存在");
                                    break;
                                }
                            }
                            printf("结束?y/n\n");
                            char t = getch();
                            if (t == 'Y' || t == 'y')break;
                        }
                        system("pause");
                    }
                    else if (t == '3')break;

                }
                else {
                    printf("你没有开设此课程"); system("pause");
                }
            }
                printf("*******************************************************************\n");
                system("pause");
            
        }
        else if (t == '2')break;
        fp = fopen("score.txt", "w");
        for (int i = 0; i <= index1; i++)
            fwrite(&score[i], sizeof(struct SCORE), 1, fp);
        fclose(fp);
    }

}

void tearefer(int x)///////////////////////////////////////////////////
{
    while (1)
    {
        system("cls");
        for (int i = 0; i < 20; i++) lesson[i].stu = 0;
        FILE *fp;
        int index1 = -1;
        if ((fp = fopen("score.txt", "r")) == NULL);
        else
        {
            while (fread(&score[index1 + 1], sizeof(struct SCORE), 1, fp) == 1)
            {
                index1++;
            }
            fclose(fp);
        }
        int index = -1;
        if ((fp = fopen("lesson.txt", "r")) == NULL);
        else {
            while (fread(&lesson[index + 1], sizeof(struct LESSON), 1, fp) == 1)
            {
                index++;
            }
            fclose(fp);
        }
        int index2 = -1;
        if ((fp = fopen("student.txt", "r")) == NULL);
        else {
            while (fread(&student[index2 + 1], sizeof(struct Student), 1, fp) == 1)
            {
                index2++;
            }
            fclose(fp);
        }

        printf("您的课程:\n");
        printf("*******************************************************************\n");
        printf("课程编号 \t课程名\n");
        for (int i = 0; i <= index; i++)
        {
            if (strcmp(lesson[i].teacher, zhmm[x].name) == 0)
            {
                printf("%4s%17s\n", lesson[i].id, lesson[i].name);
            }
        }
        printf("*******************************************************************\n");
        printf("1.选择\n2.返回\n");
        int t = getch();
        if (t == '1')
        {
            printf("课程编号:");
            char temp[20]; int finded = 0;
            scanf("%s", temp); getchar();
            int i;
            for ( i = 0; i <= index; i++)
            {
                if (strcmp(temp, lesson[i].id) == 0)
                {
                    finded = 1; break;
                }

            }
            
            system("cls");
            printf("课程编号:%s\t课程名%s\n",lesson[i].id,lesson[i].name);
            printf("*******************************************************************\n");
            printf("学生学号 \t学生姓名  \t总成绩\n");
            if (finded)
            {
                
                for ( i = 0; i <= index1; i++)
                {
                    if (strcmp(score[i].lesson, temp) == 0)
                    {
                        int j;//学生索引值
                        for (j = 0; j <= index2; j++)
                        {
                            if (strcmp(score[i].id, student[j].ID) == 0)
                            {
                                 break;
                            }
                        }
                        printf("%4s%17s%17d\n", student[j].ID, student[j].Name, score[i].value);
                        
                    }
                }
            }
            else {
                printf("你没有开设此课程"); system("pause");
            }
            printf("*******************************************************************\n");
            system("pause");

        }
        else if (t == '2')break;
    }

}
void passchange(int x)
{
    FILE *fp; int index = -1;
    while (1)
    {
        index = -1;
        system("cls");
        printf("请输入原密码:");
        if (passcheck(x))
        {
            char temp[20];
            printf("\n请输入新密码:");
            int i = 0; char pw[40]; char ch;
            while (1) {

                ch = getch();
                if (ch == 13 || i >= 39) break;
                switch (ch) {
                case 8:
                    if (i>0) {
                        i--;
                        pw[i] = 0;
                        printf("\b \b");
                    }
                    break;
                default:
                    pw[i] = ch;
                    i++;
                    pw[i] = 0;
                    printf("*");
                    break;
                }
            }

            fp = fopen("zhmm.txt", "r");
            index = -1;
            while (fread(&zhmm[index + 1], sizeof(struct ZHMM), 1, fp) == 1)
            {
                index++;
            }
            fclose(fp);
            strcpy(zhmm[x].mm, pw);

            fp = fopen("zhmm.txt", "w");
            for (int i = 0; i <= index; i++) {
                fwrite(&zhmm[i], sizeof(struct ZHMM), 1, fp);
            }
            fclose(fp);

            printf("\n成功修改\n"); system("pause"); 
            printf("%s", zhmm[x].mm); break;
        }
        else { printf("\n密码错误,continue?Y/N"); int t = getch(); if (t == 'Y' || t == 'y'); else break; }

    }
}

int main(void)
{

    int mm, zh = 1;
    SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
    while (zh == 1)//账号充输循环
    {
        system("cls");
        mm = 1;//密码重输循环
        printf("***************************************************\n");
        printf("*\t\t欢迎使用学分制系统\t\t  *\n");
        printf("***************************************************\n");

        printf("请输入账号:");//1是管理员
        for (int i = 0; i <= 100; i++)//初始化密码
        {
            strcpy(zhmm[i].mm, "2");
        }
        FILE *fp;
        int index = -1;
        if ((fp = fopen("zhmm.txt", "r")) == NULL)
        {
            strcpy(zhmm[0].zh, "1");
            strcpy(zhmm[0].mm, "1");
            strcpy(zhmm[0].name, "administration");
        }
        else {
            index = -1;
            while (fread(&zhmm[index + 1], sizeof(struct ZHMM), 1, fp) == 1)//整天把while写成if, 哇,好气
            {
                index++;

            }
            fclose(fp);
        }
        index = -1;
        if ((fp = fopen("teacher.txt", "r")) == NULL);
        else
        {
            while (fread(&teacher[index + 1], sizeof(struct TEACHER), 1, fp) == 1)
            {
                index++;
            }
            fclose(fp);
        }
        int s = 1;
        for (int i = 0; i <= index; i++)
        {

            
            strcpy(zhmm[s].zh, teacher[i].ID);
            strcpy(zhmm[s].name, teacher[i].Name);
            s++;
            //printf("%s\n", teacher[i].ID);
            //printf("%s\n", zhmm[s-1].zh);
        }

        index = -1;
        if ((fp = fopen("student.txt", "r")) == NULL);
        else
        {
            while (fread(&student[index + 1], sizeof(struct Student), 1, fp) == 1)
            {
                index++;
            }
            fclose(fp);
        }
        for (int i = 0; i <= index; i++)
        {
            strcpy(zhmm[s].zh, student[i].ID);
            strcpy(zhmm[s].name, student[i].Name);
            s++;
        }
        
        fp = fopen("zhmm.txt", "w");//写入,观察一波;
        for (int i = 0; i <= s; i++) {
            fwrite(&zhmm[i], sizeof(struct ZHMM), 1, fp);
        }
        fclose(fp);

        int finded = 0; int i = 0;
        char temp[20];
        scanf("%s", temp); 
        for (i = 0; i <= s; i++)
        {
            if (strcmp(zhmm[i].zh, temp) == 0)
            {
                finded = 1; break;
            }
        }
        while (mm == 1)
        {

            if (finded && (i == 0))
            {
                printf("管理员密码:");
                if (passcheck(i))
                {
                    
                    while (1)
                    {
                        system("cls");
                        printf("\t登陆成功\n");
                        printf("1.课程管理\n");
                        printf("2.学生管理\n");
                        printf("3.教师管理\n");
                        printf("4.更改密码\n");
                        printf("5.注销\n");
                        printf("6.退出\n");
                        char ch = getch();
                        if (ch == '1')lesso();
                        else if (ch == '2')stud();
                        else if (ch == '3')teach();
                        else if (ch == '4')passchange(0);
                        else if (ch == '5') { mm = 0; break; }
                        else if (ch == '6') { mm = 0; zh = 0; break; }
                    }
                }
                else
                {
                    getchar();
                    printf("\n密码错误,输入1退出程序,输入2重输账号,回车重输密码\n");
                    int ch = getch();
                    if (ch == '1') { zh = 0; mm = 0; }
                    if (ch == '2') {
                        mm = 0; system("cls");
                    }
                }

            }
            else if (finded)
            {
                if ((fp = fopen("zhmm.txt", "r")) == NULL);
                else {
                    index = -1;
                    while (fread(&zhmm[index + 1], sizeof(struct ZHMM), 1, fp) == 1)
                    {
                        index++;
                    }
                    fclose(fp);
                }
                int index1 = -1;

                if ((fp = fopen("student.txt", "r")) == NULL);
                else
                {
                    while (fread(&student[index1 + 1], sizeof(struct Student), 1, fp) == 1)
                    {
                        index1++;
                    }
                    fclose(fp);
                }
                int index2 = -1;
                if ((fp = fopen("teacher.txt", "r")) == NULL);
                else
                {
                    while (fread(&teacher[index2 + 1], sizeof(struct TEACHER), 1, fp) == 1)
                    {
                        index2++;
                    }
                    fclose(fp);
                }
                /////////////////////////////////////////////////////////////////
                //判断是学生还是老师并找到他们所在数组的索引值
                int j, stu = 0;

                    for ( j = 0; j <= index1; j++)
                    {
                        if (strcmp(temp, student[j].ID) == 0) {
                            stu = 1; break;
                        }
                    }
                    
                int k, tea = 0;

                    for (k = 0; k <= index2; k++)
                    {
                        if (strcmp(temp, teacher[k].ID) == 0) {
                            tea = 1; break;
                        }
                    }
                printf("      密码:");
                if (passcheck(i))
                {
                    if (stu)
                    {
                        while (1)
                        {
                            system("cls");
                            printf("%s,您好\n", student[j].Name);
                            printf("1.选课\n2.查看课程及成绩\n3.更改密码\n4.注销\n");
                            char t;
                            t = getch();
                            if (t == '1')
                            {
                                stusso(i);
                            }
                            else if (t == '2')
                            {
                                sturefer(i);
                            }
                            else if (t == '3')
                            {
                                passchange(i);
                            }
                            else if (t == '4') { mm = 0; break; }
                        }
                    }
                    else if (tea)
                    {
                        while (1)
                        {
                            system("cls");
                            printf("%s,您好\n", teacher[k].Name);
                            printf("1.查看课程及学生信息\n2.登记学生成绩\n3.更改密码\n4.注销\n");
                            char t;
                            t = getch();
                            if (t == '1')
                            {
                                tearefer(i);
                            }
                            else if (t == '2')
                            {
                                teasson(i);
                            }
                            else if (t == '3')
                            {
                                passchange(i);
                            }
                            else if (t == '4') { mm = 0; break; }
                        }
                    }
                }
                else {
                    getchar();
                    printf("\n密码错误,输入1退出程序,输入2重输账号,回车重输密码\n");
                    int ch = getch();
                    if (ch == '1') { zh = 0; mm = 0; }
                    if (ch == '2') {
                        mm = 0; system("cls");
                    }
                }
                
            }
            else
            {

                getchar(); 
                mm = 0;
            }
            
        }
        fp = fopen("zhmm.txt", "w");//写入,观察一波;
        for (int i = 0; i <= s; i++) {
            fwrite(&zhmm[i], sizeof(struct ZHMM), 1, fp);
        }
        fclose(fp);
    }//zh
}

 

posted @ 2019-07-30 11:15  淇实是我  阅读(169)  评论(0编辑  收藏  举报