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语言知识点
- 结构体
- 指针