学生统计问题

由键盘输入一个班(全班30人)学生的学号,姓名,M门课程的成绩,分别统计下列内容:
1。统计每个学生的总分和平均分,按总分由大到小排出名次。
2。打印出成绩在全班平均分之上的学生名单
(须用链表结构实现)

=================================================================================

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define M  3            /*把科目定为3.可以修改*/
#define P  30           /*用于测试时可以改小*/
typedef struct s{
    int id;
    float all,ave,score[M];
    char name[10];            /*名字10个应该够了.*/
    struct s *next;
}student;
student* createStu()            /*建结点*/
{
    int i;
    student *s=(student *)malloc(sizeof(student));
    printf("Please input the id/n");
    scanf("%d",&s->id);
    printf("Please input the name/n");
    fflush(stdin);
    gets(s->name);
    printf("Please input the score/n");
    i=0;s->all=0;
    while(i<M)
    {
        scanf("%f",&s->score[i]);
        s->all+=s->score[i++];
        if(i==M)s->ave=s->all/i;
    }
    s->next=0;
    return s;
}
student* insertLink(student *&head,student *node)      
{
    student *p=head,*q=p;
    if(!head)                          /*插入头*/
    {
        head=node;
        return head;
    }                                  
    if(head->all<node->all)            /*插入头前*/
    {
        node->next=head;
        head=node;
        return head;
    }
    while(p&&(p->all>=node->all))
    {
        q=p;p=p->next;
    }
    if(!p)p=node;                  /*插入尾*/
    else                           /*插入中间*/
    {
        q->next=node;
        node->next=p;
        q=node;
    }
    return head;
}
void print(student *head)
{
    student *p=head;
    if(!p)return ;
 printf("/nshow these students with other information/n");
    while(p)
    {
        printf("ID:%d  name:%s  ALL:%f  AVERAGE:%f/n",p->id,p->name,p->all,p->ave);
        p=p->next;
    }
}
void printUP(student *head)      
{
    float aveall,allall=0;
    student *p=head;
    if(!p)return ;
    while(p)
 {
  allall+=p->all;
  p=p->next;
 }
    aveall=allall/P;
 p=head;
 printf("/nthese students up the average!/n");
    while(p)
    {
        if(p->all>aveall)printf("%s/n",p->name);
        p=p->next;
    }   
}   
int main()
{
    int i=0;
    student *head=0;
    while(i++<P)head=insertLink(head,createStu());
    print(head);
    printUP(head);
    getch();
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值