2021-03-14 学生成绩管理系统

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


struct cla 
{
	int num;
	int numstu;
	struct cla *next;
	struct stu *nextstu;
}; 

struct stu
{	
	int num;
	char name[4];
	
	int math;
	int china;
	int eng;
	int sum;
	struct stu *next;
};

int printClass(struct cla* head)
{
	
	
	
	struct cla *p=head;
  printf("开始遍历班级");
		while(p!=NULL)
	{ 
		printf("%d ",p->num);
		p = p->next;
		
	}
	
	printf("\n");
	return 0;
	
}
int printStudent(struct stu* head)
{
	
	
	
struct stu *p=head;
  printf("开始遍历学生");
		while(p!=NULL)
	{ 
		printf("%d ",p->num);
		p = p->next;
		
	}
	
	printf("\n");
	return 0;
	
}


struct cla* insertClassBehind(struct cla *head,struct cla *newlink)
{
	struct cla *p=head;
	
	if(head==NULL)	
	{
		head=newlink;
	}
	else 
	{
	
	while(p->next!=NULL)
		{
			p=p->next;
		}
		p->next=newlink;
	}
	
return head;	
}

struct stu* insertClassStuBehind(struct stu *head,struct stu *newlink)
{
	struct stu *p=head;
	
	if(head==NULL)	
	{
		head=newlink;
	}
	else 
	{
	
	while(p->next!=NULL)
		{
			p=p->next;
		}
		p->next=newlink;
	}
	
return head;	
}


struct stu* cteateStudentinkBehind(struct stu *head)
{	struct stu *p=head;
	struct  stu *newlink; 
	
	
	for(int i=0;i<5;i++)
	{
		newlink=(struct stu*)malloc(sizeof(struct stu));
		newlink->next=NULL;
		printf("开始创建%d号同学\n",i+1);
		newlink->num=i+1;
		newlink->china=95+i;
		newlink->math=95+i;
		newlink->eng=95+i;
		newlink->sum=newlink->china+newlink->math+newlink->eng;
		head=insertClassStuBehind(head,newlink);
		printStudent(head);
	} 
	return head;
	printf("创建该班级学生结束\n"); 
}


struct cla* cteateClassLinkBehind(struct cla *head)
{	struct cla *p=head;
	struct  cla *newlink; 
	
	
	for(int i=0;i<5;i++)
	{
		newlink=(struct cla*)malloc(sizeof(struct cla));
		newlink->next=NULL;
		printf("开始创建%d班\n",i+1);
		newlink->num=i+1;
		head=insertClassBehind(head,newlink);
	} 
	return head;
	printf("创建班级结束\n"); 
}

struct cla * connectClassStudentLink(struct cla *head,struct stu *headstu)
{
	struct cla *p=head;
	struct stu *s=headstu; 
	
	while(head!=NULL)
	{
		head->nextstu=cteateStudentinkBehind(headstu);
		head=head->next;
	}
	return p;
}

int printClassStudent(struct cla *head,struct stu *headstu)
{
	struct cla *p=head;
	struct stu *s=head->nextstu; 
	while(p!=NULL)
	{
	printf("%d班 ",p->num);
	
		s=p->nextstu;
		while(s!=NULL)
		{
		printf("%d号  ",s->num);
		s =s ->next;
		}
		p = p->next;
		printf("\n"); 
	}
}

int printClassStudentScore(struct cla *head,struct stu *headstu)
{
	struct cla *p=head;
	struct stu *s=head->nextstu; 
	int sumscore=0;
	int avg;
	int countstudent=0;
	while(p!=NULL)
	{
	printf("%d班 ",p->num);
	printf("\n");
		s=p->nextstu;
		while(s!=NULL)
		{
		printf("%d号  ",s->num);
		printf("总分%d  \n",s->sum);
		sumscore=sumscore+s->sum;
		countstudent++;
		s =s ->next;
		}
		p = p->next;
		printf("\n"); 
	}
	avg=sumscore/countstudent;
	printf("平均总分:%d\n累加总分:%d\n学生人数:%d\n",avg,sumscore,countstudent);
	
}
int main()
{
  	struct cla *head=NULL;
 	struct stu *headstu=NULL;
	head=cteateClassLinkBehind(head); 
	head->nextstu=headstu;
//	headstu=cteateStudentinkBehind(headstu);
//	printStudent(headstu);
	
	 head=connectClassStudentLink(head,headstu);
	 printClassStudent(head,headstu);
	 printClassStudentScore(head,headstu);
	 
 } 

在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值