C语言写学生管理系统

C语言写学生管理系统

题目要求

链表A,每个节点存放一个新的链表B1,B2,B3,B4,B5的头结点。

场景:一个年级,相当链表A
该年级5个班,每个班5个人,相当于链表B1–B5
做一个学生成绩管理系统
学生成绩有语文 数学 英语

功能: 录入成绩 找三科总分的最高分 最低分 算出平均分

#include <stdio.h>
#include <stdlib.h>
int len=5;
int a;
typedef struct Student
{
	int yw;
    int sx;
    int yy;
    struct Student* next;
}STU,*PSTU;

typedef struct A
{
	PSTU xs;
    struct A* next;
}BJ,*PB;
//========================================
PSTU initS()
{
    PSTU pHead=NULL;
    PSTU pEnd,pNew;
    a=0;
    pEnd = pNew= (PSTU)malloc(sizeof(STU));
    
    int i;

    for(i=0;i<len;i++)
    {
		a++;
        if(a==1){
			pNew->next=pHead;
            pEnd=pNew;
            pHead=pNew;
        }
        else
        {
			pNew->next=NULL;
            pEnd->next=pNew;
            pEnd=pNew;
        }
        pNew=(PSTU)malloc(sizeof(STU));
        
    }
    free(pNew);
    return pHead;
}

PB initB()
{
	PB pHead=NULL;
    PB pEnd,pNew;
    a=0;
    pEnd = pNew= (PB)malloc(sizeof(BJ));
    int i;

    for(i=0;i<len;i++)
    {
		a++;
        if(a==1){
	    pNew->next=pHead;
            pEnd=pNew;
            pHead=pNew;
        }
        else
        {
	    pNew->next=NULL;
            pEnd->next=pNew;
            pEnd=pNew;
        }
        pNew=(PB)malloc(sizeof(BJ));
        //printf("%d",a);
    }
    free(pNew);
    return pHead;
}

void lcj(PB a)
{
	
    PB ptemp = a;
    int js=1;
    while(ptemp!=NULL)
    {
	PSTU pstu = ptemp->xs;
        while(pstu!=NULL)
        {
		int yw;
        int sx;
        int yy;
        printf("请输入第%d个学生的语数外成绩:\n",js++);
        scanf("%d %d %d",&yw,&sx,&yy);
    
		pstu->yw = yw;
        pstu->sx = sx;
        pstu->yy = yy;
        printf("%d,%d,%d \n",pstu->yw,pstu->sx,pstu->yy);
        pstu=pstu->next;
         
        
        }
        //free(pstu);
        ptemp=ptemp->next;
    
    }
    
    //free(ptemp);
   
}
int findMaxStu(PB a)
{
    PB b=a;
    PSTU max;
    max = b->xs;
    int i,j;
    while(b!=NULL)
    {
    PSTU s = b->xs;
    while(s!=NULL)
    {
		if((max->yw+max->sx+max->yy) < (s->yw+s->yy+s->sx))
        {
			max = s;
        }
        s=s->next;
    }
    //free(s);
    b=b->next;
    }
    //free(b);
    return (max->yw+max->sx+max->yy);
}

int findMinStu(PB a)
{
    PB c=a;
    PSTU min;
    min = c->xs;
    int i,j;
    while(c!=NULL)
    {
    PSTU s = c->xs;
    while(s!=NULL)
    {
		if((min->yw+min->sx+min->yy) > (c->xs->yw+c->xs->yy+c->xs->sx))
        {
			min = c->xs;
        }
        s=s->next;
    }
    //free(s);
    c=c->next;
    }
    //free(c);
    return (min->yw+min->sx+min->yy);
}

float getAverage(PB a){
    PB c=a;
	   
    int i,j;
    double sum=0;
    
    while(c!=NULL){
		PSTU s = c->xs;
    while(s != NULL){
		sum+=(s->yw+s->sx+s->yy);
        s=s->next;
    }
    free(s);
    c=c->next;
    }
    //free(c);
    return (float)(sum/(len*len));
}

int main()
{

    PB a = initB();
    PB b =a; 
	while(b!=NULL)
    {
		b->xs=initS();
		b=b->next;    
    }
    //free(b);
    
    lcj(a);//录成绩
    
    printf("最大总分为:%d\n",findMaxStu(a));
    printf("==========\n");
    printf("最小总分为:%d\n",findMinStu(a));
    printf("==========\n");
    printf("平均值:%f\n",getAverage(a));
    
	//system("pause");
	return 0;
}

涉及到的C语言知识点

  1. 结构体
  2. 指针
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值