链表嵌套链表实现学生管理系统

#include <stdio.h>
#include <stdlib.h>
void topic()
{
	printf("=======================================================================\n");
	printf("链表A,每个节点存放一个新的链表B1,B2,B3,B4,B5的头结点。\n");
	printf("场景:一个年级,相当链表A该年级5个班,每个班5个人。\n");
	printf("相当于链表B1–B5做一个学生成绩管理系统学生成绩有语文 数学 英语。\n");
	printf("录入成绩,找出三科总分的最高分,最低分,算出平均成绩。\n");
	printf("=======================================================================\n\n");
}
void welcome()
{
	puts("*************************************************************************\n");
	puts("欢迎使用学生管理系统");
	puts("\n***********************************************************************\n");
}

struct Class
{
	char name[32];
	struct Class *next;
	struct Student *studentHead;
};
struct Student
{
	char name[32];
	int yingyu;
	int yuwen;
	int shuxue;
	int sum;
	struct Student *next;
};
struct Class *classHead = NULL;
struct Student *stuHead = NULL;

void init(int *pclassCount, int *studentCount)
{
	void (*ptopic)() = topic;
	(*ptopic)();
	void (*pwelcome)() = welcome;
	(*pwelcome)();
	puts("请输入班级数");
	scanf("%d",pclassCount);
	puts("请输入班级学生人数");
	scanf("%d",studentCount);
}
// 遍历链表
void printLink()
{
	struct Class *p = classHead;
	struct Student *p2 = stuHead;
	while(p != NULL){
		p2 = p->studentHead;
		while(p2 != NULL){
			printf("====================================================\n");
			printf("%s班的%s语文成绩为%d分\n",p->name,p2->name,p2->yuwen);
			printf("%s班的%s数学成绩为%d分\n",p->name,p2->name,p2->shuxue);
			printf("%s班的%s英语成绩为%d分\n",p->name,p2->name,p2->yingyu);
			printf("%s班的%s总成绩为%d分\n",p->name,p2->name,p2->sum);
			printf("====================================================\n\n");
			p2 = p2->next;
		}
		p = p->next;
	}
}
// 创建学生节点
struct Student* createStudentNode(struct Student *new)
{
	struct Student *p = stuHead;
	if(p == NULL){
		p = new;
		return p;
	}
	while(p->next != NULL){
		p = p->next;
	}
	p->next = new;
	return stuHead;
}
// 登记学生成绩
struct Student* registerStudentScore(int studentCount)
{
	int i;
	struct Student *new = NULL;
	for(i = 0; i < studentCount; i++){
		new = (struct Student *)malloc(sizeof(struct Student));
		puts("请输入学生姓名");
		scanf("%s",&(new->name));
		puts("请输入英语成绩");
		scanf("%d",&(new->yingyu));
		puts("请输入语文成绩");
		scanf("%d",&(new->yuwen));
		puts("请输入数学成绩");
		scanf("%d",&(new->shuxue));
		new->next = NULL;
		new->sum = new->yingyu + new->yuwen + new->shuxue;
		// 创建学生节点
		stuHead = createStudentNode(new);
	}
	return stuHead;
}
// 创建班级节点
struct Class* createClassNode(struct Class *new)
{
	struct Class * p = classHead;
	if(p == NULL){
		p = new;
		return p;
	}
	while(p->next != NULL){
		p = p->next;
	}
	p->next = new;
	return classHead;
}
// 初始化班级
struct Class* initClass(int classCount, int studentCount)
{
	int i;
	struct Class *new = NULL;
	for(i = 0; i < classCount; i++){
		new = (struct Class *)malloc(sizeof(struct Class));
		puts("请输入班级名称!");
		scanf("%s",&(new->name));
		new->next = NULL;
		// 创建班级节点
		classHead = createClassNode(new);
		// 登记学生成绩
		new->studentHead = registerStudentScore(studentCount);
	}
	//return classHead;
}
// 最高分
int getMax()
{
	int max;
	struct Class *p = classHead;
	struct Student *p2 = NULL;
	max = p->studentHead->sum;
	while(p != NULL){
		p2 = p->studentHead;
		while(p2 != NULL){
			if(p2->sum > max){
				max = p2->sum;
			}
			p2 = p2->next;
		}
		p = p->next;
	}
	return max;
}
int getMin()
{
	int min;
	struct Class *p = classHead;
	struct Student *p2 = NULL;
	min = p->studentHead->sum;
	while(p != NULL){
		p2 = p->studentHead;
		while(p2 != NULL){
			if(p2->sum < min){
				min = p2->sum;
			}
			p2 = p2->next;
		}
		p = p->next;
	}
	return min;
}
float getAver(int classCount, int studentCount){
	float aver;
	int sum = 0;
	struct Class *p = classHead;
	struct Student *p2 = NULL;
	while(p != NULL){
		p2 = p->studentHead;
		while(p2 != NULL){
			sum = sum + p2->sum;
			p2 = p2->next;
		}
		p = p->next;
	}
	aver = sum / (float)(classCount * studentCount);
	return aver;
}
int main()
{
	int classCount;
	int studentCount;
	int max,min;
	float aver;
	
	init(&classCount, &studentCount);
	
	// 初始化班级
	initClass(classCount, studentCount);
	printLink();
	
	max = getMax();
	min = getMin();
	aver = getAver(classCount, studentCount);
	printf("总分最高的是:%d\n总分最低的是:%d\n总分平均分是:%2.f\n",max ,min, aver);
	
	return 0;	
}

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值