栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言学生信息成绩管理系统

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言学生信息成绩管理系统

    首先请允许我介绍一下这是一个比较年幼但是相对比较稳固的系统。它同样也会显得有点业余等等许多其它的问题!然而,它的这些问题都只是第二类问题,我是说,它本身是一个非常健全的系统,它需要的只是优化。

    在该系统的project文件目录下,创建AccountData文本文件,AccountData.txt是保存账号的文件。再创建一个StudentData文本文件,StudentData.txt是保存学生信息和成绩的文件。然后就可以完美运行了。

typedef struct account
{
    int number;
    char password[16];
}Account;
Account acc[M1];登录账号结构体

typedef struct score
{
    int HigherMathematics;
    int CollegeEnglish;
    int UniversityPhysics;
}Score;成绩结构体
typedef struct student
{
    char grade[20];
    char name[10];
    int id;
    char sex;
    int birthday;
    Score s;
}Stu;
Stu stu[M2];学生信息结构体
 

#include 
#include 
#include
#define M1 10
#define M2 200
void Menu();

typedef struct account
{
    int number;
    char password[16];
}Account;
Account acc[M1];

typedef struct score
{
    int HigherMathematics;
    int CollegeEnglish;
    int UniversityPhysics;
}Score;
typedef struct student
{
    char grade[20];
    char name[10];
    int id;
    char sex;
    int birthday;
    Score s;
}Stu;
Stu stu[M2];

void AccountDataImport()
{
    int i=0;
    FILE *fs=fopen("AccountData.txt","r");
    if(fs==NULL){
        printf("can't open file:AccountData.txt!n");
        exit(0);
    }
    while(!feof(fs)){
        fscanf(fs,"%d %sn",&acc[i].number,acc[i].password);
        i++;
    }
    fclose(fs);
}

void AccountDataSave()
{
    Account *p=&acc;
    FILE *fp;
    fp=fopen("AccountData.txt","w");
    if(fp==NULL){
        printf("can't open file!n");
        exit(0);
    }
    while(p->number){
        fprintf(fp,"%d %sn",p->number,p->password);
        p++;
    }
    fclose(fp);
}

void StudentDataImport()
{
    int i=0;
    FILE *fs=fopen("StudentData.txt","r");
    if(fs==NULL){
        printf("can't open file:StudentData.txt!n");
        exit(0);
    }
    while(!feof(fs)){
        fscanf(fs,"%s %s %d %c %d ",stu[i].grade,stu[i].name,&stu[i].id,&stu[i].sex,&stu[i].birthday);
        fscanf(fs,"%d %d %dn",&stu[i].s.HigherMathematics,&stu[i].s.CollegeEnglish,&stu[i].s.UniversityPhysics);
        printf("%s %s %d %c %d ",stu[i].grade,stu[i].name,stu[i].id,stu[i].sex,stu[i].birthday);
        printf("%d %d %dn",stu[i].s.HigherMathematics,stu[i].s.CollegeEnglish,stu[i].s.UniversityPhysics);
        i++;
    }
    fclose(fs);
}

void StudentDataSave()
{
    Stu *p=&stu;
    FILE *fp;
    fp=fopen("StudentData.txt","w");
    if(fp==NULL){
        printf("can't open file:StudentData.txt!n");
        exit(0);
    }
    while(p->birthday){
        fprintf(fp,"%s %s %d %c %d ",p->grade,p->name,p->id,p->sex,p->birthday);
        fprintf(fp,"%d %d %dn",p->s.HigherMathematics,p->s.CollegeEnglish,p->s.UniversityPhysics);
        p++;
    }
    fclose(fp);
}

void Login()
{
    int choice;
    int number;
    int flash=0;
    int count=0;
    char password[16];
    char password2[16];
    Account *p=&acc;
    AccountDataImport();
    printf("If you already have an account,please log in!'1'Loginn");
    printf("Or you can also register an account!'0'registern");
    scanf("%d",&choice);
    if(choice){
        system("cls");
        printf("Login account!n");
        printf("Initial account:%d %sn",p->number,p->password);
        printf("Please enter your account number!n");
        scanf("%d",&number);
        while(p->number){
            if(p->number==number){
                flash=1;
                break;
            }
            p++;
        }
        if(flash){
            printf("Please enter you account password!n");
            scanf("%s",password);
            while(strcmp(p->password,password)!=0){
                printf("Wrong password,Re-enter!n");
                scanf("%s",password);
                count++;
                if(count>3){
                    printf("Too many cypher errors.n");
                    printf("Please re-enter!n");
                    Login();
                    break;
                }
            }
            system("cls");
            printf("The password is correct!n");


        }

        if(!flash){
            printf("The account does not exist!n");
            printf("Please re-enter!n");
            Login();
        }
    }
    else{
        system("cls");
        printf("Register account!n");
        printf("Please set the account number you want to register!n");
        scanf("%d",&number);
        while(p->number){
            if(p->number==number){
                printf("The number already exists!n");
                printf("Please go back and re-enter!n");
                Login();
                break;
            }
            p++;
        }
        printf("Please enter you account password!n");
        scanf("%s",password);
        printf("Please enter the password again!n");
        scanf("%s",password2);
        while(strcmp(password,password2)){
            printf("The password entered twice is inconsistent!n");
            printf("Please re-enter again!n");
            scanf("%s",password2);
        }
        p->number=number;
        strcpy(p->password,password);
        printf("You account:%d %sn",p->number,p->password);
        printf("Please go back and re-enter!n");
        AccountDataSave();
        Login();

    }

}

void AddInformation(Stu *p)
{
    int choice;
    int id,birthday,Math,English,Physics;
    char grade[20];
    char name[10];
    char sex;
    printf("%s %s %d %c %d",p->grade,p->name,p->id,p->sex,p->birthday);
    printf(" %d %d %dn",p->s.HigherMathematics,p->s.CollegeEnglish,p->s.UniversityPhysics);
    printf("Please enter the information of the student you want to add:n");
    printf("The format is as follows:n");
    printf("grade name id sex birthday ");
    printf("HigherMathematics CollegeEnglish UniversityPhysicsn");
    scanf("%s %s %d %c %d %d %d %d",grade,name,&id,&sex,&birthday,&Math,&English,&Physics);
    printf("%s %s %d %c %d %d %d %dn",grade,name,id,sex,birthday,Math,English,Physics);
    while(p->birthday){
        if(p->id==id){
            printf("The student information already exists,n");
            printf("please re-enter!n");
            AddInformation(p);
        }
        p++;
    }
    strcpy(p->grade,grade);
    strcpy(p->name,name);
    p->id=id;
    p->sex=sex;
    p->birthday=birthday;
    p->s.HigherMathematics=Math;
    p->s.CollegeEnglish=English;
    p->s.UniversityPhysics=Physics;
    printf("%s %s %d %c %d",p->grade,p->name,p->id,p->sex,p->birthday);
    printf(" %d %d %dn",p->s.HigherMathematics,p->s.CollegeEnglish,p->s.UniversityPhysics);
    printf("Information increase success!n");
    printf("Do you want to add one!'1'Yesn");
    printf("Or you will go banck to the main menu!'0'n");
    scanf("%d",&choice);
    if(choice){
        AddInformation(p);
    }
    else{
        Back();
    }
}

void DeleteInformation(Stu *p)
{
    int id;
    int flash=0;
    printf("Please enter the id of the student you want to delete!n");
    scanf("%d",&id);
    while(p->birthday){
            printf("Enter while1!n");
        if(p->id==id){
            printf("Please confirm the student information you want to delete!n");
            printf("%s %s %c %d %dn",p->grade,p->name,p->sex,p->id,p->birthday);
            flash=1;
            break;
        }
        p++;
    }
    if(flash==0){
        printf("This student id does not exist,please re-enter!n");
        DeleteInformation(p);
    }
    else{
        while(p->birthday){
                printf("Enter while2!n");
                p->birthday=(p+1)->birthday;
                strcpy(p->grade,(p+1)->grade);
                p->id=(p+1)->id;
                strcpy(p->name,(p+1)->name);
                p->sex=(p+1)->sex;
                p++;
            }
        printf("deleted successfullyn");
    }

}

void CheckInformation(Stu *p)
{
    int choice1,choice2;
    char grade[16];
    char name[16];
    int flash=0;
    int id;
    printf("Which information do you want to use to find student?n");
    printf("student grade:1n");
    printf("student name:2n");
    printf("student id:3n");
    scanf("%d",&choice1);
    if(choice1==1){
        printf("You choose to find student information by GRADE!n");
        printf("Please enter the grade of the student you want to find!n");
        scanf("%s",grade);
        printf("Find this student: %sn",grade);
        printf("gradettnametsextidttbirthdayn");
        while(p->birthday){
            if(strcmp(p->grade,grade)==0){
                printf("%st%st%ct%dt%dn",p->grade,p->name,p->sex,p->id,p->birthday);
                flash=1;
            }
            p++;
        }
        if(flash==0){
            printf("Students with this name are not available in the system!n");
            printf("Do you want to retrieve?'1'Yesn");
            scanf("%d",&choice2);
            if(choice2){
                CheckInformation(p);
            }
        }


    }
    else if(choice1==2){
        printf("You choose to find student information by NAME!n");
        printf("Please enter the name of the student you want to find!n");
        scanf("%s",name);
        printf("Find this student: %sn",name);
        printf("gradettnametsextidttbirthdayn");
        while(p->birthday){
            if(strcmp(p->name,name)==0){
                printf("%st%st%ct%dt%dn",p->grade,p->name,p->sex,p->id,p->birthday);
                flash=1;
            }
            p++;
        }
        if(flash==0){
            printf("Students with this name are not available in the system!n");
            printf("Do you want to retrieve?'1'Yesn");
            scanf("%d",&choice2);
            if(choice2){
                CheckInformation(p);
            }
        }

    }
    else{
        printf("You choose to find student information by ID!n");
        printf("Please enter the id of the student you want to find!n");
        scanf("%d",&id);
        printf("Find this student: %dn",id);
        printf("gradettnametsextidttbirthdayn");
        while(p->birthday){
            if(p->id==id){
                printf("%st%st%ct%dt%dn",p->grade,p->name,p->sex,p->id,p->birthday);
                flash=1;
            }
            p++;
        }
        if(flash==0){
            printf("Students with this id are not available in the system!n");
            printf("Do you want to retrieve?'1'Yesn");
            scanf("%d",&choice2);
            if(choice2){
                CheckInformation(p);
            }
        }


    }

}

void ModifyInformation(Stu *p)
{
    int id;
    int flash=0;
    int choice,choice2;
    char grade[16];
    char name[16];
    int birthday;
    int score1,score2,score3;
    printf("We only support modifying student information through ID!n");
    printf("Please enter student id!n");
    scanf("%d",&id);
    while(p->birthday){
        if(p->id==id){
            printf("The student's current information is as follows:n");
            printf("gradettnametsextidttbirthdayn");
            printf("%st%st%ct%dt%dn",p->grade,p->name,p->sex,p->id,p->birthday);
            printf("What information do you want to modify?n");
            printf("Grade 1n");
            printf("Name  2n");
            printf("Birthday 3n");
            printf("score    4n");
            scanf("%d",&choice);
            switch(choice){
                case(1):
                    printf("Please enter the modified grade!n");
                    scanf("%s",grade);
                    strcpy(p->grade,grade);
                    printf("Modified successfully!n");
                    printf("The student's current information is follows:n");
                    printf("gradettnametsextidttbirthdayn");
                    printf("%st%st%ct%dt%dn",p->grade,p->name,p->sex,p->id,p->birthday);
                    printf("Do you want to modify it again?'1'Yes '0'Non");
                    scanf("%d",&choice2);
                    if(choice2){
                        ModifyInformation(p);
                    }
                    break;
                case(2):
                    printf("Please enter the modified name!n");
                    scanf("%s",name);
                    strcpy(p->name,name);
                    printf("Modified successfully!n");
                    printf("The student's current information is follows:n");
                    printf("gradettnametsextidttbirthdayn");
                    printf("%st%st%ct%dt%dn",p->grade,p->name,p->sex,p->id,p->birthday);
                    printf("Do you want to modify it again?'1'Yes '0'Non");
                    scanf("%d",&choice2);
                    if(choice2){
                        ModifyInformation(p);
                    }
                    break;
                case(3):
                    printf("Please enter the modified birthday!n");
                    scanf("%d",&birthday);
                    p->birthday=birthday;
                    printf("Modified successfully!n");
                    printf("The student's current information is follows:n");
                    printf("gradettnametsextidttbirthdayn");
                    printf("%st%st%ct%dt%dn",p->grade,p->name,p->sex,p->id,p->birthday);
                    printf("Do you want to modify it again?'1'Yes '0'Non");
                    scanf("%d",&choice2);
                    if(choice2){
                        ModifyInformation(p);
                    }
                    break;
                case(4):
                    printf("Please enter the modified score!n");

                    scanf("%d%d%d",&score1,&score2,&score3);
                    p->s.HigherMathematics=score1;
                    p->s.CollegeEnglish=score2;
                    p->s.UniversityPhysics=score3;
                    printf("Modified successfully!n");
                    printf("The student's current information is follows:n");
                    printf("gradettnametsextidttbirthdayt");
                    printf("Math English Physicsn");
                    printf("%st%st%ct%dt%dt",p->grade,p->name,p->sex,p->id,p->birthday);
                    printf("t%d   %d     %dn",p->s.HigherMathematics,p->s.CollegeEnglish,p->s.UniversityPhysics);
                    printf("Do you want to modify it again?'1'Yes '0'Non");
                    scanf("%d",&choice2);
                    if(choice2){
                        ModifyInformation(p);
                    }
                    break;
                default:
                    printf("Please enter the correct option!n");
                    ModifyInformation(p);
            }

            flash=1;
            break;
        }
        p++;
    }
    if(!flash){
        printf("This student id does not exist,please re-enter!n");
        CheckInformation(p);
    }
}

float Scp(int a)
{
    float scp;
    if(a>=60){
        scp=1.0+(a-60)/10.0;
    }
    else{
        scp=0.0;
    }
    return scp;
}

void TraversalInformation(Stu *p)
{
    int choice;
    int count=0;
    Stu *q=&stu;
    printf("Do you want to print according to the grade point ranking!'1'Yesn");
    scanf("%d",&choice);
    if(choice){
        printf("gradettnametsextidttbirthdayt");
        printf("Math    English Physics Scorepointn");
        while(p->birthday){
            while(q->birthday){
                if(Scp(q->s.CollegeEnglish)+Scp(q->s.HigherMathematics)+Scp(q->s.UniversityPhysics)
                   s.CollegeEnglish)+Scp((q+1)->s.HigherMathematics)+Scp((q+1)->s.UniversityPhysics))
                    Swap(q,(q+1));
                q++;
            }
            count++;
            p++;
        }
        q--;
        while(q->birthday){
           printf("%st%st%ct%dt%dt",q->grade,q->name,q->sex,q->id,q->birthday);
           printf("%dt%dt%d",q->s.HigherMathematics,q->s.CollegeEnglish,q->s.UniversityPhysics);
           printf("t%.1fn",(Scp(q->s.CollegeEnglish)+Scp(q->s.HigherMathematics)+Scp(q->s.UniversityPhysics))/3);
           q--;
        }
        printf("There are %d student!n",count);

    }
}


void Swap(Stu *p,Stu *q)
{
    Stu temp;
    temp=*p;
    *p=*q;
    *q=temp;
}

void AccountOperate(Account *p)
{
    int number;
    int number2;
    char password[16];
    char password2[16];
    int choice,choice2;
    int flash=0;
    int count=0;
    printf("We need to re-verify your account.n");
    printf("Please enter your account:n");
    scanf("%d",&number);
    while(p->number){
        if(p->number==number){
            printf("Please enter your account password!n");
            scanf("%s",password);
            while(strcmp(p->password,password)){
                printf("Wrong password,Re-enter!n");
                scanf("%s",password);
                count++;
                if(count>3){
                    printf("Too many errors,Re-enter!n");
                    AccountOperate(p);
                    break;
                }
            }
            printf("Verify successfully!n");
            printf("You can modify or cancel your account.n");
            printf("Account Modify 1n");
            printf("Account Cancel 2n");
            scanf("%d",&choice);
            if(choice==1){
                printf("You can modify your account or password.n");
                printf("Account number Modify 1n");
                printf("Account password Modify 2n");
                scanf("%d",&choice2);
                if(choice2==1){
                        printf("Please enter your new number!n");
                        scanf("%d",&number2);
                        p->number=number2;
                        printf("Your new accountnnumber:%d password:%sn",p->number,p->password);
                        printf("Please go back and Re-Loginn");
                        AccountDataSave();
                        Login();

                }
                else{
                    printf("Please enter your new password!n");

                    scanf("%s",password2);
                    while(!strcmp(p->password,password2)){
                        printf("Old and new passwords cannot be the same!n");
                        printf("Please re-enter!n");
                        scanf("%s",password2);
                    }
                    strcpy(p->password,password2);
                    printf("Your new account number:%d password:%sn",p->number,p->password);
                    printf("Please go back and Re-Loginn");
                    AccountDataSave();
                    Login();


                }

            }
            else{
                while(p->number){
                    p->number=(p+1)->number;
                    strcpy(p->password,(p+1)->password);
                    p++;
                }
                printf("The account has been canceled!n");
                printf("Please go back and Re-Login or Register!n");
                Login();

            }
            flash=1;
            }
        p++;

    }

    if(flash==0){
        printf("Wrong account number,Re-enter!n");
        AccountOperate(p);
    }

}

void Menu()
{
    int choice;
    StudentDataImport();
    printf("Welcome to our Student Management System!n");
    printf("Please select the action you want.n");
    printf("1   AddInformationn");
    printf("2   DeleteInformationn");
    printf("3   CheckInformationn");
    printf("4   ModifyInformationn");
    printf("5   TraversalInformationn");
    printf("6   AccountOperaten");
    scanf("%d",&choice);
    switch(choice)
    {

        case(1):
            system("cls");
            printf("You chose 1 ,AddInformation!n");
            AddInformation(&stu);
            break;
        case(2):
            system("cls");
            printf("You chose 2 ,DeleteInformation!n");
            DeleteInformation(&stu);
            Back();
            break;
        case(3):
            system("cls");
            printf("You chose 3 ,CheckInformation!n");
            CheckInformation(&stu);
            Back();
            break;
        case(4):
            system("cls");
            printf("You chose 4 ,ModifyInformation!n");
            ModifyInformation(&stu);
            Back();
            break;
        case(5):
            system("cls");
            printf("You chose 5 ,TraversalInformation!n");
            TraversalInformation(&stu);
            Back();
            break;
        case(6):
            system("cls");
            printf("You chose 6 ,AccountOperate!n");
            AccountOperate(&acc);
            Back();
            break;
        default:
            system("cls");
            printf("Please reenter!n");
            Menu();
    }
}
void Back()
{
    int choice;
    printf("Do you want to return to the main Menu?'0'Yesn");
    scanf("%d",&choice);
    if(choice==0){
        StudentDataSave();
        Menu();

    }
}
int main()
{
    Login();
    Menu();
    return 0;
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/1008643.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号