码迷,mamicode.com
首页 > 其他好文 > 详细

学员成绩管理

时间:2018-07-05 21:47:59      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:创建链表   pre   clu   链表   name   avr   printf   i++   原创   

#include <stdio.h>
#include<string.h>
#include<stdlib.h>
using namespace std;
struct student                        //学生信息存储结构
{
    int no;                              //学号
    char name[15];                            //姓名
    int score[3];                             //成绩
    double avr;                            //平均分
    struct student *next;
};
void load()
{
    printf("****************************************\n");
    printf("********欢迎使用学员成绩管理系统********\n");
    printf("********本程序由计科171王恺锋原创*******\n");
    printf("****************************************\n");
}
struct student *Create(student *head)        //ok
{
    student *p,*q;;
    head=(student *)malloc(sizeof(student));
    head->next=NULL;
    q=head;
    p=(student*)malloc(sizeof(student));
    printf("请输入学号:");
    scanf("%d",&p->no);
    getchar();
    printf("请输入姓名:");
    scanf("%s",p->name);
    printf("请输入成绩1:");
    scanf("%d",&p->score[0]);
    printf("请输入成绩2:");
    scanf("%d",&p->score[1]);
    printf("请输入成绩3:");
    scanf("%d",&p->score[2]);
    p->avr=(p->score[0]+p->score[1]+p->score[2])/3.0;
    q->next=p;
    q=p;
    q->next=NULL;
    return head;
}
struct student *Append(student *head)
{
    student *p,*q=head,*t;
    p=(student*)malloc(sizeof(student));
    printf("请输入学号:");
    scanf("%d",&p->no);
    getchar();
    printf("请输入姓名:");
    scanf("%s",p->name);
    printf("请输入成绩1:");
    scanf("%d",&p->score[0]);
    printf("请输入成绩2:");
    scanf("%d",&p->score[1]);
    printf("请输入成绩3:");
    scanf("%d",&p->score[2]);
    p->avr=(p->score[0]+p->score[1]+p->score[2])/3.0;
    /*p->order=0;*/
    while(q)
    {
        t=q;
        q=q->next;
    }
    t->next=p;
    t=p;
    t->next=NULL;
    return head;
}
void Print(student *head)              //ok
{
    student *p=head;
    while(p->next)
    {
        p=p->next;
        printf("学号: %d\n",p->no);
        printf("姓名: %s\n",p->name);
        printf("成绩1: %d 成绩2: %d 成绩3: %d \n",p->score[0],p->score[1],p->score[2]);
        printf("平均成绩: %.2f\n",p->avr);
    }
}

struct student *Del(student *head) //OK
{
    int  number;
    student *p=head,*q;
    printf("输入要删除的学生学号:");
    scanf("%d",&number);
    while(p->next&&number!=p->no)
    {
        q=p;
        p=p->next;
    }
    q->next=p->next;
    return head;
}


struct student *Sort(student *head)
{
    int i=1;
    student *q, *s, *pre,*p,*a;
    p=head->next;
    q=p->next;
    p->next=NULL;
    while(q)
    {
        s=q;
        q=q->next;
        pre=head;
        p=head->next;
        while(p!=NULL && p->avr > s->avr)
        {
            pre=p;
            p=p->next;
        }
        s->next=p;
        pre->next=s;
    }
    a=head->next;
    while(a)
    {
        /*a->order=i++;*/
        a=a->next;
    }
    return head;
}
int main()
{
    char c;
    student *head=NULL;
    load();
    printf("请输入学员信息:\n");
    head=Create(head);///输入第一条信息并创建链表
    while(1)
    {
        printf("是否继续?(y or n)\n");
        scanf(" %c",&c);
        if(c==y||c==Y)
        {
            head=Append(head);///追加信息
        }
        else if(c==n||c==N)
        {
            break;
        }
    }
    printf("按学员平均成绩降序排列:\n");
    head=Sort(head);
    Print(head);
    printf("是否插入新成员?(y or n)\n");
    scanf(" %c",&c);
    if(c==y||c==Y)
    {
        printf("请输入要增加的学生信息:\n");
        head=Append(head);///追加信息
        printf("插入新学员后的信息如下:\n");
        head=Sort(head);
        Print(head);
    }
    printf("是否删除某一成员?(y or n)\n");
    scanf(" %c",&c);
    if(c==y||c==Y)
    {
        head=Del(head);
        printf("删除某一学员后的信息如下:\n");
        head=Sort(head);
        Print(head);
    }
    return 0;
}

 

学员成绩管理

标签:创建链表   pre   clu   链表   name   avr   printf   i++   原创   

原文地址:https://www.cnblogs.com/wkfvawl/p/9269984.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!