C语言,链表,实现学生信息管理系统

这篇博客介绍如何使用C语言和链表数据结构来实现一个学生信息管理系统。系统包含学号、姓名、性别、年龄等基本信息,以及成绩、学分、通过形式等学生成绩信息。系统支持中文菜单,初始包含5名学生,能进行输入、删除、排序等操作,同时具备成绩统计和多种查询功能。最后,系统能够将学生信息保存到文本文档中。
摘要由CSDN通过智能技术生成

C语言,链表实现学生信息管理系统

问题分析及任务描述

用链表这种存储结构,每个学生作为一个数据元素,包括date1(每个学生的信息),date2(每个学生的成绩信息)这两个数据项,用结构体详细定义date1中的学号,姓名,性别、年龄,date2中的成绩、学分、通过形式(考试、补考、重修)、学期和学期信息。

具体要解决的问题有如下6个
(1)使用中文菜单
(2)将学生信息保存在链表中
(3)初始状态已包含5名学生信息,在此基础上进行输入、删除、按学号排序等操作。
(4)成绩统计:计算总分、平均分和学分绩点,并按总分降序排列显示出来。输入科目名, 显示出该科平均分,最高分最低分
(5)多种查询(如学号、姓名、成绩等)及输出功能
(6)所有操作完成,或者在相应的命令后,再将学生信息保存到文本文档中

程序代码

下面展示一些 内联代码片

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
//学号长度
#define NO_LENGTH 20
//姓名长度
#define NAME_LENGTH 11
//性别长度
#define SEX_LENGTH 5
//通过形式长度
#define PASTYP_LENGTH 8
//学分长度
#define CREDIT_LENGTH 5
//定义学生结构体的数据结构
typedef struct Student
{
    char studentNo[NO_LENGTH];//学号
    char studentName[NAME_LENGTH];//姓名
    char studentSex[SEX_LENGTH];//性别
    int studentAge;//年龄
} St;
typedef struct Score
{
    int scoreMath;//数学成绩
    char creditMath[CREDIT_LENGTH];//数学学分
    char pasMath[PASTYP_LENGTH];//数学通过方式
    int termMath;//学期

    int scoreEgls;//英语成绩
    char creditEgls[CREDIT_LENGTH];//英语学分
    char pasEgls[PASTYP_LENGTH];//英语通过方式
    int termEgls;//学期

    int scoreComp;//计算机成绩
    char creditComp[CREDIT_LENGTH];//计算机学分
    char pasComp[PASTYP_LENGTH];//计算机通过方式
    int termComp;//学期

    int scoreSport;//体育成绩
    char creditSport[CREDIT_LENGTH];//体育学分
    char pasSport[PASTYP_LENGTH];//体育通过方式
    int termSport;//学期

    int scoreChinese;//马原成绩
    char creditChinese[CREDIT_LENGTH];//马原学分
    char pasChinese[PASTYP_LENGTH];//马原通过方式
    int termChinese;//学期

}Sc;

//定义结点的数据结构
typedef struct node
{
    St date1;
    Sc date2;
    struct node *next;//定义头结点的指针域
} Node, *Link;

//初始化学生信息,成绩
void createList1(Link head);
void createList2(Link head);
void createList3(Link head);
void createList4(Link head);
void createList5(Link head);
//功能菜单
void myMenu(void);
//输入学生信息
void inputNode(Link p);
//新增学生记录
bool addNode(Link head);
//删除学生记录
bool deleteNode(Link head);
//输入学号
void inputStudentNo(char s[], char no[]);
//输入姓名
void inputStudentName(char s[],char name[]);
//打印链表,指针不指向下一个
void displayNode1(Link head);
//打印链表
void displayNode(Link head);
//查询学生记录
bool queryNode(Link head);
//插入一个学生记录
void insertNode(Link head, Link newNode);
//修改学生记录
bool modifyNode(Link head);
//统计学生人数
int countNode(Link head);
//清除链表
void clearLink(Link head);
//成绩统计
void statisticsNode(Link head);
//保存到文件
void printfile(Link head);
//排序并插入
void insertsort(Link head,Link newNode);

int main(void)
{
    int select;//功能选项代码
    int count; //学生人数
    Link head;//头指针

    head = (Link)malloc(sizeof(Node));
    head->next = NULL;

    createList1(head);
    createList2(head);
    createList3(head);
    createList4(head);
    createList5(head);

    while (1)
    {
        myMenu();
        printf("\n请输入你的选择(1-9):");
        scanf("%d", &select);

        switch (select)
        {
        case 1://增加学生记录
            if (addNode(head))
            {
                printf("成功增加一个学生记录。\n");
            }
            break;
        case 2://删除学生记录
            if (deleteNode(head))
            {
                printf("成功删除一个学生记录。\n");
            }
            else
            {
                printf("没有找到要删除的学生记录。\n");
            }
            break;
        case 3://查找学生记录
            if (queryNode(head))
            {
                printf("成功找到学生记录。\n");
            }
            else
            {
                printf("没有找到要查询的学生记录。\n");
            }
            break;
        case 4://修改学生记录
            if (modifyNode(head))
            {
                printf("成功修改一个学生记录。\n");
            }
            else
            {
                printf("没有找到要修改的学生记录。\n");
            }
            break;
        case 5://统计学生记录
            count = countNode(head);
            printf("学生人数为:%d\n", count);
            break;
        case 6://显示学生记录
            displayNode(head);
            break;
        case 7://成绩统计
            statisticsNode(head);
            break;
        case 8://保存到文件
            printfile(head);
            break;
        case 9://退出系统
            clearLink(head);
            break;
            return 0;
            ;
           default:
            printf("输入不正确,请输入1-9之间的数。\n");
            break;
        }
    }
}

//功能菜单
void myMenu(void)
{
    printf("\n");
    printf(" * * * * * * * * * 菜     单 * * * * * * * * * *\n");
    printf("     1 增加学生记录            2 删除学生记录       \n");
    printf("     3 查找学生记录            4 修改学生记录       \n");
    printf("     5 统计学生人数            6 显示学生记录       \n");
    printf("     7 成绩统计                8 保存到文件         \n");
    printf("     9 退出系统\n");
    printf(" * * * * * * * * * * * * * * * * * * * * * * * *\n");
}

//初始化五个学生信息,成绩
void createList1(Link head)
{
    Link newNode;//空结点指针
    newNode = (Link)malloc(sizeof(Node));
    strcpy(newNode->date1.studentNo,"1910903");
    strcpy(newNode->date1.studentName,"三");
    strcpy(newNode->date1.studentSex,"女");
    newNode->date1.studentAge=19;

    newNode->date2.scoreMath=88;
    strcpy(newNode->date2.creditMath,"3.5");
    strcpy(newNode->date2.pasMath,"考试");
    newNode->date2.termMath=1;

    newNode->date2.scoreEgls=90;
    strcpy(newNode->date2.creditEgls,"3.7");
    strcpy(newNode->date2.pasEgls,"考试");
    newNode->date2.termEgls=1;

    newNode->date2.scoreComp=85;
    strcpy(newNode->date2.creditComp,"3.4");
    strcpy(newNode->date2.pasComp,"考试");
    newNode->date2.termComp=1;

    newNode->date2.scoreSport=80;
    strcpy(newNode->date2.creditSport,"3.0");
    strcpy(newNode->date2.pasSport,"考试");
    newNode->date2.termSport=1;

    newNode->date2.scoreChinese=85;
    strcpy(newNode->date2.creditChinese,"3.5");
    strcpy(newNode->date2.pasChinese,"考试");
    newNode->date2.termChinese=1;
    newNode->next = NULL;

    insertsort(head,newNode);
    }

void createList2(Link head)
{
    Link newNode;//空结点指针
    newNode = (Link)malloc(sizeof(Node));
    strcpy(newNode->date1.studentNo,"1910902");
    strcpy(newNode->date1.studentName,"二");
    strcpy(newNode->date1.studentSex,"男");
    newNode->date1.studentAge=19;

    newNode->date2.scoreMath=95;
    strcpy(newNode->date2.creditMath,"3.8");
    strcpy(newNode->date2.pasMath,"考试");
    newNode->date2.termMath=1;

    newNode->date2.scoreEgls=91;
    strcpy(newNode->date2.creditEgls,"3.7");
    strcpy(newNode->date2.pasEgls,"考试");
    newNode->date2.termEgls=1;

    newNode->date2.scoreComp=83;
    strcpy(newNode->date2.creditComp,"3.3");
    strcpy(newNode->date2.pasComp,"考试");
    newNode->date2.termComp=1;

    newNode->date2.scoreSport=81;
    strcpy(newNode->date2.creditSport,"3.1");
    strcpy(newNode->date2.pasSport,"考试");
    newNode->date2.termSport=2;

    newNode->date2.scoreChinese=86;
    strcpy(newNode->date2.creditChinese,"3.5");
    strcpy(newNode->date2.pasChinese,"考试");
    newNode->date2.termChinese=1;
    newNode->next = NULL;

    insertsort(head,newNode);
    }
    void createList3(Link head)
{
    Link newNode;//空结点指针
    newNode = (Link)malloc(sizeof(Node));
    strcpy(newNode->date1.studentNo,"1910901");
    strcpy(newNode->date1.studentName,"一");
    strcpy(newNode->date1.studentSex,"女");
    newNode->date1.studentAge=19;

    newNode->date2.scoreMath=70;
    strcpy(newNode->date2.creditMath,"2.8");
    strcpy(newNode->date2.pasMath,"重修");
    newNode->date2.termMath=1;

    newNode->date2.scoreEgls=97;
    strcpy(newNode->date2.creditEgls,"3.7");
    strcpy(newNode->date2.pasEgls,"考试");
    newNode->date2.termEgls=1;

    newNode->date2.scoreComp=85;
    strcpy(newNode->date2.creditComp,"3.4");
    strcpy(newNode->date2.pasComp,"考试");
    newNode->date2.termComp=1;

    newNode->date2.scoreSport=80;
    strcpy(newNode->date2.creditSport,"3.0");
    strcpy(newNode->date2.pasSport,"补考");
    newNode->date2.termSport=5;

    newNode->date2.scoreChinese=86;
    strcpy(newNode->date2.creditChinese,"3.6");
    strcpy(newNode->date2.pasChinese,"考试");
    newNode->date2.termChinese=1;
    newNode->next = NULL;

    insertsort(head,newNode);
    }
    
    void createList4(Link head)
{
    Link newNode;//空结点指针
    newNode = (Link)malloc(sizeof(Node));
    strcpy(newNode->date1.studentNo,"1910904");
    strcpy(newNode->date1.studentName,"四");
    strcpy(newNode->date1.studentSex,"男");
    newNode->date1.studentAge=20;

    newNode->date2.scoreMath=88;
    strcpy(newNode->date2.creditMath,"3.4");
    strcpy(newNode->date2.pasMath,"考试");
    newNode->date2.termMath=1;

    newNode->date2.scoreEgls=60;
    strcpy(newNode->date2.creditEgls,"2.1");
    strcpy(newNode->date2.pasEgls,"重修");
    newNode->date2.termEgls=5;

    newNode->date2.scoreComp=85;
    strcpy(newNode->date2.creditComp,"3.4");
    strcpy(newNode->date2.pasComp,"考试");
    newNode->date2.termComp=1;

    newNode->date2.scoreSport=81;
    strcpy(newNode->date2.creditSport,"3.0");
    strcpy(newNode->date2.pasSport,"考试");
    newNode->date2.termSport=1;

    newNode->date2.scoreChinese=86;
    strcpy(newNode->date2.creditChinese,"3.5");
    strcpy(newNode->date2.pasChinese,"考试");
    newNode->date2.termChinese=1;
    newNode->next = NULL;

    insertsort(head,newNode);
    }
    
    void createList5(Link head)
{
    Link newNode;//空结点指针
    newNode = (Link)malloc(sizeof(Node));
    strcpy(newNode->date1.studentNo,"1910905");
    strcpy(newNode->date1.studentName,"五");
    strcpy(newNode->date1.studentSex,"女");
    newNode->date1.studentAge=19;

    newNode->date2.scoreMath=86;
    strcpy(newNode->date2.creditMath,"3.5");
    strcpy(newNode->date2.pasMath,"考试");
    newNode->date2.termMath=1;

    newNode->date2.scoreEgls=90;
    strcpy(newNode->date2.creditEgls,"3.7");
    strcpy(newNode->date2.pasEgls,"补考");
    newNode->date2.termEgls=1;

    newNode->date2.scoreComp=85;
    strcpy(newNode->date2.creditComp,"3.4");
    strcpy(newNode->date2.pasComp,"考试");
    newNode->date2.termComp=8;

    newNode->date2.scoreSport=90;
    strcpy(newNode->date2.creditSport,"3.5");
    strcpy(newNode->date2.pasSport,"考试");
    newNode->date2.termSport=1;

    newNode->date2.scoreChinese=85;
    strcpy(newNode->date2.creditChinese,"3.5");
    strcpy(newNode->date2.pasChinese,"考试");
    newNode->date2.termChinese=1;
    newNode->next = NULL;

    insertsort(head,newNode);
    }

//插入并排序
    void insertsort(Link head,Link newNode)
{
    Link q,p;
    p=head;//用作标记
    q=head->next;//用作比较
    bool flag=false; //是否增加成功
    //如果是空链表
   if (head->next==NULL)
    {
        head->next=newNode;
        flag=true;
    }
    else
    {
        while (q!=NULL)
        {
            if (strcmp(newNode->date1.studentNo,q->date1.studentNo) < 0)
            {
                p->next=newNode;
                newNode->next=q;
                flag=true;
                break;
            }
            else
            {
                p=q;
                q=q->next;
            }
        }
    }
    if(q==NULL&&flag==false)
    {
        p->next=newNode;
        flag=true;
    }
    return flag;
}

//增加学生记录
bool addNode(Link head)
{
    Link p, q;
    Link newNode;//空结点指针
    int n,i;
    bool flag = false; //是否增加成功
    printf("请输入想要输入的学生信息数:");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    newNode=(Link)malloc(sizeof(Node));
    inputNode(newNode);
    insertsort(head,newNode);

    }
    return flag;
}

void inputNode(Link newNode)
{
    printf("----------------------------------------------------------------------------\n");
    printf("请输入学生学号:");
    scanf("%s", newNode->date1.studentNo);
    printf("请输入学生姓名:");
    scanf("%s", newNode->date1.studentName);
    printf("请输入学生性别:");
    scanf("%s",newNode->date1.studentSex);
    printf("请输入学生年龄:");
    scanf("%d",&newNode->date1.studentAge);

    printf("----------------------------------------------------------------------------\n");
    printf("请输入学生数学成绩:");
    scanf("%d",&newNode->date2.scoreMath);
    printf("请输入学生数学学分:");
    scanf("%s",newNode->date2.creditMath);
    printf("请输入学生数学通过方式:");
    scanf("%s",newNode->date2.pasMath);
    printf("请输入学期:");
    scanf("%d",&newNode->date2.termMath);

    printf("-----------------------------------------------------------------------------\n");
    printf("请输入学生英语成绩:");
    scanf("%d",&newNode->date2.scoreEgls);
    printf("请输入学生英语学分:");
    scanf("%s",newNode->date2.creditEgls);
    printf("请输入学生英语通过方式:");
    scanf("%s",newNode->date2.pasEgls);
    printf("请输入学期:");
    scanf("%d",&newNode->date2.termEgls);

    printf("-----------------------------------------------------------------------------\n");
    printf("请输入学生计算机成绩:");
    scanf("%d",&newNode->date2.scoreComp);
    printf("请输入学生计算机学分:");
    scanf("%s",newNode->date2.creditComp);
    printf("请输入学生计算机通过方式:");
    scanf("%s",newNode->date2.pasComp);
    printf("请输入学期:");
    scanf("%d",&newNode->date2.termComp);

    printf("-----------------------------------------------------------------------------\n");
    printf("请输入学生体育成绩:");
    scanf("%d",&newNode->date2.scoreSport);
    printf("请输入学生体育学分:");
    scanf("%s",newNode->date2.creditSport);
    printf("请输入学生体育通过方式:");
    scanf("%s",newNode->date2.pasSport);
    printf("请输入学期:");
    scanf("%d",&newNode->date2.termSport);

    printf("-----------------------------------------------------------------------------\n");
    printf("请输入学生马原成绩:");
    scanf("%d",&newNode->date2.scoreChinese);
    printf("请输入学生马原学分:");
    scanf("%s",newNode->date2.creditChinese);
    printf("请输入学生马原通过方式:");
    scanf("%s",newNode->date2.pasChinese);
    printf("请输入学期:");
    scanf("%d",&newNode->date2.termChinese);
    printf("----------------------------------------------------------------------------\n");
    newNode->next = NULL;//尾结点指针域置空
}

//按照给定的学号删除学生记录,如果删除成功返回true,否则返回false
bool deleteNode(Link head)
{
    char no[NO_LENGTH]; //要删除学生的学号
    Link p, q;

    inputStudentNo("删除", no);
    p = head;
    q = head->next;

    while (q!=NULL)
    {
        if (strcmp(q->date1.studentNo,no) == 0)//找到相同的学号
        {
            p->next=q->next;
            free(q);
            return true;
        }
        else
        {
            p=q;
            q=q->next;//未找到,下一个结点
        }
    }
    return false;
}
void inputStudentNo(char s[], char no[])
{
    printf("请输入要%s的学生学号:",s);
    scanf("%s",no);
}
void inputStudentName(char s[],char name[])
{
    printf("请输入要%s的学生姓名:",s);
    scanf("%s",name);
}


//打印链表
void displayNode(Link head)
{
    printf("\n\t***学生信息***\n");
    Link p=head->next;
    while (p!= NULL)
    {
        printf("-----------------------------------------------------------------------------\n");
        printf("\t  \t学号\t\t姓名\t\t性别\t\t年龄\n");
        printf("\t  \t%s\t\t%s\t\t%s\t\t%d\n", p->date1.studentNo, p->date1.studentName,p->date1.studentSex,p->date1.studentAge);
        printf("\t  \t--------------------------------------------------\n");
        printf("\t  \t成绩\t\t学分\t\t方式\t\t学期\n");
        printf("\t数学 \t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreMath,p->date2.creditMath,p->date2.pasMath,p->date2.termMath);
        printf("\t英语 \t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreEgls,p->date2.creditEgls,p->date2.pasEgls,p->date2.termEgls);
        printf("\t计算机\t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreComp,p->date2.creditComp,p->date2.pasComp,p->date2.termComp);
        printf("\t体育 \t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreSport,p->date2.creditSport,p->date2.pasSport,p->date2.termSport);
        printf("\t马原 \t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreChinese,p->date2.creditChinese,p->date2.pasChinese,p->date2.termChinese);
        p=p->next;
        printf("-----------------------------------------------------------------------------\n");
    }
}
//打印链表,指针不指向下一个
void displayNode1(Link p)
{
        printf("----------------------------------------------\n");
        printf("\t  \t学号\t\t姓名\t\t性别\t\t年龄\n");
        printf("\t  \t%s\t\t%s\t\t%s\t\t%d\n", p->date1.studentNo, p->date1.studentName,p->date1.studentSex,p->date1.studentAge);
        printf("\t  \t成绩\t\t学分\t\t方式\t\t学期\n");
        printf("\t数学 \t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreMath,p->date2.creditMath,p->date2.pasMath,p->date2.termMath);
        printf("\t英语 \t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreEgls,p->date2.creditEgls,p->date2.pasEgls,p->date2.termEgls);
        printf("\t计算机\t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreComp,p->date2.creditComp,p->date2.pasComp,p->date2.termComp);
        printf("\t体育 \t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreSport,p->date2.creditSport,p->date2.pasSport,p->date2.termSport);
        printf("\t马原 \t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreChinese,p->date2.creditChinese,p->date2.pasChinese,p->date2.termChinese);
        printf("----------------------------------------------\n");
    }

//按照给定的学号查询学生记录,找到返回true,没有找到返回false
bool queryNode(Link head)
{
    char no[NO_LENGTH],nam[NAME_LENGTH];
    int select;
    Link p = head->next;
    printf("1.学号\t2.姓名\t\n");
    printf("请输入想要查询的项目:");
    scanf("%d",&select);
    switch(select)
    {
     case 1:
           inputStudentNo("查询",no);
           while (p!= NULL)
           {
             if (strcmp(p->date1.studentNo,no) == 0)
            {
                 displayNode1(p);
                 return true;
            }
            else
            {
                 p=p->next;
            }
           }
            break;
    case 2:
        inputStudentName("查询",nam);
         while (p!=NULL)
           {
             if (strcmp(p->date1.studentName,nam)==0)
            {
                 displayNode1(p);
                 return true;
            }
            else
            {
                 p=p->next;
            }
           }
            break;
    default:
        printf("输入不正确,请输入1-2之间的数。\n");
      break;
    }
    return false;
}

//修改学生记录,修改成功,返回true,否则返回false
bool modifyNode(Link head)
{
    char no[NO_LENGTH];
    char no_new[NO_LENGTH];     //新学号
    char name_new[NAME_LENGTH]; //新姓名
    int select;                 //功能选择
    Link p, q;

    inputStudentNo("修改", no);
    printf("请输入需要修改的项目: 1 学号 2 姓名\n");
    scanf("%d",&select);

    p=head;
    q=head->next;
    while (q!=NULL)
    {
        if (strcmp(q->date1.studentNo,no)==0)
        {
            if (select==1)
            {
                p->next=q->next;
                q->next=NULL;
                printf("请输入该学生的新学号:");
                scanf("%s",no_new);
                strcpy(q->date1.studentNo,no_new);
                insertNode(head,q);
            }
            else
            {
                printf("请输入该学生的新姓名:");
                scanf("%s",name_new);
                strcpy(q->date1.studentName,name_new);
            }
            return true;
        }
        else
        {
            p=q;
            q=q->next;
        }
    }

    return false;
}

//插入一个学生记录
void insertNode(Link head, Link newNode)
{
    Link p,q;
    bool flag=false; //是否插入成功

    p=head;//做标记
    q=head->next;//用作比较
    //如果是空链表
    if(head->next==NULL)
    {
        head->next=newNode;
        flag=true;
    }
    else
    {
        //不是空链表
        while (q!=NULL)
        {
            if (strcmp(newNode->date1.studentNo, q->date1.studentNo) < 0)
            {
                p->next=newNode;
                newNode->next=q;
                flag=true;
                break;
            }
            else
            {
                p=q;
                q=q->next;
            }
        }
    }
        if(q==NULL&&flag==false)
    {
        p->next=newNode;
        flag=true;
    }
}

//统计学生人数
int countNode(Link head)
{
    Link p;
    int count=0;
    p=head->next;
    while (p!= NULL)
    {
        count++;
        p=p->next;
    }

    return count;
}

//清除链表
void clearLink(Link head)
{
    Link p,q;

    p=head;
    q=head->next;

    while (q!=NULL)
    {
        free(p);
        p=q;
        q=q->next;
    }
    free(p);
}

//成绩统计
void statisticsNode(Node *head)
{
    typedef struct student
    {
      char name[20];//姓名
      int sum;//总分
      float aver;//平均分
      float credit;//学分
    }student;
    student stu[20],buf;
    int i,n=0,q,w,select;
    int maxM=0,maxE=0,maxC=0,maxS=0,maxCH=0;
    int sumM=0,sumE=0,sumC=0,sumS=0,sumCH=0;
    float aveM,aveE,aveC,aveS,aveCH;
    float numM[20],numE[20],numC[20],numS[20],numCH[20];
    Node *p;
    p=head->next;
    i=countNode(head);
    printf("\t总共%d个学生\n",i);
    printf("\t姓名\t总分\t平均分\t学分绩点\n");
    while (p)
    {
        //将char类型的学分转换成浮点型float
        numM[n]=atof(p->date2.creditMath);
        numE[n]=atof(p->date2.creditEgls);
        numC[n]=atof(p->date2.creditComp);
        numS[n]=atof(p->date2.creditSport);
        numCH[n]=atof(p->date2.creditChinese);
        strcpy(stu[n].name,&p->date1.studentName);
        stu[n].sum=p->date2.scoreMath+p->date2.scoreEgls+p->date2.scoreComp+p->date2.scoreSport+p->date2.scoreChinese;//计算总分
        stu[n].aver=stu[n].sum/5;//计算平均分
        stu[n].credit=(numM[n]+numE[n]+numC[n]+numS[n]+numCH[n])/5;//计算学分
        printf("\t%s\t%d\t%.2f\t%.2f\n",stu[n].name,stu[n].sum,stu[n].aver,stu[n].credit);
        p=p->next;//下一个结点
        n++;
    };
    printf("\t-------------排序后------------\n");
    printf("\t姓名\t总分\t平均分\t学分\n");
      for (q=0;q<n-1;++q)  //比较n-1轮
    {
        for (w=0;w<n-1-q;++w)  //每轮比较n-1-i次,
        {
            if (stu[w].sum<stu[w+1].sum)
            {
                buf=stu[w];
                stu[w]=stu[w+1];
                stu[w+1]=buf;
            }
        }
    }
    for(n=0;n<i;n++)
    {
        printf("\t%s\t%d\t%.2f\t%.2f\n",stu[n].name,stu[n].sum,stu[n].aver,stu[n].credit);
    }
    printf("\t------------科目查询-----------\n");
    printf("\t1.数学\t2.英语 3.计算机\t4.体育\t5.马原\n");
    printf("\t请输入需要查询的科目序号:");
    scanf("%d",&select);
    p=head->next;
    switch(select)
    {
    case 1:
         while(p)
      {
        if(maxM<p->date2.scoreMath)
         {
            maxM=p->date2.scoreMath;
         }
        sumM=sumM+p->date2.scoreMath;
        p=p->next;
      }
      aveM=sumM/i;
      printf("\t数学最高分:%d\n",maxM);
      printf("\t数学平均分:%.2f\n",aveM);
     break;

     case 2:
          while(p)
      {
           if(maxE<p->date2.scoreEgls)
            {
               maxE=p->date2.scoreEgls;
            }
         sumE=sumE+p->date2.scoreEgls;
         p=p->next;
      }
      aveE=sumE/i;//平均值
      printf("\t英语最高分:%d\n",maxE);
      printf("\t英语平均分:%.2f\n",aveE);
      break;

    case 3:
         while(p)
      {
          if(maxC<p->date2.scoreComp)
           {
              maxC=p->date2.scoreComp;
           }
         sumC=sumC+p->date2.scoreComp;
         p=p->next;
      }
      aveC=sumC/i;
      printf("\t计算机最高分:%d\n",maxC);
      printf("\t计算机平均分:%.2f\n",aveC);
      break;

      case 4:
           while(p)
        {
           if(maxS<p->date2.scoreSport)
            {
               maxS=p->date2.scoreSport;
            }
          sumS=sumS+p->date2.scoreSport;
          p=p->next;
        }
        aveS=sumS/i;
        printf("\t体育最高分:%d\n",maxS);
        printf("\t体育平均分:%.2f\n",aveS);
      break;


     case 5:
          while(p)
        {
            if(maxCH<p->date2.scoreChinese)
             {
                maxCH=p->date2.scoreChinese;
             }
          sumCH=sumCH+p->date2.scoreChinese;
          p=p->next;
        }
        aveCH=sumCH/i;
        printf("\t马原最高分:%d\n",maxCH);
        printf("\t马原平均分:%.2f\n",aveCH);
      break;
     default:
        printf("\t输入不正确,请输入1-7之间的数。\n");
      break;
    }

}
//保存到文件
void printfile(Link head)
{
    FILE *fp;
    fp=fopen("chengji.txt","w");//打开文件

        fprintf(fp,"                    学生信息表\n");

    Link p=head->next;
    while (p!=NULL)
    {
        fprintf(fp,"----------------------------------------------\n");
        fprintf(fp,"\t  \t学号\t\t姓名\t\t性别\t\t年龄\n");
        fprintf(fp,"\t  \t%s\t\t%s\t\t%s\t\t%d\n", p->date1.studentNo, p->date1.studentName,p->date1.studentSex,p->date1.studentAge);
        fprintf(fp,"\t  \t成绩\t\t学分\t\t方式\t\t学期\n");
        fprintf(fp,"\t数学 \t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreMath,p->date2.creditMath,p->date2.pasMath,p->date2.termMath);
        fprintf(fp,"\t英语 \t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreEgls,p->date2.creditEgls,p->date2.pasEgls,p->date2.termEgls);
        fprintf(fp,"\t计算机\t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreComp,p->date2.creditComp,p->date2.pasComp,p->date2.termComp);
        fprintf(fp,"\t体育 \t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreSport,p->date2.creditSport,p->date2.pasSport,p->date2.termSport);
        fprintf(fp,"\t马原 \t%d\t\t%s\t\t%s\t\t%d\n",p->date2.scoreChinese,p->date2.creditChinese,p->date2.pasChinese,p->date2.termChinese);
        p=p->next;
        fprintf(fp,"----------------------------------------------\n");
    }
    fclose(fp);//关闭文件
    printf("\n\n*******************恭喜,保存完成!*******************\n\n");
}

`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值