您的位置:首页 > 运维架构 > Linux

linux编程,C语言基础,基于链表的成绩管理系统

2020-07-20 04:23 1051 查看

基于链表的成绩管理系统

#include<stdio.h>
#include<stdlib.h>

typedef struct student
{
char *name;
int chinese;
int math;
int english;
struct student *temp;
}STU,*STCU;

typedef struct class
{
STCU stu1;
struct class *next;
}STC,*STCC;

void lianStudent(STCC head);

void lianClass(STCC head)
{
STCC p=head;
int h;
for(h=0;h<4;h++)
{
STCC new=(STCC)malloc(sizeof(STC)+5*sizeof(STU));
p->next=new;
p=new;
p->next=NULL;
}
lianStudent(head);
}

void lianStudent(STCC head)
{
int i,j;
STCC q=head;
head->stu1=(STCU)malloc(sizeof(STU));
STCU w=head->stu1;
for(i=0;i<5;i++)
{
if(i!=0)
{
w=(STCU)malloc(sizeof(STU));
}
for(j=0;j<4;j++)
{
STCU new=(STCU)malloc(sizeof(STU));
w->temp=new;
w=new;
w->temp=NULL;
}
if(i!=4)
{
q=q->next;
w=q->stu1;
}
}
}

void shuRuChengJi(STCC head)
{
int i,j;
STCC p=head;
STCU q=p->stu1;
for(i=0;i<5;i++)
{
printf("The %d class\n",i+1);
for(j=0;j<5;j++)
{
q->name=(char *)malloc(128);
printf("please input %d student's score\n",j+1);
printf("please input his name\n");
scanf("%s",q->name);
printf("please input his Chinese score\n");
scanf("%d",&q->chinese);
printf("please input his Math score\n");
scanf("%d",&q->math);
printf("please input his English score\n");
scanf("%d",&q->english);
if(j!=4)
{
q=q->temp;
}
}
if(i!=4)
{
p=p->next;
q=p->stu1;
}
}
}

void jiSuanZongFen(STCC head)
{
STCC p=head;
STCU q=p->stu1;
int i,j;
int sum[5]={0};
int max=sum[0],min=sum[0];
int maxnum,minnum;
float ava=0;
for(j=0;j<5;j++)
{
sum[0]=0;
sum[1]=0;
sum[2]=0;
sum[3]=0;
sum[4]=0;
ava=0;
for(i=0;i<5;i++)
{
sum[i]=sum[i]+q->chinese+q->math+q->english;
if(i!=4)
{
q=q->temp;
}
}
max=sum[0];
min=sum[0];
for(i=0;i<5;i++)
{
ava+=sum[i];
}
ava=(float)ava/5;
q=p->stu1;
for(i=0;i<5;i++)
{
if(sum[i]>max)
{
max=sum[i];
maxnum=i+1;
}
if(sum[i]<min)
{
min=sum[i];
minnum=i+1;

}
}
for(i=0;i<maxnum-1;i++)
{
q=q->temp;
}
printf("%d class:\n",j+1);
printf("average total score:%f\n",ava);
printf("%s is the best,his score is %d\n",q->name,max);
q=p->stu1;
for(i=0;i<minnum-1;i++)
{
q=q->temp;
}
printf("%s is the lowest,his score is %d\n",q->name,min);
if(j!=4)
{
p=p->next;
q=p->stu1;
}
}
}

int main()
{
STCC head=(STCC)malloc(sizeof(STC)+5*sizeof(STU));
lianClass(head);
//	int i,j;
//	STCC p=head;
//	STCU q=p->stu1;
/*	for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
printf("input\n");
scanf("%d",&q->chinese);
printf("%d",q->chinese);
q=q->temp;
}
p=p->next;
q=p->stu1;
}*/
shuRuChengJi(head);
jiSuanZongFen(head);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: