学生管理系统(未完)

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
typedef struct DATE{                        //定义成绩数据结构体
    float chinese_soc;
    float math_soc;
    float phy_soc;
    float chemical_soc;
    float english_soc;
    float ave_soc;
}Date,*Pdate;
typedef struct STUDENT{                     //定义学生结构体
    char stu_name[20];
    char stu_num[20];
    char stu_sex[10];
    char years[10];
    Pdate psoceer;
    struct STUDENT *pNext;
}Student,*Pstudent;
typedef struct CLASS{                       //定义班级结构体
    struct CLASS *pNext;
    Pstudent pstudent_head;
    int class_num;
}Class,*Pclass;
int j=0;                                    //全局变量,班级号
int main (void){                            //主函数
    void init_list(void);           //整个主界面
    void space(void);               //去除scanf后面的回车
    Pstudent create_students(void); //创建一个班级的学生
    Pclass create_class(void);      //创建一个年级的学生
    Pclass init_students(void);       //初始化学生数据,不添加任何数据进去
    void found_student_for_sth(Pclass);     //查找某个学生成绩
    void append_list(Pclass);               //增加某个学生成绩
    void show_list(Pclass);         //显示整个学生数据库中的数据
    Pstudent delete_student(Pclass);
    printf("〓〓〓〓〓〓〓〓〓〓  ☆   学 生 成 绩 管 理 系  统     ☆  〓〓〓〓〓〓〓〓〓〓");
    init_list();
    char i;
    Pclass class_head=init_students();
        while(scanf("%c",&i)==1){
                //space();
                if(i>'0'&&i<'8'){
                        switch(i){
                            case '1':{
                                class_head=create_class();
                                init_list();
                                }
                                break;
                            case '2':{
                                append_list(class_head);
                                init_list();
                                }
                                break;
                            case '3':{
                                show_list(class_head);
                                init_list();
                                }
                                break;
                            case '5':{
                                found_student_for_sth(class_head);
                                init_list();
                            }
                            break;
                            case '6':{
                                //delete_student(class_head);
                                init_list();
                            }
                            break;

                    }
                }
    }
    return 0;
}
void init_list(void){                       //初始化主界面
  printf("〓〓〓〓〓〓〓★★★★★         ★★★★★★★         ★★★★★〓〓〓〓〓〓〓");
  printf("〓〓〓〓〓〓〓〓〓★  ☆      1.初始化并添加学生数据    ☆  ★〓〓〓〓〓〓〓〓〓");
  printf("〓〓〓〓〓〓〓〓〓★  ☆          2.增加学生成绩        ☆  ★〓〓〓〓〓〓〓〓〓");
  printf("〓〓〓〓〓〓〓〓〓★  ☆          3.显示学生成绩        ☆  ★〓〓〓〓〓〓〓〓〓");
  printf("〓〓〓〓〓〓〓〓〓★  ☆          4.排序统计成绩        ☆  ★〓〓〓〓〓〓〓〓〓");
  printf("〓〓〓〓〓〓〓〓〓★  ☆          5.查找学生成绩        ☆  ★〓〓〓〓〓〓〓〓〓");
  printf("〓〓〓〓〓〓〓〓〓★  ☆          6.删除学生成绩        ☆  ★〓〓〓〓〓〓〓〓〓");
  printf("〓〓〓〓〓〓〓〓〓★  ☆          7.修改学生信息        ☆  ★〓〓〓〓〓〓〓〓〓");
  printf("〓〓〓〓〓〓〓〓〓★  ☆        8.保存信息至文件        ☆  ★〓〓〓〓〓〓〓〓〓");
  printf("〓〓〓〓〓〓〓〓〓★  ☆          0.安全退出系统        ☆  ★〓〓〓〓〓〓〓〓〓");
  printf("请输入序号哦~~~第一步必须初始化\n");
}
Pstudent create_students(void){             //创建一个班级的学生数据
    int len,i;
    void space(void);
    printf("第%d个班的学生总人数学生人数:",++j);
    scanf("%d",&len);
    space();
    Pstudent pstudent_head=(Pstudent)malloc(sizeof(Student));
    if(pstudent_head==NULL){
        printf("这里一定有一个不应该发生的错误!我该怎么办咧~~~\n");
        exit(-1);
    };
    Pstudent pTemp=pstudent_head;
    pTemp->pNext=NULL;
    for(i=0;i<len;i++){
        Pstudent pNew=(Pstudent)malloc(sizeof(Student));
        Pdate psoccer=(Pdate)malloc(sizeof(Date));
        if(pNew==NULL){
            printf("这里一定有一个不应该发生的错误!我该怎么办咧~~~\n");
            exit(-1);
        }
        printf("现在请输入第%d个学生的信息:\n",i+1);
        printf("输入学生的姓名:");
        scanf("%s",pNew->stu_name);
        printf("请输入学生性别:");
        scanf("%s",pNew->stu_sex);
        printf("请输入学生学号:");
        scanf("%s",pNew->stu_num);
        printf("请输入学生学期数:");
        scanf("%s",pNew->years);
        space();
        printf("接下来输入的是学生的各科成绩:\n");
            printf("语文成绩:");
            scanf("%f",&psoccer->chinese_soc);
            printf("数学成绩:");
            scanf("%f",&psoccer->math_soc);
            printf("英语成绩:");
            scanf("%f",&psoccer->english_soc);
            printf("化学成绩:");
            scanf("%f",&psoccer->chemical_soc);
            printf("物理成绩:");
            scanf("%f",&psoccer->phy_soc);
            space();
        pNew->psoceer=psoccer;
        printf("第%d个学生成绩录入完毕\n",i+1);
        pTemp->pNext=pNew;
        pNew->pNext=NULL;
        pTemp=pTemp->pNext;
    }
    return pstudent_head;
}
Pclass create_class(void){                  //创建一个年级的学生数据
    Pstudent create_students(void);
    int len,i;
    printf("告诉我这个年级有多少个班!");
    scanf("%d",&len);
    if(len>30){
        printf("卧槽,有这么多个班啊!回去输个小点的数\n");
    }else{
            Pclass class_head=(Pclass)malloc(sizeof(Class));
            if(class_head==NULL){
                    printf("这里一定有一个不应该发生的错误!我该怎么办咧~~~\n");
                    exit(-1);
                }
        Pclass class_temp=class_head;
        class_temp->pNext=NULL;
        for(i=0;i<len;i++){
            Pclass class_New=(Pclass)malloc(sizeof(Class));
            Pstudent phead=create_students();
            class_New->pstudent_head=phead;
            class_New->class_num=i+1;
            class_New->pNext=NULL;
            class_temp->pNext=class_New;
            class_temp=class_New;
        }
        return class_head;
    }
    return 0;
}
Pclass init_students(void){                 //初始化一个学生数据综合
    Pdate psoccer=(Pdate)malloc(sizeof(Date));
    Pstudent pstudent_head=(Pstudent)malloc(sizeof(Student));
    Pclass class_head=(Pclass)malloc(sizeof(Class));
    class_head->pstudent_head=pstudent_head;
    pstudent_head->psoceer=psoccer;
    psoccer=NULL;
    pstudent_head->pNext=NULL;
    class_head->pNext=NULL;
    return class_head;
}
void show_list(Pclass class_head){          //显示学生数据信息
    Pclass temp=class_head->pNext;
    if(temp==NULL){
        printf("木有任何学生成绩!\n");
    }
    while(temp!=NULL){
        printf("%d班学生成绩总表\n",temp->class_num);
        Pstudent student_temp=temp->pstudent_head->pNext;
        printf("\n");
        printf("学期\t学号\t姓名\t性别\t语文\t数学\t外语\t物理\t化学\n");
        while(student_temp!=NULL){
            Pdate date_temp=student_temp->psoceer;
            printf("%7s%10s%8s%8s%7.2f %7.2f %7.2f %7.2f %7.2f\n",student_temp->years,student_temp->stu_num,student_temp->stu_name,student_temp->stu_sex,date_temp->chinese_soc,date_temp->math_soc,date_temp->english_soc,date_temp->phy_soc,date_temp->chemical_soc);
            student_temp=student_temp->pNext;
        }
        temp=temp->pNext;
    }
}
void found_student_for_sth(Pclass class_head){                                               //根据姓名等查找函数
    int choice1,choice2,i=0,class_num;
    char name[20];
    Pclass temp_class;
    Pstudent temp_student=malloc(sizeof(Student));
    void found_student(char*name,Pclass class_head,Pstudent temp_students,int flag);
    Pstudent found_student_num(char*name,Pclass class_head);
    Pclass found_class(int class_num,Pclass class_head);
    printf("1.模糊查找\t2.精确查找\n");
    scanf("%d",&choice1);
    if(choice1==1){                 //模糊查找
        printf("模糊查找只支持班级查找.\n");
        printf("请输入你要查询的班级:");
        scanf("%d",&class_num);
        temp_class=found_class(class_num,class_head);
        if(temp_class!=NULL){
            temp_student=temp_class->pstudent_head->pNext;
            printf("学期\t学号\t姓名\t性别\t语文\t数学\t外语\t物理\t化学\n");
            while(temp_student!=NULL){
            Pdate date_temp=temp_student->psoceer;
            printf("%7s%10s%8s%8s%7.2f %7.2f %7.2f %7.2f %7.2f\n",temp_student->years,temp_student->stu_num,temp_student->stu_name,temp_student->stu_sex,date_temp->chinese_soc,date_temp->math_soc,date_temp->english_soc,date_temp->phy_soc,date_temp->chemical_soc);
            temp_student=temp_student->pNext;
            }
           free(temp_student);
        }else{
            printf("查无此人!\n");
        }
    }
    else{
        printf("请输入你需要以下哪种方式径行查找\n");
        printf("1.按照姓名\t2.按照学号\t3.按照性别\t4.按照班级\n");
        scanf("%d",&choice2);
        switch(choice2){
            case 1:{
                printf("请输入你要查找的姓名:");
                scanf("%s",name);
                Pstudent temp_students=(Pstudent)malloc(sizeof(Student)*30);
                found_student(name,class_head,temp_students,1);
                if(temp_students->psoceer!=NULL){
                    printf("学期\t学号\t姓名\t性别\t语文\t数学\t外语\t物理\t化学\n");
                    while((temp_students+i)->psoceer!=NULL){
                        printf("%7s%10s%8s%8s%7.2f %7.2f %7.2f %7.2f %7.2f\n",(temp_students+i)->years,(temp_students+i)->stu_num,(temp_students+i)->stu_name,(temp_students+i)->stu_sex,(temp_students+i)->psoceer->chinese_soc,(temp_students+i)->psoceer->math_soc,(temp_students+i)->psoceer->english_soc,(temp_students+i)->psoceer->phy_soc,(temp_students+i)->psoceer->chemical_soc);
                        i++;
                    }
                    free(temp_students);
                }else{
                    printf("查无此人!\n");
                }
            }
            break;
            case 2:{
                printf("请输入你要查找的学号:");
                scanf("%s",name);
                Pstudent temp_students=(Pstudent)malloc(sizeof(Student)*30);
                found_student(name,class_head,temp_students,2);
                if(temp_students->psoceer!=NULL){
                    printf("学期\t学号\t姓名\t性别\t语文\t数学\t外语\t物理\t化学\n");
                    while((temp_students+i)->psoceer!=NULL){
                        printf("%7s%10s%8s%8s%7.2f %7.2f %7.2f %7.2f %7.2f\n",(temp_students+i)->years,(temp_students+i)->stu_num,(temp_students+i)->stu_name,(temp_students+i)->stu_sex,(temp_students+i)->psoceer->chinese_soc,(temp_students+i)->psoceer->math_soc,(temp_students+i)->psoceer->english_soc,(temp_students+i)->psoceer->phy_soc,(temp_students+i)->psoceer->chemical_soc);
                        i++;
                    }
                    free(temp_students);
                }else{
                    printf("查无此人!\n");
                }
            }
            break;
            case 3:{
                printf("请输入你要查找的性别:");
                scanf("%s",name);
                Pstudent temp_students=(Pstudent)malloc(sizeof(Student)*30);
                found_student(name,class_head,temp_students,3);
                if(temp_students->psoceer!=NULL){
                    printf("学期\t学号\t姓名\t性别\t语文\t数学\t外语\t物理\t化学\n");
                    while((temp_students+i)->psoceer!=NULL){
                        printf("%7s%10s%8s%8s%7.2f %7.2f %7.2f %7.2f %7.2f\n",(temp_students+i)->years,(temp_students+i)->stu_num,(temp_students+i)->stu_name,(temp_students+i)->stu_sex,(temp_students+i)->psoceer->chinese_soc,(temp_students+i)->psoceer->math_soc,(temp_students+i)->psoceer->english_soc,(temp_students+i)->psoceer->phy_soc,(temp_students+i)->psoceer->chemical_soc);
                        i++;
                    }
                    free(temp_students);
                }else{
                    printf("查无此人!\n");
                }
            }
            break;
            case 4:{
                printf("请输入你要查找的学期数:");
                scanf("%s",name);
                Pstudent temp_students=(Pstudent)malloc(sizeof(Student)*30);
                found_student(name,class_head,temp_students,4);
                if(temp_students->psoceer!=NULL){
                    printf("学期\t学号\t姓名\t性别\t语文\t数学\t外语\t物理\t化学\n");
                    while((temp_students+i)->psoceer!=NULL){
                        printf("%7s%10s%8s%8s%7.2f %7.2f %7.2f %7.2f %7.2f\n",(temp_students+i)->years,(temp_students+i)->stu_num,(temp_students+i)->stu_name,(temp_students+i)->stu_sex,(temp_students+i)->psoceer->chinese_soc,(temp_students+i)->psoceer->math_soc,(temp_students+i)->psoceer->english_soc,(temp_students+i)->psoceer->phy_soc,(temp_students+i)->psoceer->chemical_soc);
                        i++;
                    }
                    free(temp_students);
                }else{
                    printf("查无此人!\n");
                }
            }
            break;
        }
    }
}
void found_student(char*name,Pclass class_head,Pstudent temp_students,int flag){             //精确查找函数
    int i=0;
    Pclass temp=class_head->pNext;
   while(temp!=NULL){
        Pstudent temp_student=temp->pstudent_head->pNext;
        while(temp_student!=NULL){
                switch(flag){
                        case 1:if(strcmp(name,temp_student->stu_name)==0){
                                temp_students[i]=*temp_student;
                                i++;
                            }break;
                        case 2:if(strcmp(name,temp_student->stu_num)==0){
                                temp_students[i]=*temp_student;
                                i++;
                            }break;
                        case 3:if(strcmp(name,temp_student->stu_sex)==0){
                                temp_students[i]=*temp_student;
                                i++;
                            }break;
                        case 4:if(strcmp(name,temp_student->years)==0){
                                temp_students[i]=*temp_student;
                                i++;
                            }break;
                        }
                temp_student=temp_student->pNext;
        }
        temp=temp->pNext;
    }
}
Pclass found_class(int class_num,Pclass class_head){                                         //模糊查找函数
    Pclass temp_class=class_head->pNext;
    while(temp_class!=NULL&&temp_class->class_num!=class_num){
        temp_class=temp_class->pNext;
    }
    return temp_class;
}
void append_list(Pclass class_head){            //添加一个学生
    void space(void);
    int class_num;
    Pstudent pNew=(Pstudent)malloc(sizeof(Student));
    Pdate psoccer=(Pdate)malloc(sizeof(Date));
    printf("请输入你要添加的学生是哪一个班级:");
    scanf("%d",&class_num);
    space();
    printf("输入新增学生的姓名:");
    scanf("%s",pNew->stu_name);
    printf("请输入新增学生性别:");
    scanf("%s",pNew->stu_sex);
    printf("请输入新增学生学号:");
    scanf("%s",pNew->stu_num);
    printf("请输入新增学生学期数:");
    scanf("%s",pNew->years);
    space();
    printf("接下来输入的是学生的各科成绩:\n");
        printf("语文成绩:");
        scanf("%f",&psoccer->chinese_soc);
        printf("数学成绩:");
        scanf("%f",&psoccer->math_soc);
        printf("英语成绩:");
        scanf("%f",&psoccer->english_soc);
        printf("化学成绩:");
        scanf("%f",&psoccer->chemical_soc);
        printf("物理成绩:");
        scanf("%f",&psoccer->phy_soc);
        space();
    pNew->psoceer=psoccer;
    if(class_head->pNext!=NULL){                        //if判断成绩表中是否有数据,没有数据就在else中新建
        Pclass temp_class=class_head->pNext;
        Pclass temp1_class=class_head->pNext;
        Pstudent temp_student=(Pstudent)malloc(sizeof(Student));
        temp_class=found_class(class_num,class_head);
        if(temp_class==NULL){                           //if判断这个班级是否存在,若不存在,则新建之
            temp_class=(Pclass)malloc(sizeof(Class));
            while(temp1_class->pNext!=NULL){
                temp1_class=temp1_class->pNext;
            }
            temp1_class->pNext=temp_class;
            temp_class->class_num=class_num;
            temp_class->pNext=NULL;
            temp_class->pstudent_head=temp_student;
            temp_student->pNext=pNew;
        }else{
            temp_student=temp_class->pstudent_head->pNext;
            while(temp_student->pNext!=NULL){
                temp_student=temp_student->pNext;
            }
            //if(temp_student==NULL){printf("yes");}
            //printf("%7s%10s%8s%8s%7.2f %7.2f %7.2f %7.2f %7.2f\n",pNew->years,pNew->stu_num,pNew->stu_name,pNew->stu_sex,pNew->psoceer->chinese_soc,pNew->psoceer->math_soc,pNew->psoceer->english_soc,pNew->psoceer->phy_soc,pNew->psoceer->chemical_soc);
            temp_student->pNext=pNew;
            //if(temp_student==NULL){printf("yes");}
           // printf("%7s%10s%8s%8s%7.2f %7.2f %7.2f %7.2f %7.2f\n",temp_student->years,temp_student->stu_num,temp_student->stu_name,temp_student->stu_sex,temp_student->psoceer->chinese_soc,temp_student->psoceer->math_soc,temp_student->psoceer->english_soc,temp_student->psoceer->phy_soc,temp_student->psoceer->chemical_soc);

        }
        pNew->pNext=NULL;
    }else{
        Pclass pNew_class=(Pclass)malloc(sizeof(Class));
        Pstudent pNew_student=(Pstudent)malloc(sizeof(Student));
        class_head->pNext=pNew_class;
        pNew_class->class_num=class_num;
        pNew_class->pstudent_head=pNew_student;
        pNew_class->pNext=NULL;
        pNew_student->pNext=pNew;
        pNew->pNext=NULL;
    }
}
Pstudent delete_student(Pclass class_head){       //删除一个学生
    char name[20];
    int i=0,j;
    printf("请输入删除学生的姓名:");
    scanf("%s",name);
    Pstudent temp_students=(Pstudent)malloc(sizeof(Student)*30);
    found_student(name,class_head,temp_students,1);
    if(temp_students->psoceer!=NULL){
        Pstudent temp=temp_students;
        while(temp->psoceer!=NULL){
            temp=temp+1;
            i++;
        }
        for(j=0;j<i;j++){
            Pstudent after_student,before_student;
            after_student=temp_students[j]->pNext;
            while(){}
        }
    }
    return 0;
};
void space(void){                               //移除输入的空格以及回车键,输入后面不需要的数据
    while(getchar()!='\n'){
        continue;
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值