怎么用C语言结构体链表和指针实现学生管理系统

今天小编给大家分享一下怎么用C语言结构体链表和指针实现学生管理系统的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

一、需求分析

通过使用“学生管理系统”,可以更加有效地对学生实现管理,完成对学生基本信息以及成绩信息的文件保存,具有信息的增加,删除、查询以及修改等功能,能提供简单的数据统计、分析信息。

二、整体设计

学生管理系统 主要由两大功能模块组成,分别是是“学生档案管理”和“学生成绩管理“两个子系统。整体模块架构如下:

三、详细设计

学生档案管理子系统

用户选择

进入“学生档案管理”子系统,显示该子系统菜单,用户分别可选择:录入数据、查询数据、修改数据、删除数据、增加数据、统计分析、退出系统等功能。

录入数据

主要实现函数为 readin_record( ) ,能引导用户输入学生人数,依次录入每个学生的学号、姓名、性别、出生日期、班级、生源地(具体到省、自治区和直辖市)等信息。采用结构体Stu_record数据类型保存学生档案信息。结构体中含有学号、姓名、性别、出生日期、班级、生源地(具体到省、自治区和直辖市)共六项信息。
数据存储由链表实现,读入数据完成后,按学号排序输出,并将其保存在磁盘文件Tdata_new.txt中。

查询数据

采用函数menu3_inquire_record ()。设置查询菜单,分为按学号查询id_inquiry_record()、按姓名查询name_inquiry_record()、按班级查询clas_inquiry_record()、按生源地查询syd_inquiry_record()、多条件组合查询(班级与生源地组合查询)clasSyd_inquiry_record()、全部显示search()、退出查询等功能。

修改数据

采用函数modify_record()。用户输入修改学生的学号,系统显示该生信息。用switch case语句设置修改选项,选择修改学号、姓名、性别、出生日期、班级、生源地、修改全部、保存并退出修改等。在磁盘文件Tdata_new.txt中修改相应信息。

删除数据

采用函数delete_record()。用户输入删除学生的学号,删除前系统提示用户再次确认是否删除。注意需要在学生成绩管理系统同步删除该生信息。

增加数据

采用函数add_record()。引导用户输入增加学生的学号、姓名、性别、出生日期、班级、生源地信息,更新磁盘文件。

统计分析

采用函数statistics_record()。显示各生源地的人数以及所占百分比。

学生成绩管理子系统

用户选择

进入“学生成绩管理”子系统,显示该子系统菜单,用户分别可选择:录入数据、查询数据、修改数据、删除数据、增加数据、统计分析、退出系统等功能。

录入数据

主要实现函数为 readin_score ( ) ,能引导用户输入学生人数,依次录入每个学生的学号、姓名、班级、课程成绩等信息。采用结构体Stu_score数据类型保存学生成绩信息。结构体中含有学号、姓名、班级、课程数据,其中课程数据包括3门课程的成绩以及平均成绩。
读入数据完成后,根据用户输入的3门课程成绩自动计算平均分avg, 将所有数据保存在磁盘文件Tscore_new.txt中。

查询数据

采用函数inquiry_score()。设置查询菜单,分为按学号查询id_inquiry_score()、按姓名查询name_inquiry_score()、按班级查询clas_inquiry_score()、退出查询等功能。

修改数据

采用函数modify_ score ()。用户输入修改学生的学号,系统显示该生信息。用switch case语句设置修改选项,选择修改学号、姓名、班级、课程1成绩、课程2成绩、课程3成绩、保存并退出修改等。在磁盘文件Tscore_new.txt中修改相应信息。

删除数据

采用函数delete_ score ()。用户输入删除学生的学号,删除前系统提示用户再次确认是否删除。注意需要在学生档案管理系统同步删除该生信息。

增加数据

采用函数add_ score ()。引导用户输入增加学生的学号、姓名、班级、课程1成绩、课程2成绩和课程3成绩。系统自动计算平均分。更新磁盘文件。

统计分析

采用函数menu3_statistics_score ()。设置统计分析菜单,分为按学生分析和按课程分析。若用户选择按学生分析stu_statistics_score(),该函数统计输出有不及格课程的学生的人数和其所占百分比。若用户选择按课程分析course_statistics_score(),该函数分析并输出每门课程的最高分、最低分、平均分。

四、代码实现

文件 main.c

#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include<stdio.h>
#include<malloc.h>
#include"student.h"

/*函数声明*/
void menu1();
void menu2_record();
void menu2_score();
int main()
{
    while(1)
    {
        int n;
        menu1();
        printf("请输入您的选择:\n");
        scanf("%d",&n);
        switch (n)
        {
            case 1: menu2_record() ;break;
            case 2: menu2_score() ;break;
            case 0: return 0;
            default: printf("您的选择错误,请重新输入。\n");
        }
        system("pause");
        system("cls");
    }
    return 0;
}

文件 student.h

#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include<stdio.h>
#include<malloc.h>

struct Date
{
    int year;
    int month;
    int day;
};
enum Depart {sdjinan,sdqingdao,sdyantai,sdweifang,sdheze,sddezhou,sdbinzhou,sdweihai};
struct Stu_record
{
    int id;
    char name[20];
    char sex[10];
    struct Date birth;
    int clas;
    enum Depart syd;
    struct Stu_record *next;
};
struct Stu_record *head = NULL;

struct Stu_score
{
    int id;
    char name[20];
    int clas;
    double course1;
    double course2;
    double course3;
    double avg;
    struct Stu_score *next;
};
/*函数声明*/
struct Stu_record *readin_record();
void menu3_inquire_record();
void id_inquiry_record(struct Stu_record *head);
void name_inquiry_record(struct Stu_record *head);
void clas_inquiry_record(struct Stu_record *head);
void syd_inquiry_record(struct Stu_record *head);
void clasSyd_inquiry_record(struct Stu_record *head);
void modify_record(struct Stu_record *head);
struct Stu_record *delete_record(struct Stu_record *head);
struct Stu_record *add_record(struct Stu_record *head);
void statistics_record(struct Stu_record *head);

struct Stu_score *readin_score();
void menu3_inquire_score();
void id_inquiry_score(struct Stu_score *head);
void name_inquiry_score(struct Stu_score *head);
void clas_inquiry_score(struct Stu_score *head);
void modify_score(struct Stu_score *head) ;
struct Stu_score *delete_score(struct Stu_score *head) ;
struct Stu_score *add_score(struct Stu_score *head) ;
void menu3_statistics_score();
void stu_statistics_score(struct Stu_score *head);
void course_statistics_score(struct Stu_score *head);
/********** 公共函数 **********/
struct Stu_record *insert(struct Stu_record *head, struct Stu_record *stu)
{
    struct Stu_record *p1, *p2;
    if (stu == NULL)
    {
        printf("请按照学号、姓名、性别、出生日期(如1999 9 9)、班级、生源地\n(0:山东济南 1:山东青岛 2:山东烟台 3:山东潍坊 4:山东菏泽 5:山东德州 6:山东滨州 7:山东威海)顺序输入\n");
        stu = (struct Stu_record *) malloc(sizeof(struct Stu_record));
        while (!scanf("%d %s %s %d %d %d %d %d", &stu->id, stu->name, stu->sex, &stu->birth.year, &stu->birth.month,&stu->birth.day,&stu->clas, &stu->syd))
        {
            printf("输入信息有误,请重新输入\n");
            fflush(stdin);
        }
    }
    if (head == NULL)
    {
        head = stu;
        head->next = NULL;
    }
    else
    {
        p1 = p2 = head;
        while (stu->id > p1->id && p1->next != NULL)
        {
            p2 = p1;
            p1 = p1->next;
        }
        if (p2 == p1)
        {
            if (stu->id < p2->id)
            {
                head = stu;
                stu->next = p2;
            }
            else
            {
                p2->next = stu;
                stu->next = NULL;
            }
        }
        else
        {
            if (stu->id < p1->id)
            {
                p2->next = stu;
                stu->next = p1;
            }
            else
            {
                p1->next = stu;
                stu->next = NULL;
            }
        }
    }
    return(head);
}
struct Stu_score *sinsert(struct Stu_score *head, struct Stu_score *stu)
{

    struct Stu_score *p1, *p2;
    if (stu == NULL)
    {

        printf("请按照学号、姓名、班级、课程1、课程2、课程3 顺序输入\n");
        stu = (struct Stu_score *) malloc(sizeof(struct Stu_score));
        while (!scanf("%d %s %d %lf %lf %lf", &stu->id, stu->name, &stu->clas, &stu->course1, &stu->course2,&stu->course3))
        {
            printf("输入信息有误,请重新输入\n");
            fflush(stdin);
        }

        stu->avg=(stu->course1+stu->course2+stu->course3)/3.0;
    }
    if (head == NULL)
    {
        head = stu;
        head->next = NULL;
    }
    else
    {
        p1 = p2 = head;
        while (stu->id > p1->id && p1->next != NULL)
        {
            p2 = p1;
            p1 = p1->next;
        }
        if (p2 == p1)
        {
            if (stu->id < p2->id)
            {
                head = stu;
                stu->next = p2;
            }
            else
            {
                p2->next = stu;
                stu->next = NULL;
            }
        }
        else
        {
            if (stu->id < p1->id)
            {
                p2->next = stu;
                stu->next = p1;
            }
            else
            {
                p1->next = stu;
                stu->next = NULL;
            }
        }
    }
    return(head);
}
void search(struct Stu_record *head)
{
    struct Stu_record *p1;
    if (head == NULL)
    {
        printf("没有学生信息,结束查询\n");
        return;
    }
    p1 = head;
    printf("  学号   姓名    性别    出生日期       班级    生源地  \n");
    printf("———————————————————————————\n");
    while (p1 != NULL)
    {
        printf("%-7d  %-4s  %-6s  %-4d年%-2d月%-2d日   %-6d  %-6d\n", p1->id, p1->name, p1->sex, p1->birth.year, p1->birth.month, p1->birth.day, p1->clas, p1->syd);
        p1 = p1->next;
    }
    printf("\n");
}
void ssearch(struct Stu_score *head)
{
    struct Stu_score *p1;
    if (head == NULL)
    {
        printf("没有学生信息,结束查询\n");
        return;
    }
    p1 = head;
    printf("  学号   姓名   班级    课程1     课程2    课程3    平均分  \n");
    printf("—————————————————————————————————\n");
    while (p1 != NULL)
    {
        printf("%-7d %-7s %-7d %-5.2lf    %-5.2lf    %-5.2lf   %-5.2lf\n", p1->id, p1->name, p1->clas, p1->course1, p1->course2, p1->course3, p1->avg);
        p1 = p1->next;
    }
    printf("\n");
}
/*** 一堆menu函数的定义 ***/
void menu1()
{

    printf("                                                       \n");
    printf("               欢迎进入学生管理系统                    \n");
    printf("-------------------------------------------------------\n");
    printf("                                                       \n");
    printf("*************StudentInformationManagement**************\n");
    printf("*                                                     *\n");
    printf("*\t\t1.进入学生档案管理子系统              *\n");
    printf("*                                                     *\n");
    printf("*\t\t2.进入学生成绩管理子系统              *\n");
    printf("*                                                     *\n");
    printf("*\t\t0.退出系统                            *\n");
    printf("*                                                     *\n");
    printf("*******************************************************\n\n");

}
void menu2_record()
{
    while(1)
    {
        int n;
        printf("********学生档案管理*********\n");
        printf("*                           *\n");
        printf("*\t1.录入数据          *\n");
        printf("*\t2.查询数据          *\n");
        printf("*\t3.修改数据          *\n");
        printf("*\t4.删除数据          *\n");
        printf("*\t5.增加数据          *\n");
        printf("*\t6.统计分析          *\n");
        printf("*\t0.退出系统          *\n");
        printf("*                           *\n");
        printf("*****************************\n\n");

        printf("请输入您的选择:\n");
        scanf("%d",&n);
        switch (n)
        {
        case 1:
            readin_record() ;
            break;
        case 2:
            menu3_inquire_record() ;
            break;
        case 3:
            modify_record(head) ;
            break;
        case 4:
            delete_record(head) ;
            break;
        case 5:
            head=add_record(head);
            search(head);
            break;
        case 6:
            statistics_record(head) ;
            break;
        case 0:
            return;
        default:
            printf("您的选择错误,请重新输入。\n");
        }
        system("pause");
        system("cls");
    }
}
void menu2_score()
{
    while(1)
    {
        int n;
        printf("********学生成绩管理*********\n");
        printf("*                           *\n");
        printf("*\t1.录入数据          *\n");
        printf("*\t2.查询数据          *\n");
        printf("*\t3.修改数据          *\n");
        printf("*\t4.删除数据          *\n");
        printf("*\t5.增加数据          *\n");
        printf("*\t6.统计分析          *\n");
        printf("*\t0.退出系统          *\n");
        printf("*                           *\n");
        printf("*****************************\n\n");

        printf("请输入您的选择:\n");
        scanf("%d",&n);
        switch (n)
        {
        case 1:
            readin_score() ;
            break;
        case 2:
            menu3_inquire_score();
            break;
        case 3:
            modify_score(head);
            break;
        case 4:
            delete_score(head);
            break;
        case 5:
            head=add_score(head);
            ssearch(head);
            break;
        case 6:
            menu3_statistics_score() ;
            break;
        case 0:
            return;
        default:
            printf("您的选择错误,请重新输入。\n");
        }
        system("pause");
        system("cls");
    }
}
void menu3_inquire_record()
{
    while(1)
    {
        int n;
        printf("************查询菜单*************\n");
        printf("*                               *\n");
        printf("*\t1.按学号查询            *\n");
        printf("*\t2.按姓名查询            *\n");
        printf("*\t3.按班级查询            *\n");
        printf("*\t4.按生源地查询          *\n");
        printf("*\t5.多条件组合查询        *\n");
        printf("*\t6.全部显示              *\n");
        printf("*\t0.退出查询              *\n");
        printf("*                               *\n");
        printf("*********************************\n\n");

        printf("请输入您的选择:\n");
        scanf("%d",&n);
        switch (n)
        {
        case 1:
            id_inquiry_record(head);
            break;
        case 2:
            name_inquiry_record(head) ;
            break;
        case 3:
            clas_inquiry_record(head) ;
            break;
        case 4:
            syd_inquiry_record(head) ;
            break;
        case 5:
            clasSyd_inquiry_record(head) ;
            break;
        case 6:
            search(head);
            break;
        case 0:
            return;
        default:
            printf("您的选择错误,请重新输入。\n");
        }
        system("pause");
        system("cls");
    }

}
void menu3_inquire_score()
{
    while(1)
    {
        int n;
        printf("************查询菜单*************\n");
        printf("*                               *\n");
        printf("*\t1.按学号查询            *\n");
        printf("*\t2.按姓名查询            *\n");
        printf("*\t3.按班级查询            *\n");
        printf("*\t4.全部显示              *\n");
        printf("*\t0.退出查询              *\n");
        printf("*                               *\n");
        printf("*********************************\n\n");

        printf("请输入您的选择:\n");
        scanf("%d",&n);
        switch (n)
        {
        case 1:
            id_inquiry_score(head);
            break;
        case 2:
            name_inquiry_score(head) ;
            break;
        case 3:
            clas_inquiry_score(head) ;
            break;
        case 4:
            ssearch(head);
            break;
        case 0:
            return;
        default:
            printf("您的选择错误,请重新输入。\n");
        }
        system("pause");
        system("cls");
    }
}
void menu3_statistics_score()
{
     while(1)
    {
        int n;
        printf("************统计分析*************\n");
        printf("*                               *\n");
        printf("*\t1.按学生分析            *\n");
        printf("*\t2.按课程分析            *\n");
        printf("*\t0.退出统计分析          *\n");
        printf("*                               *\n");
        printf("*********************************\n\n");

        printf("请输入您的选择:\n");
        scanf("%d",&n);
        switch (n)
        {
        case 1:
            stu_statistics_score(head);
            break;
        case 2:
            course_statistics_score(head) ;
            break;
        case 0:
            return;
        default:
            printf("您的选择错误,请重新输入。\n");
        }
        system("pause");
        system("cls");
    }
}
/****** record中函数 ******/
struct Stu_record *readin_record()
{
    struct Stu_record *p2,*p1;
    int n,i;
    head=NULL;
    FILE *w;
    if ((w = fopen("C:\\Desktop\\Tdata_new.txt", "wb+")) == NULL)
    {
        printf("cannot open file\n");
        exit(1);
    }

    printf("请输入学生人数: \n");
    scanf("%d",&n);
    head=p2=p1=(struct Stu_record *) malloc(sizeof(struct Stu_record));                                //开辟内存,用于生成链表
    printf("学生个数为:%d个,请按照以下顺序输入\n", n);                            //对学生总数的提示,并且提示每个学生信息的输入顺序
    printf("学号、姓名、性别、出生日期(如1999 9 9)、班级、生源地\n(0:山东济南 1:山东青岛 2:山东烟台 3:山东潍坊 4:山东菏泽 5:山东德州 6:山东滨州 7:山东威海)\n");    //每个学生信息的输入顺序
    for (i = 0; i < n; i++)
    {
        while (!scanf("%d %s %s %d %d %d %d %d", &p2->id, p2->name, p2->sex, &p2->birth.year, &p2->birth.month,&p2->birth.day,&p2->clas, &p2->syd))
        {
            printf("输入有误,请重新输入该学生信息\n   ");
            fflush(stdin);
        }
        if (n == 1)
        {
            p2->next = NULL;
        }
        else
        {
            head = insert(head, p2);
            p2 = (struct Student *) malloc(sizeof(struct Stu_record));
        }
    }
    p1=head;
    while(p1!=NULL)
    {
        fprintf(w,"%d %s %s %d %d %d %d %d\n", p1->id, p1->name, p1->sex, p1->birth.year, p1->birth.month,p1->birth.day,p1->clas, p1->syd);
        p1= p1->next;
    }
    fclose(w);
    printf("成功录入%d名学生信息,学生信息已经按学号从小到大排列,信息如下: \n\n",n);
    search(head);
    return head;
}
void id_inquiry_record(struct Stu_record *head)
{
    int cho, t = 1;
    int num;
    struct Stu_record *p1;
    if (head == NULL)
    {
        printf("没有学生信息,结束查询\n");
        return;
    }
    p1 = head;
    do
    {
        p1 = head;
        if ( t == 1)
        {
            printf("请输入需要查询的学生学号: ");
            while (!scanf("%d", &num))
            {
                printf("输入有误,请重新输入: ");
                fflush(stdin);
            }
            t = 1;
        }
        else
        {
            cho = 2;
        }
        while (p1->id != num)
        {
            if (p1->next == NULL)
                break;
            p1 = p1->next;
        }
        if (p1->id == num)
        {
            printf("  学号   姓名    性别    出生日期       班级    生源地  \n");
            printf("———————————————————————————\n");
            printf("%-7d  %-4s  %-6s  %-4d年%-2d月%-2d日   %-6d  %-6d\n", p1->id, p1->name, p1->sex, p1->birth.year, p1->birth.month, p1->birth.day, p1->clas, p1->syd);
        }
        else
        {
            printf("找不到该学生\n");
        }
        if (t == 1)
        {
            printf("1.继续查询\n");
            printf("2.结束查询\n");
            printf("请选择: ");
            while (!scanf("%d", &cho))
            {
                printf("输入序号有误,请重新输入: ");
                fflush(stdin);
            }
        }
    }
    while(cho==1);
}
void name_inquiry_record(struct Stu_record *head)
{
    int cho, t = 1;
    char qname[20];
    struct Stu_record *p1;
    if (head == NULL)
    {
        printf("没有学生信息,结束查询\n");
        return;
    }
    p1 = head;
    do
    {
        p1 = head;
        if ( t == 1)
        {
            printf("请输入需要查询的学生姓名: ");
            while (!scanf("%s", qname))
            {
                printf("输入有误,请重新输入: ");
                fflush(stdin);
            }
            t = 1;
        }
        else
        {
            cho = 2;
        }
        while (strcmp(p1->name,qname)!=0)
        {
            if (p1->next == NULL)
                break;
            p1 = p1->next;
        }
        if (strcmp(p1->name,qname)==0)
        {
            printf("  学号   姓名    性别    出生日期       班级    生源地  \n");
            printf("———————————————————————————\n");
            printf("%-7d  %-4s  %-6s  %-4d年%-2d月%-2d日   %-6d  %-6d\n", p1->id, p1->name, p1->sex, p1->birth.year, p1->birth.month, p1->birth.day, p1->clas, p1->syd);
        }
        else
        {
            printf("找不到该学生\n");
        }
        if (t == 1)
        {
            printf("1.继续查询\n");
            printf("2.结束查询\n");
            printf("请选择: ");
            while (!scanf("%d", &cho))
            {
                printf("输入序号有误,请重新输入: ");
                fflush(stdin);
            }
        }
    }
    while(cho==1);
}
void clas_inquiry_record(struct Stu_record *head)
{
    int cho, t = 1;
    struct Stu_record *p1;
    int qclas;
    if (head == NULL)
    {
        printf("没有学生信息,结束查询\n");
        return;
    }
    p1 = head;
    do
    {
        p1 = head;
        if (t == 1)
        {
            printf("请输入需要查询的学生班级: ");
            while (!scanf("%d", &qclas))
            {
                printf("输入有误,请重新输入: ");
                fflush(stdin);
            }
            t = 1;
        }
        else
        {
            cho = 2;
        }
        while (p1->clas != qclas)
        {
            if (p1->next == NULL)
                break;
            p1 = p1->next;
        }
        if (p1->clas == qclas)
        {
            printf("  学号   姓名    性别    出生日期       班级    生源地  \n");
            printf("———————————————————————————\n");
            printf("%-7d  %-4s  %-6s  %-4d年%-2d月%-2d日   %-6d  %-6d\n", p1->id, p1->name, p1->sex, p1->birth.year, p1->birth.month, p1->birth.day, p1->clas, p1->syd);
        }
        else
        {
            printf("找不到该学生\n");
        }
        if (t == 1)
        {
            printf("1.继续查询\n");
            printf("2.结束查询\n");
            printf("请选择: ");
            while (!scanf("%d", &cho))
            {
                printf("输入序号有误,请重新输入: ");
                fflush(stdin);
            }
        }
    }
    while(cho==1);

}
void syd_inquiry_record(struct Stu_record *head)
{
    int cho,t = 1;
    struct Stu_record *p1;
    int qsyd;
    if (head == NULL)
    {
        printf("没有学生信息,结束查询\n");
        return;
    }
    p1 = head;
    do
    {
        p1 = head;
        if ( t == 1)
        {
            printf("请输入需要查询的学生生源地: ");
            printf("(0:山东济南 1:山东青岛 2:山东烟台 3:山东潍坊 4:山东菏泽 5:山东德州 6:山东滨州 7:山东威海)\n");
            while (!scanf("%d", &qsyd))
            {
                printf("输入有误,请重新输入: ");
                fflush(stdin);
            }
            t = 1;
        }
        else
        {
            cho = 2;
        }
        while (p1->syd != qsyd)
        {
            if (p1->next == NULL)
                break;
            p1 = p1->next;
        }
        if (p1->syd == qsyd)
        {
            printf("  学号   姓名    性别    出生日期       班级    生源地  \n");
            printf("———————————————————————————\n");
            printf("%-7d  %-4s  %-6s  %-4d年%-2d月%-2d日   %-6d  %-6d\n", p1->id, p1->name, p1->sex, p1->birth.year, p1->birth.month, p1->birth.day, p1->clas, p1->syd);
        }
        else
        {
            printf("找不到该学生\n");
        }
        if (t == 1)
        {
            printf("1.继续查询\n");
            printf("2.结束查询\n");
            printf("请选择: ");
            while (!scanf("%d", &cho))
            {
                printf("输入序号有误,请重新输入: ");
                fflush(stdin);
            }
        }
    }
    while(cho==1);

}
void clasSyd_inquiry_record(struct Stu_record *head)
{
    int cho, t = 1;
    struct Stu_record *p1;
    int qsyd,qclas;
    if (head == NULL)
    {
        printf("没有学生信息,结束查询\n");
        return;
    }
    p1 = head;
    do
    {
        p1 = head;
        if ( t == 1)
        {
            printf("请输入需要查询的学生生源地: ");
            while (!scanf("%d", &qsyd))
            {
                printf("输入有误,请重新输入: ");
                fflush(stdin);
            }
            printf("请输入需要查询的学生班级: ");
            while (!scanf("%d", &qclas))
            {
                printf("输入有误,请重新输入: ");
                fflush(stdin);
            }
            t = 1;
        }
        else
        {
            cho = 2;
        }
        while (p1->syd != qsyd||p1->clas != qclas)
        {
            if (p1->next == NULL)
                break;
            p1 = p1->next;
        }
        if (p1->syd == qsyd&&p1->clas == qclas)
        {
            printf("  学号   姓名    性别    出生日期       班级    生源地  \n");
            printf("———————————————————————————\n");
            printf("%-7d  %-4s  %-6s  %-4d年%-2d月%-2d日   %-6d  %-6d\n", p1->id, p1->name, p1->sex, p1->birth.year, p1->birth.month, p1->birth.day, p1->clas, p1->syd);
        }
        else
        {
            printf("找不到该学生\n");
        }
        if (t == 1)
        {
            printf("1.继续查询\n");
            printf("2.结束查询\n");
            printf("请选择: ");
            while (!scanf("%d", &cho))
            {
                printf("输入序号有误,请重新输入: ");
                fflush(stdin);
            }
        }
    }
    while(cho==1);

}
void modify_record(struct Stu_record *head)
{
    struct Stu_record *p1, *p2;
    int num,cho,k=1,l=0;
    FILE *w;

    if (head == NULL)
    {
        printf("没有学生信息,结束修改\n   ");
        system("pause");
        return;
    }
    printf("请输入需要修改的学生学号: ");
    while (!scanf("%d",&num))
    {
        printf("输入学号有误,请重新输入: ");
        fflush(stdin);
    }
    do
    {
        p2 = p1 = head;
        while (p1->id != num)
        {
            if (p1->next == NULL)
                break;
            p2 = p1;
            p1 = p1->next;
        }
        if (p1->id == num)
        {
            printf("已找到该学生,该学生的信息为: \n");
            printf("生源地(0:山东济南 1:山东青岛 2:山东烟台 3:山东潍坊 4:山东菏泽 5:山东德州 6:山东滨州 7:山东威海)\n");
            printf("学号   姓名    性别    出生日期       班级    生源地  \n");
            printf("———————————————————————————\n");
            printf("%-7d  %-4s  %-6s  %-4d年%-2d月%-2d日   %-6d  %-6d\n", p1->id, p1->name, p1->sex, p1->birth.year, p1->birth.month, p1->birth.day, p1->clas, p1->syd);
            l = 0;
            do
            {
                if (l == 0)
                    printf("\n选择修改的内容\n");
                else
                    printf("序号输入错误,请重新选择\n");
                l = 1;
                printf("   1.学号\n");
                printf("   2.姓名\n");
                printf("   3.性别\n");
                printf("   4.出生日期\n");
                printf("   5.班级\n");
                printf("   6.生源地\n");
                printf("   7.全部\n");
                printf("请选择序号: ");
                fflush(stdin);
                while (!scanf("%d", &cho))
                {
                    printf("输入序号有误,请重新输入: ");
                    fflush(stdin);
                }
            }
            while (cho > 7 || cho < 1);
            switch (cho)
            {
            case 1:
            {
                printf("请输入该学生改正的学号信息: ");
                while (!scanf("%d", &p1->id))
                {
                    printf("输入改正信息有误,请重新输入: ");
                    fflush(stdin);
                }
                break;
            }
            case 2:
            {
                printf("请输入该学生改正的姓名信息: ");
                while (!scanf("%s", p1->name))
                {
                    printf("输入改正信息有误,请重新输入: ");
                    fflush(stdin);
                }
                break;
            }
            case 3:
            {
                printf("请输入该学生改正的性别信息: ");
                while (!scanf("%s", p1->sex))
                {
                    printf("输入改正信息有误,请重新输入: ");
                    fflush(stdin);
                }
                break;
            }
            case 4:
            {
                printf("请输入该学生改正的出生年月信息(如输入1999 9 9): ");
                while (!scanf("%d %d %d", &p1->birth.year,&p1->birth.month,&p1->birth.day))
                {
                    printf("输入改正信息有误,请重新输入: ");
                    fflush(stdin);
                }
                break;
            }
            case 5:
            {
                printf("请输入该学生改正的班级信息: ");
                while (!scanf("%d",&p1->clas))
                {
                    printf("输入改正信息有误,请重新输入: ");
                    fflush(stdin);
                }
                break;
            }
            case 6:
            {
                printf("请输入该学生改正的生源地信息: ");
                printf("生源地(0:山东济南 1:山东青岛 2:山东烟台 3:山东潍坊 4:山东菏泽 5:山东德州 6:山东滨州 7:山东威海)\n");
                while (!scanf("%d",&p1->syd))
                {
                    printf("输入改正信息有误,请重新输入: ");
                    fflush(stdin);
                }
                break;
            }
            case 7:
            {
                printf("请输入该学生全部要改正的信息: ");
                while (!scanf("%d %s %s %d %d %d %d %d",&p1->id, p1->name, p1->sex, &p1->birth.year, &p1->birth.month, &p1->birth.day, &p1->clas, &p1->syd))
                {
                    printf("输入改正信息有误,请重新输入: ");
                    fflush(stdin);
                }
                break;
            }
            }
            if (cho == 1 || cho == 7)
            {
                if (p1 == head)
                {
                    head = head->next;
                }
                else if (p1->next == NULL)
                {
                    p2->next = NULL;
                }
                else
                {
                    p2->next = p1->next;
                }
                head = insert(head,p1);
            }
            printf("修改成功,该学生改正后的信息为: \n");
            printf("  学号   姓名    性别    出生日期       班级    生源地  \n");
            printf("———————————————————————————\n");
            printf("%-7d  %-4s  %-6s  %-4d年%-2d月%-2d日   %-6d  %-6d\n", p1->id, p1->name, p1->sex, p1->birth.year, p1->birth.month, p1->birth.day, p1->clas, p1->syd);
            printf("   1.继续修改其他学生信息\n");
            printf("   2.退出修改\n");
            printf("请选择: ");
            while (!scanf("%d",&k))
            {
                printf("输入序号有误,请重新输入: ");
                fflush(stdin);
            }
            if (k == 1)
            {
                printf("请输入需要修改的学生学号: ");
                while (!scanf("%d", &num))
                {
                    printf("输入修改信息有误,请重新输入: ");
                    fflush(stdin);
                }
            }
            else if (k != 2)
            {
                printf("输入有误,请重新输入\n");
            }
            if ((w = fopen("C:\\Desktop\\Tdata_new.txt", "wb+")) == NULL)
            {
                printf("cannot open file\n");
                exit(1);
            }
            p1=head;
            while(p1!=NULL)
            {
                fprintf(w,"%d %s %s %d %d %d %d %d\n", p1->id, p1->name, p1->sex, p1->birth.year, p1->birth.month,p1->birth.day,p1->clas, p1->syd);
                p1= p1->next;
            }
            fclose(w);
        }
        else
        {
            k = 1;
            printf("找不到该学生信息,请重新输入需要修改的学生学号: ");
            fflush(stdin);
            while (!scanf("%d", &num))
            {
                printf("输入修改信息有误,请重新输入: ");
                fflush(stdin);
            }
        }
    }
    while(k == 1);
    printf("   ");
    system("pause");
}
struct Stu_record *delete_record(struct Stu_record *head)
{
    int num,k;
    FILE *w;
    struct Stu_record *p1,*p2;
    if(head == NULL)
    {
        printf("没有学生信息,结束删除\n");
        return(head);
    }
    printf("请输入要删除的学生学号: ");
    while (!scanf("%d", &num))
    {
        printf("输入有误,请重新输入学生学号: ");
        fflush(stdin);
    }
    do
    {
        p1 = p2 = head;
        while (num != p1->id && p1->next != NULL)
        {
            p2 = p1;
            p1 = p1->next;
        }
        if (num == p1->id)
        {
            if (num == p1->id)
            {
                if (p1->next == NULL && p1 == head)
                {
                    free(p1);
                    head = NULL;
                }
                else if (p1->next == NULL)//如果删除完表空了 把表删除
                {
                    free(p1);
                    p2->next = NULL;
                }
                else if (head == p1)
                {
                    head = p1->next;
                    free(p1);
                }
                else
                {
                    p2->next = p1->next;
                    free(p1);
                }
            }
            printf("成功删除学生信息\n");
        }
        else
        {
            printf("找不到该同学信息\n");
            fflush(stdin);
        }
        if (head == NULL)
        {
            printf("没有学生信息,结束删除\n");
            return(head);
        }
        else
        {
            printf("   1.继续删除学生信息\n");
            printf("   2.结束删除\n");
            printf("请选择: ");
            while (!scanf("%d",&k))
            {
                printf("输入有误,请重新输入选择的序号: ");
                fflush(stdin);
            }
            if (k == 1)
            {
                printf("请输入要删除的学生学号: ");
                while (!scanf("%d", &num))
                {
                    printf("输入有误,请重新输入学生学号: ");
                    fflush(stdin);
                }
            }
            else if (k != 2)
            {
                k = 1;
            }
            if ((w = fopen("C:\\Desktop\\Tdata_new.txt", "wb+")) == NULL)
            {
                printf("cannot open file\n");
                exit(1);
            }
            p1=head;
            while(p1!=NULL)
            {
                fprintf(w,"%d %s %s %d %d %d %d %d\n", p1->id, p1->name, p1->sex, p1->birth.year, p1->birth.month,p1->birth.day,p1->clas, p1->syd);
                p1= p1->next;
            }
            fclose(w);
        }
    }
    while (k == 1);
    return(head);
}
struct Stu_record *add_record(struct Stu_record *head)
{
    FILE *w;
    int i,num;
    struct Stu_record *p1;
    head = insert(head, NULL);
    printf("   成功插入学生信息\n   ");

    if ((w = fopen("C:\\Desktop\\Tdata_new.txt", "wb+")) == NULL)
    {
        printf("cannot open file\n");
        exit(1);
    }
    p1=head;
    while(p1!=NULL)
    {
        fprintf(w,"%d %s %s %d %d %d %d %d\n", p1->id, p1->name, p1->sex, p1->birth.year, p1->birth.month,p1->birth.day,p1->clas, p1->syd);
        p1= p1->next;
    }
    fclose(w);

    return head;
}
void statistics_record(struct Stu_record *head)
{
    double cnt[8];
    int i;
    double sum=0;
    struct Stu_record *p1;
    p1 = head;
    memset(cnt,0,sizeof(cnt));
    printf("统计各生源地人数及所占百分比:\n");
    while (1)
    {
        sum++;
        for(i=0;i<8;i++)
        {
            if(p1->syd==i) cnt[i]++;
        }
        if (p1->next == NULL)
            break;
        p1 = p1->next;
    }
    printf("全体学生人数:%.0lf人\n\n",sum);
    printf("山东济南:%.0lf人 %5.2lf%%\n",cnt[0],(cnt[0]/sum)*100);
    printf("山东青岛:%.0lf人 %5.2lf%%\n",cnt[1],(cnt[1]/sum)*100);
    printf("山东烟台:%.0lf人 %5.2lf%%\n",cnt[2],(cnt[2]/sum)*100);
    printf("山东潍坊:%.0lf人 %5.2lf%%\n",cnt[3],(cnt[3]/sum)*100);
    printf("山东菏泽:%.0lf人 %5.2lf%%\n",cnt[4],(cnt[4]/sum)*100);
    printf("山东德州:%.0lf人 %5.2lf%%\n",cnt[5],(cnt[5]/sum)*100);
    printf("山东滨州:%.0lf人 %5.2lf%%\n",cnt[6],(cnt[6]/sum)*100);
    printf("山东威海:%.0lf人 %5.2lf%%\n\n",cnt[7],(cnt[7]/sum)*100);
}
/*** score中的函数 ***/
struct Stu_score *readin_score()
{
    struct Stu_score *p2,*p1;
    int n,i;
    head=NULL;
    FILE *w;
    if ((w = fopen("C:\\Desktop\\Tscore_new.txt", "wb+")) == NULL)
    {
        printf("cannot open file\n");
        exit(1);
    }

    printf("请输入学生人数: \n");
    scanf("%d",&n);
    head=p2=p1=(struct Stu_score *) malloc(sizeof(struct Stu_score));                                //开辟内存,用于生成链表
    printf("学生个数为:%d个,请按照以下顺序输入\n", n);                            //对学生总数的提示,并且提示每个学生信息的输入顺序
    printf("学号、姓名、班级、课程1、课程2、课程3\n");    //每个学生信息的输入顺序
    for (i = 0; i < n; i++)
    {
        while (!scanf("%d %s %d %lf %lf %lf", &p2->id, p2->name, &p2->clas, &p2->course1, &p2->course2,&p2->course3))
        {
            printf("输入有误,请重新输入该学生信息\n   ");
            fflush(stdin);
        }
        p2->avg = (p2->course1+p2->course2+p2->course3)/3.0;
        if (n == 1)
        {
            p2->next = NULL;
        }
        else
        {
            head = sinsert(head, p2);
            p2 = (struct Stu_score *) malloc(sizeof(struct Stu_score));
        }
    }
    p1=head;
    while(p1!=NULL)
    {
        fprintf(w,"%d %s %d %lf %lf %lf\n",p2->id, p2->name, p2->clas, p2->course1, p2->course2,p2->course3,p2->avg);
        p1= p1->next;
    }
    fclose(w);
    printf("成功录入%d名学生成绩信息,学生成绩信息已经按学号从小到大排列,信息如下: \n\n",n);
    ssearch(head);
    return head;
}
void id_inquiry_score(struct Stu_score *head)
{
    int cho, t = 1;
    int num;
    struct Stu_score *p1;
    if (head == NULL)
    {
        printf("没有学生信息,结束查询\n");
        return;
    }
    p1 = head;
    do
    {
        p1 = head;
        if ( t == 1)
        {
            printf("请输入需要查询的学生学号: ");
            while (!scanf("%d", &num))
            {
                printf("输入有误,请重新输入: ");
                fflush(stdin);
            }
            t = 1;
        }
        else
        {
            cho = 2;
        }
        while (p1->id != num)
        {
            if (p1->next == NULL)
                break;
            p1 = p1->next;
        }
        if (p1->id == num)
        {
            printf("  学号   姓名   班级    课程1     课程2    课程3    平均分  \n");
            printf("—————————————————————————————————\n");
            printf("%-7d %-7s %-7d %-5.2lf    %-5.2lf    %-5.2lf   %-5.2lf\n", p1->id, p1->name, p1->clas, p1->course1, p1->course2, p1->course3, p1->avg);
        }
        else
        {
            printf("找不到该学生\n");
        }
        if (t == 1)
        {
            printf("1.继续查询\n");
            printf("2.结束查询\n");
            printf("请选择: ");
            while (!scanf("%d", &cho))
            {
                printf("输入序号有误,请重新输入: ");
                fflush(stdin);
            }
        }
    }
    while(cho==1);
}
void name_inquiry_score(struct Stu_score *head)
{
    int cho, t = 1;
    char qname[20];
    struct Stu_score *p1;
    if (head == NULL)
    {
        printf("没有学生信息,结束查询\n");
        return;
    }
    p1 = head;
    do
    {
        p1 = head;
        if ( t == 1)
        {
            printf("请输入需要查询的学生姓名: ");
            while (!scanf("%s",qname))
            {
                printf("输入有误,请重新输入: ");
                fflush(stdin);
            }
            t = 1;
        }
        else
        {
            cho = 2;
        }
        while (strcmp(p1->name,qname)!=0)
        {
            if (p1->next == NULL)
                break;
            p1 = p1->next;
        }
        if (strcmp(p1->name,qname)==0)
        {
            printf("  学号   姓名   班级    课程1     课程2    课程3    平均分  \n");
            printf("—————————————————————————————————\n");
            printf("%-7d %-7s %-7d %-5.2lf    %-5.2lf    %-5.2lf   %-5.2lf\n", p1->id, p1->name, p1->clas, p1->course1, p1->course2, p1->course3, p1->avg);
        }
        else
        {
            printf("找不到该学生\n");
        }
        if (t == 1)
        {
            printf("1.继续查询\n");
            printf("2.结束查询\n");
            printf("请选择: ");
            while (!scanf("%d", &cho))
            {
                printf("输入序号有误,请重新输入: ");
                fflush(stdin);
            }
        }
    }
    while(cho==1);
}
void clas_inquiry_score(struct Stu_score *head)
{
    int cho, t = 1;
    int qclas;
    struct Stu_score *p1;
    if (head == NULL)
    {
        printf("没有学生信息,结束查询\n");
        return;
    }
    p1 = head;
    do
    {
        p1 = head;
        if ( t == 1)
        {
            printf("请输入需要查询的学生班级: ");
            while (!scanf("%d", &qclas))
            {
                printf("输入有误,请重新输入: ");
                fflush(stdin);
            }
            t = 1;
        }
        else
        {
            cho = 2;
        }
        while (p1->clas != qclas)
        {
            if (p1->next == NULL)
                break;
            p1 = p1->next;
        }
        if (p1->clas == qclas)
        {
            printf("  学号   姓名   班级    课程1     课程2    课程3    平均分  \n");
            printf("—————————————————————————————————\n");
            printf("%-7d %-7s %-7d %-5.2lf    %-5.2lf    %-5.2lf   %-5.2lf\n", p1->id, p1->name, p1->clas, p1->course1, p1->course2, p1->course3, p1->avg);
        }
        else
        {
            printf("找不到该学生\n");
        }
        if (t == 1)
        {
            printf("1.继续查询\n");
            printf("2.结束查询\n");
            printf("请选择: ");
            while (!scanf("%d", &cho))
            {
                printf("输入序号有误,请重新输入: ");
                fflush(stdin);
            }
        }
    }
    while(cho==1);
}
void modify_score(struct Stu_score *head)
{
    struct Stu_score *p1, *p2;
    int num,cho,k=1,l=0;
    FILE *w;

    if (head == NULL)
    {
        printf("没有学生成绩信息,结束修改\n ");
        system("pause");
        return;
    }
    printf("请输入需要修改的学生学号: ");
    while (!scanf("%d",&num))
    {
        printf("输入学号有误,请重新输入: ");
        fflush(stdin);
    }
    do
    {
        p2 = p1 = head;
        while (p1->id != num)
        {
            if (p1->next == NULL)
                break;
            p2 = p1;
            p1 = p1->next;
        }
        if (p1->id == num)
        {
            printf("已找到该学生,该学生的信息为: \n");
            printf("  学号   姓名   班级    课程1     课程2    课程3    平均分  \n");
            printf("—————————————————————————————————\n");
            printf("%-7d %-7s %-7d %-5.2lf    %-5.2lf    %-5.2lf   %-5.2lf\n", p1->id, p1->name, p1->clas, p1->course1, p1->course2, p1->course3, p1->avg);
            l = 0;
            do
            {
                if (l == 0)
                    printf("\n选择修改的内容\n");
                else
                    printf("序号输入错误,请重新选择\n");
                l = 1;
                printf("   1.学号\n");
                printf("   2.姓名\n");
                printf("   3.班级\n");
                printf("   4.课程1成绩\n");
                printf("   5.课程2成绩\n");
                printf("   6.课程3成绩\n");
                printf("   7.全部\n");
                printf("请选择序号: ");
                fflush(stdin);
                while (!scanf("%d", &cho))
                {
                    printf("输入序号有误,请重新输入: ");
                    fflush(stdin);
                }
            }
            while (cho > 7 || cho < 1);
            switch (cho)
            {
            case 1:
            {
                printf("请输入该学生改正的学号信息: ");
                while (!scanf("%d", &p1->id))
                {
                    printf("输入改正信息有误,请重新输入: ");
                    fflush(stdin);
                }
                break;
            }
            case 2:
            {
                printf("请输入该学生改正的姓名信息: ");
                while (!scanf("%s", p1->name))
                {
                    printf("输入改正信息有误,请重新输入: ");
                    fflush(stdin);
                }
                break;
            }
            case 3:
            {
                printf("请输入该学生改正的班级信息: ");
                while (!scanf("%d", &p1->clas))
                {
                    printf("输入改正信息有误,请重新输入: ");
                    fflush(stdin);
                }
                break;
            }
            case 4:
            {
                printf("请输入该学生改正的课程1成绩信息: ");
                while (!scanf("%lf", &p1->course1))
                {
                    printf("输入改正信息有误,请重新输入: ");
                    fflush(stdin);
                }
                p1->avg=(p1->course1+p1->course2+p1->course3)/3.0;
                break;
            }
            case 5:
            {
                printf("请输入该学生改正的课程2成绩信息: ");
                while (!scanf("%lf",&p1->course2))
                {
                    printf("输入改正信息有误,请重新输入: ");
                    fflush(stdin);
                }
                p1->avg=(p1->course1+p1->course2+p1->course3)/3.0;
                break;
            }
            case 6:
            {
                printf("请输入该学生改正的课程3成绩信息: ");
                while (!scanf("%lf",&p1->course3))
                {
                    printf("输入改正信息有误,请重新输入: ");
                    fflush(stdin);
                }
                p1->avg=(p1->course1+p1->course2+p1->course3)/3.0;
                break;
            }
            case 7:
            {
                printf("请输入该学生全部要改正的信息: ");
                while (!scanf("%d %s %d %lf %lf %lf",&p1->id, p1->name, &p1->clas, &p1->course1, &p1->course2, &p1->course3))
                {
                    printf("输入改正信息有误,请重新输入: ");
                    fflush(stdin);
                }
                p1->avg=(p1->course1+p1->course2+p1->course3)/3.0;
                break;
            }
            }
            if (cho == 1 || cho == 7)
            {
                if (p1 == head)
                {
                    head = head->next;
                }
                else if (p1->next == NULL)
                {
                    p2->next = NULL;
                }
                else
                {
                    p2->next = p1->next;
                }
                head = sinsert(head,p1);
            }
            printf("  学号   姓名   班级    课程1     课程2    课程3    平均分  \n");
            printf("—————————————————————————————————\n");
            printf("%-7d %-7s %-7d %-5.2lf    %-5.2lf    %-5.2lf   %-5.2lf\n", p1->id, p1->name, p1->clas, p1->course1, p1->course2, p1->course3, p1->avg);
            l = 0;
            printf("   1.继续修改其他学生信息\n");
            printf("   2.退出修改\n");
            printf("请选择: ");
            while (!scanf("%d",&k))
            {
                printf("输入序号有误,请重新输入: ");
                fflush(stdin);
            }
            if (k == 1)
            {
                printf("请输入需要修改的学生学号: ");
                while (!scanf("%d", &num))
                {
                    printf("输入修改信息有误,请重新输入: ");
                    fflush(stdin);
                }
            }
            else if (k != 2)
            {
                printf("输入有误,请重新输入\n");
            }
            if ((w = fopen("C:\\Desktop\\Tscore_new.txt", "wb+")) == NULL)
            {
                printf("cannot open file\n");
                exit(1);
            }
            p1=head;
            while(p1!=NULL)
            {
                fprintf(w,"%d %s %d %lf %lf %lf %lf \n", p1->id, p1->name, p1->clas, p1->course1, p1->course2,p1->course3,p1->avg);
                p1= p1->next;
            }
            fclose(w);
        }
        else
        {
            k = 1;
            printf("找不到该学生信息,请重新输入需要修改的学生学号: ");
            fflush(stdin);
            while (!scanf("%d", &num))
            {
                printf("输入修改信息有误,请重新输入: ");
                fflush(stdin);
            }
        }
    }
    while(k == 1);
    printf("   ");
    system("pause");
}
struct Stu_score *delete_score(struct Stu_score *head)
{
    int num,k;
    FILE *w;
    struct Stu_score *p1,*p2;
    if(head == NULL)
    {
        printf("没有学生信息,结束删除\n");
        return(head);
    }
    printf("请输入要删除的学生学号: ");
    while (!scanf("%d", &num))
    {
        printf("输入有误,请重新输入学生学号: ");
        fflush(stdin);
    }
    do
    {
        p1 = p2 = head;
        while (num != p1->id && p1->next != NULL)
        {
            p2 = p1;
            p1 = p1->next;
        }
        if (num == p1->id)
        {
            if (num == p1->id)
            {
                if (p1->next == NULL && p1 == head)
                {
                    free(p1);
                    head = NULL;
                }
                else if (p1->next == NULL)//如果删除完表空了 把表删除
                {
                    free(p1);
                    p2->next = NULL;
                }
                else if (head == p1)
                {
                    head = p1->next;
                    free(p1);
                }
                else
                {
                    p2->next = p1->next;
                    free(p1);
                }
            }
            printf("成功删除学生信息\n");
        }
        else
        {
            printf("找不到该同学信息\n");
            fflush(stdin);
        }
        if (head == NULL)
        {
            printf("没有学生信息,结束删除\n");
            return(head);
        }
        else
        {
            printf("   1.继续删除学生信息\n");
            printf("   2.结束删除\n");
            printf("请选择: ");
            while (!scanf("%d",&k))
            {
                printf("输入有误,请重新输入选择的序号: ");
                fflush(stdin);
            }
            if (k == 1)
            {
                printf("请输入要删除的学生学号: ");
                while (!scanf("%d", &num))
                {
                    printf("输入有误,请重新输入学生学号: ");
                    fflush(stdin);
                }
            }
            else if (k != 2)
            {
                k = 1;
            }
            if ((w = fopen("C:\\Desktop\\Tscore_new.txt", "wb+")) == NULL)
            {
                printf("cannot open file\n");
                exit(1);
            }
            p1=head;
            while(p1!=NULL)
            {
                fprintf(w,"%d %s %d %lf %lf %lf %lf \n", p1->id, p1->name, p1->clas, p1->course1, p1->course2,p1->course3,p1->avg);
                p1= p1->next;
            }
            fclose(w);
        }
    }
    while (k == 1);
    return(head);
}
struct Stu_score *add_score(struct Stu_score *head)
{
    FILE *w;
    int i,num;
    struct Stu_score *p1;
    head = sinsert(head, NULL);
    printf("成功插入学生信息\n");

    if ((w = fopen("C:\\Desktop\\Tscore_new.txt", "wb+")) == NULL)
    {
        printf("cannot open file\n");
        exit(1);
    }
    p1=head;
    while(p1!=NULL)
    {
        fprintf(w,"%d %s %d %lf %lf %lf %lf\n",p1->id, p1->name, p1->clas, p1->course1, p1->course2,p1->course3,p1->avg);
        p1= p1->next;
    }
    fclose(w);
    return head;
}
void stu_statistics_score(struct Stu_score *head)
{
    double cnt[3];
    int i;
    double sum=0;
    struct Stu_score *p1;
    p1 = head;
    memset(cnt,0,sizeof(cnt));
    printf("统计各课程不及格人数及所占百分比:\n");
    while (1)
    {
        sum++;
        if(p1->course1<60) cnt[0]++;
        if(p1->course2<60) cnt[1]++;
        if(p1->course3<60) cnt[2]++;
        if (p1->next == NULL)
            break;
        p1 = p1->next;
    }
    printf("全体学生人数:%.0lf人\n\n",sum);
    printf("课程1不及格人数:%.0lf人 %5.2lf%%\n",cnt[0],(cnt[0]/sum)*100);
    printf("课程2不及格人数:%.0lf人 %5.2lf%%\n",cnt[1],(cnt[1]/sum)*100);
    printf("课程3不及格人数:%.0lf人 %5.2lf%%\n\n",cnt[2],(cnt[2]/sum)*100);
}
void course_statistics_score(struct Stu_score *head)
{
    int i;
    int c1max=0,c2max=0,c3max=0;
    int c1min=1000,c2min=1000,c3min=1000;
    double sum1=0,sum2=0,sum3=0;
    double n=0;
    struct Stu_score *p1;
    p1 = head;
    printf("统计各课程最高分、最低分和平均分:\n");
    while (1)
    {
        if(p1->course1<c1min) c1min=p1->course1;
        if(p1->course2<c2min) c2min=p1->course2;
        if(p1->course3<c3min) c3min=p1->course3;
        if(p1->course1>c1max) c1max=p1->course1;
        if(p1->course2>c2max) c2max=p1->course2;
        if(p1->course3>c3max) c3max=p1->course3;
        sum1+=p1->course1;
        sum2+=p1->course2;
        sum3+=p1->course3;
        n++;
        if (p1->next == NULL)
            break;
        p1 = p1->next;
    }
    printf("全体学生人数:%.0lf人\n\n",n);
    printf("课程1最高分、最低分和平均分:%3d  %3d  %3.2lf\n",c1max,c1min,sum1/n);
    printf("课程2最高分、最低分和平均分:%3d  %3d  %3.2lf\n",c2max,c2min,sum2/n);
    printf("课程3最高分、最低分和平均分:%3d  %3d  %3.2lf\n\n",c3max,c3min,sum3/n);
}

以上就是“怎么用C语言结构体链表和指针实现学生管理系统”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注蜗牛博客行业资讯频道。

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:niceseo99@gmail.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

评论

有免费节点资源,我们会通知你!加入纸飞机订阅群

×
天气预报查看日历分享网页手机扫码留言评论电报频道链接