zoukankan      html  css  js  c++  java
  • 学生信息管理系统

    /*编译环境为vc++6.0----VS2015*/
    #define _CRT_SECURE_NO_WARNINGS
    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    #include<Windows.h>
    #include<ctype.h>
    struct list {
        char ID[20];
        char name[20];
        char gender[5];
        float score;
        struct list *next;
    };
                                            /*文件指针*/
    char *filename ="'C:\Users\ASUS\Desktop\myfile.txt";/*文件存储路径*/
    int re_ID = 0;                                          /*为了检验是否经过了创建学生信息的检查*/
    struct list *List = NULL;                               /*表头*/
    struct list *create();                                  /*创建学生链表*/
    struct list *Find_Previous(struct list *p);             /*为了删除而使用的查找函数*/
    struct list *Find_Previously(struct list *p);           /*为了添加而使用的查找函数*/
    struct list *Selectsort(struct list *L);                /*插入排序--按照成绩进行排序*/
    void Print();                                           /*打印菜单*/
    void Print_Query();                                     /*打印查询菜单*/
    void Exit();                                            /*退出*/
    void Querying();                                        /*查询*/
    void Help();                                            /*帮助手册*/
    void Display(struct list *p);                           /*打印表*/
    void Save(struct list *pp);                             /*将链表写入文件中*/
    void Query_ID(struct list *p);                          /*按学号查询*/
    void Query_Name(struct list *p);                        /*按姓名查询*/
    void Query_Gender(struct list *p);                      /*按性别查询*/
    void Query_Score(struct list *p);                       /*按成绩查询*/
    void Addition(struct list *p);                          /*添加学生信息*/
    void Delete(struct list *p);                            /*删除学生的信息*/
    void Rebuild(struct list *p);                           /*删除所有信息*/
    int  check_ID(char ID[]);                               /*检查学号的输入正确性*/
    int main(void)  
    {
        char choice = '';
        while (1) {
            system("cls");
            fflush(stdin);
            Print();
            scanf("%c", &choice);
            switch (choice) {
            case'1':
                List = create();
                break;
            case'2':
                Querying();
                break;
            case'3':
                Selectsort(List);
                break;
            case'4':
                Display(List);
                break;
            case'5':
                Exit();
                break;
            case'6':
                Help();
                break;
            case'7':
                Save(List);
                break;
            case'8':
                Addition(Find_Previous(List));
                break;
            case'9':
                Delete(Find_Previous(List));
                break;
            case'0':
                Rebuild(List);
                break;
            default:
                printf("没有此选择项,请重新输入!
    ");
                break;
            }
        }
        return 0;
    }
    
    struct list *create() {
        char ch = '';
        struct list *head = NULL;
        struct list *current = NULL;
        struct list *previous = NULL;
        while (1) {
            printf("请问是否输入学生信息?(Y or N)
    ");
            scanf(" %c", &ch);
            if (tolower(ch) == 'n') {
                puts("你选择了取消输入!
    ");
                system("pause");
                break;
            }
            current = (struct list *)malloc(sizeof(struct list));
    
            if (head == NULL)
                head = current;
            if (previous != NULL)
                previous->next = current;
    
            puts("请输入学生姓名:");
            scanf("%s", current->name);
            while (1) {
                puts("请输入学生学号:");
                fflush(stdin);
                scanf("%s", current->ID);
                if (check_ID(current->ID) == 0)
                    break;
                else
                    puts("你输入的格式错误,请重新输入!
    ");
            }
            while (1) {
                puts("请输入学生的性别:(注意:boy or girl)");
                fflush(stdin);
                scanf(" %s", current->gender);
                if (strcmp(current->gender, "boy") == 0 || strcmp(current->gender, "girl") == 0)
                    break;
                else
                    puts("你输入的格式错误,请重新输入!
    ");
            }
            while (1) {
                printf("请输入学生的成绩:
    ");
                fflush(stdin);
                if (scanf("%f", &current->score)!=EOF&&current->score>=0.0)
                    break;
                else
                    printf("你输入的格式错误,请重新输入!
    ");
                    fflush(stdin);
            }
            current->next = NULL;
            previous = current;
        }
        re_ID++;
        return (head);
    }
    
    void Exit() {   /*这个是用来退出*/
        int i = 0;
        printf("退出中");
        for (i = 4; i > 0; --i) {
            Sleep(200);
            printf(".");
        }
        exit(0);
    }
    void Save(struct list *pp)
    {
        if (re_ID == 0) {
            printf("请先创建学生信息!
    ");
            system("pause");
            return;
        }
        struct list *head = NULL;
        head = pp;
        FILE *fp = NULL;
        if (!(fp = fopen(filename, "wb"))) {
            fprintf(stderr,"
    打开失败
    ");
            system("pause");
            return;
        }
        while (head->next != NULL) {
            fwrite(head,sizeof(struct list),1,fp);
            head = head->next;
        }
        fclose(fp);
        printf("数据读入文件完毕
    ");
        system("pause");
    }
    
    
    void Display(struct list *p) {
        if (re_ID == 0) {
            printf("请先创建学生信息!
    ");
            system("pause");
            return;
        }
        struct list *temp = NULL;
        temp = p;
        while (temp != NULL) {
            printf("-----/*姓名*/--------/*学号*/-----/*性别*/-----/*成绩*/-----
    ");
            printf("       %s              %s           %s            %.2f
    ", temp->name, temp->ID,temp->gender,temp->score);
            temp = temp->next;
        }
        system("pause");
    }
    void Print() {
        printf("-----主菜单功能如下:
    ");
        printf("-----1.输入学生信息
    ");
        printf("-----2.查询
    ");
        printf("-----3.排序
    ");
        printf("-----4.打印学生信息
    ");
        printf("-----5.退出
    ");
        printf("-----6.帮助
    ");
        printf("-----7.数据写入文件
    ");
        printf("-----8.插入学生信息
    ");
        printf("-----9.删除学生信息
    ");
        printf("-----0.重建学生信息
    ");
        printf("请输入你的选择!
    ");
    }
    void Help() {
        puts("Ver3.0-学生信息管理系统
    ");
        puts("由于本人是新手,所以一定会有很多的问题
    ");
        puts("如果能告诉我,在下不胜感激
    ");
        system("pause");
    }
    void Print_Query() {
        printf("-----查询菜单功能如下:
    ");
        printf("-----1.按学号查询
    ");
        printf("-----2.按姓名查询
    ");
        printf("-----3.按性别查询
    ");
        printf("-----4.按成绩查询
    ");
        printf("-----5.退出查询
    ");
        printf("请输入你的选择:
    ");
    }
    void Querying() {
        char cho = '';
        while (1) {
            system("cls");
            fflush(stdin);
            Print_Query();
            scanf("%c", &cho);
            switch (cho) {
            case'1':
                Query_ID(List);
                break;
            case'2':
                Query_Name(List);
                break;
            case'3':
                Query_Gender(List);
                break;
            case'4':
                Query_Score(List);
                break;
            case'5':
                return;
                break;
            default:
                printf("无此选择项!
    ");
                system("pause");
                break;
            }
        }
    }
    void Query_Name(struct list *p) {
        if (re_ID == 0) {
            printf("请先创建学生信息!
    ");
            system("pause");
            return;
        }
        struct list *temp = NULL;
        char na[20];
        temp = p;
        printf("请输入你想要查询的姓名:
    ");
        scanf("%s", na);
        while (temp != NULL) {
            if (strcmp(temp->name, na) == 0) {
                printf("你的查找如下:
    ");
                printf("-----/*姓名*/--------/*学号*/-----/*性别*/-----/*成绩*/-----
    ");
                printf("        %s              %s          %s            %.2f
    ", temp->name, temp->ID, temp->gender, temp->score);
                temp = temp->next;
            }
            else
                temp = temp->next;
        }
        system("pause");
    }
    void Query_ID(struct list *p) {
        if (re_ID == 0) {
            printf("请先创建学生信息!
    ");
            system("pause");
            return;
        }
        struct list *temp = NULL;
        char id[20];
        temp = p;
        while (1) {
            printf("请输入你想要查询的学号:
    ");
            fflush(stdin);
            scanf("%s", id);
            if (check_ID(id) == 0)
                break;
            else
                puts("你输入的格式错误,请重新输入!");
        }
        while (temp != NULL) {
            if (strcmp(temp->ID, id) == 0) {
                printf("你的查找如下:
    ");
                printf("-----/*姓名*/--------/*学号*/-----/*性别*/-----/*成绩*/-----
    ");
                printf("       %s              %s          %s            %.2f
    ", temp->name, temp->ID, temp->gender, temp->score);
                temp = temp->next;
            }
            else
                temp = temp->next;
        }
        system("pause");
    }
    void Query_Gender(struct list *p) {
        if (re_ID == 0) {
            printf("请先创建学生信息!
    ");
            system("pause");
            return;
        }
        struct list *temp = NULL;
        char ge[5];
        temp = p;
        while (1) {
            puts("请输入学生的性别:(注意:boy or girl)");
            fflush(stdin);
            scanf(" %s", ge);
            if (strcmp(ge, "boy") == 0 || strcmp(ge, "girl") == 0)
                break;
            else
                puts("你输入的格式错误,请重新输入!
    ");
        }
        while (temp != NULL) {
            if (strcmp(temp->gender,ge) == 0) {
                printf("你的查找如下:
    ");
                printf("-----/*姓名*/--------/*学号*/-----/*性别*/-----/*成绩*/-----
    ");
                printf("       %s              %s          %s            %.2f
    ", temp->name, temp->ID, temp->gender, temp->score);
                temp = temp->next;
            }
            else
                temp = temp->next;
        }
        system("pause");
    }
    void Query_Score(struct list *p) {
        if (re_ID == 0) {
            printf("请先创建学生信息!
    ");
            system("pause");
            return;
        }
        struct list *temp = NULL;
        float sc = 0;
        temp = p;
        while (1) {
            puts("请输入学生的成绩:");
            fflush(stdin);
            if (scanf("%f", &sc) != EOF&&sc >= 0.0)
                break;
            else
                puts("你输入的格式错误,请重新输入!
    ");
        }
        while (temp != NULL) {
            if (temp->score == sc) {
                printf("你的查找如下:
    ");
                printf("-----/*姓名*/--------/*学号*/-----/*性别*/-----/*成绩*/-----
    ");
                printf("       %s             %s          %s            %.2f
    ", temp->name, temp->ID, temp->gender, temp->score);
                temp = temp->next;
            }
            else
                temp = temp->next;
        }
        system("pause");
    }
    
    struct list *Find_Previously(struct list *p){
        if (re_ID == 0) {
            printf("请先创建学生信息!
    ");
            system("pause");
            return NULL;
        }
        struct list *temp = NULL;
        temp = p;
        char iidd[20];
        while (1) {
            printf("请输入你想要查询的学号:(注意:第一条信息之前不能插入信息)
    ");
            fflush(stdin);
            scanf("%s", iidd);
            if (check_ID(iidd) == 0)
                break;
            else
                puts("你输入的格式错误,请重新输入!
    ");
        }
        while (temp != NULL) {
            if (strcmp(temp->ID, iidd) == 0) {
                break;
            }
            else
                temp = temp->next;
        }
        return temp;
    }
    struct list *Find_Previous(struct list *p) {
        if (re_ID == 0) {
            printf("请先创建学生信息!
    ");
            system("pause");
            return NULL;
        }
        struct list *temp = NULL;
        temp = p;
        char iidd[20];
        while (1) {
            Display(List);
            printf("请输入你想要插入之前的学号:
    ");
            fflush(stdin);
            scanf("%s", iidd);
            if (check_ID(iidd) == 0)
                break;
            else
                puts("你输入的格式错误,请重新输入!
    ");
        }
        while (temp != NULL) {
            if (strcmp(temp->next->ID, iidd) == 0) {
                break;
            }
            else
                temp = temp->next;
        }
        return temp;
    }
    
    void Delete(struct list *p) {
        if (re_ID == 0) {
            printf("请先创建学生信息!
    ");
            system("pause");
            return;
        }
        struct list *temp = NULL;
        temp = p->next;
        p->next = temp->next;
        free(temp);
    }
    void Rebuild(struct list *p) {
        if (re_ID == 0) {
            printf("请先创建学生信息!
    ");
            return;
        }
        struct list *temp = NULL;
        struct list *tt = NULL;
        temp = p;
        p->next = NULL;
        while (temp != NULL) {
            tt = temp->next;
            free(temp);
            temp = tt;
        }
        puts("重建学生信信息完成!
    ");
        re_ID = 0;
        system("pause");
    }
    void Addition(struct list *p) {
        if (re_ID == 0) {
            printf("请先创建学生信息!
    ");
            system("pause");
            return;
        }
        struct list *temp = NULL;
        temp = (struct list *)malloc(sizeof(struct list));
        if (temp == NULL) {
            fprintf(stderr, "空间不足!
    ");
            exit(0);
        }
        puts("请输入学生姓名:");
        scanf("%s", temp->name);
        while (1) {
            puts("请输入学生学号:");
            fflush(stdin);
            scanf("%s", temp->ID);
            if (check_ID(temp->ID) == 0)
                break;
            else
                puts("你输入的格式错误,请重新输入!
    ");
        }
        while (1) {
            puts("请输入学生的性别:(注意:boy or girl)");
            fflush(stdin);
            scanf("%s", temp->gender);
            if (strcmp(temp->gender, "boy") == 0 || strcmp(temp->gender, "girl") == 0)
                break;
            else
                puts("你输入的格式错误,请重新输入!
    ");
        }
        while (1) {
            printf("请输入学生的成绩:");
            fflush(stdin);
            if (scanf("%f", &temp->score) != EOF&&temp->score >= 0.0)
                break;
            else
                printf("你输入的格式错误,请重新输入!
    ");
            continue;
        }
        temp->next = p->next;
        p->next = temp;
    }
    int check_ID(char ID[]) {
        int i = 0, flag = 0;
        while (ID[i] != '') {
            if (ID[i]<'0' || ID[i]>'9') {
                flag = 1;
                break;
            }
            else
                i++;
        }
        return flag;
    }
    
    struct list *Selectsort(struct list *L)
    {
        float temp;
        struct list *p, *q, *m;
        if (!L->next || !L->next->next)return L;
        p = L->next;
        while (p->next)
        {
            m = p;
            q = p->next;
            while (q)
            {
                if (q->score<m->score)m = q;
                q = q->next;
    
            }
            if (p != m)
            {
                temp = m->score;
                m->score = p->score;
                p->score = temp;
            }
            p = p->next;
        }
    
        return L;
    }
    

    最后,附上几张测试图:
    这个是开始界面
    这个是输入界面
    这个是查询界面

    (。・∀・)ノ
  • 相关阅读:
    深入理解系统调用
    基于mykernel 2.0编写一个操作系统内核
    如何评测一个软件工程师的计算机网络知识水平与网络编程技能水平?
    如何评测软件工程知识技能水平?
    深入理解TCP的三次握手及其源代码
    Socket与系统调用深度分析
    未来的图书会是什么样子?
    构建调试Linux内核网络代码的环境MenuOS系统
    Python笔记005-神奇的+=
    Python笔记004-元组的拆包和命名元组
  • 原文地址:https://www.cnblogs.com/FlyerBird/p/9052587.html
Copyright © 2011-2022 走看看