基于链表实现的学生成绩管理系统

C语言学习成果,主要是加强对链表的熟练操作。。。

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

//学生结构体
struct Student 
{
	int ID;
	int Chinese;
	int Math;
	int English;
	struct Student *next;
};
//班级结构体
struct Class
{
	int Classnum;
	struct Student *stuHead;	
	struct Class *next;

};

//头插法创建学生
struct Student *creatStu(struct Student *head,int classnum,int stunum)
{
	struct Student *new;
	int num = stunum;
	int j;
	
	for(j = 0;j<stunum;j++){
		new = (struct Student *)malloc(sizeof(struct Student));
		//输入名字
		printf("input Class%d the %d Student student-ID scores,please\n",classnum,num);
		scanf("%d",&new->ID);

		//输入语文成绩
		printf("input Class%d the %d Student Chinese scores (0-150) ,please\n",classnum,num);
		scanf("%d",&new->Chinese);

		//输入数学成绩
		printf("input Class%d the %d Student Math scores (0-150) ,please\n",classnum,num);
		scanf("%d",&new->Math);
		
		//输入英语成绩
		printf("input Class%d the %d Student English scores (0-150) ,please\n",classnum,num);
		scanf("%d",&new->English);
		break;	
		num--;
		//判断学生头节点是否为空,空则赋值,不空则添加
		if(head == NULL){
			head = new;

		}else{
			new->next = head;
        	head = new;
		}
	}
	printf("\n");
	return head;
}

//头插法创建班级
struct Class *creatClass(struct Class *head,int classnum,int stunum)
{
	struct Class *new = NULL;
	struct Student *stuhead;
	int num = classnum;

	int i;
	//头部添加班级
	for(i = 0;i<classnum;i++){
		new = (struct Class *)malloc(sizeof(struct Class));
		new->Classnum = num;
		stuhead = creatStu(stuhead,num,stunum);
		new->stuHead = stuhead;
		num--;
		//判断班级头节点是否为空,并赋值,空则赋值,不空则添加
		if(head == NULL){
			head = new;
		}else{
			new->next = head;
       		head = new;
		}
	}
	return head;
}


//打印数据
void printScore(struct Class *head,int classnum,int stunum)
{
	struct Student *p = NULL;
	struct Class *class;
	class = head;

	int j = classnum;
	int i = 0;
	while(j > 0){
		p = class->stuHead;
		printf("Class %d\n",j);
		while(p != NULL && i < stunum){	
				i++;
				printf("the %d student\nID:%d Chinese:%d Math:%d English:%d\n"
					,i,p->ID,p->Chinese,p->Math,p->English);
				p = p->next;
		}
		j--;
		i = 0;
		class = class->next;
	}
	printf("\n");
}

//获取最高分与其平均分
void getMax(struct Class *head,int classnum,int stunum)
{
	
	struct Class *class;
	struct Student *p = (struct Student *)malloc(sizeof(struct Student));
	class = head;
	p = class->stuHead;
	int total = 0;
	int max = 0;
	double ave = 0;
	int j = classnum;
	int i = 0;
	int id;
	while(j > 0){
		while(p != NULL && i < stunum*j){	
			total = p->Chinese + p->Math + p->English;
			if(total > max){
				id = p->ID;
				max = total;
			}
			p = p->next;
			i++;
		}
		j--;
		class = class->next;
	}
	ave = (double)max/3;
	//输出结果
	printf("-----------------------\n");
	printf("-----------------------\n");
	printf("The Best Student:");
	printf("student-ID is: %d\n",id);
	printf("The Score is: %d\n",max);
	printf("Average is: %f\n",ave);
	printf("----------------------\n");
	printf("-----------------------\n");
	
	printf("\n");
}

//获取最低分与七平均分
void getMin(struct Class *head,int classnum,int stunum)
{
	
	struct Class *class;
	struct Student *p = (struct Student *)malloc(sizeof(struct Student));
	class = head;
	p = class->stuHead;
	int min = p->Chinese + p->Math + p->English;
	int j = classnum;
	int total = 0;
	double ave = 0;
	int i = 0;
	int id;
	while(j > 0){
		while(p != NULL && i < stunum*j){	
			total = p->Chinese + p->Math + p->English;
			if(total < min){
				id = p->ID;
				min = total;
			}
			p = p->next;
			i++;
		}
		j--;
		class = class->next;
	}
		ave = (double)min/3;
	//输出结果
	printf("-----------------------\n");
	printf("-----------------------\n");
	printf("The Devoloping Student:");
	printf("student-ID is: %d\n",id);
	printf("The Score is: %d\n",min);
	printf("Average is: %f\n",ave);
	printf("----------------------\n");
	printf("-----------------------\n");
	printf("\n");
}

//展示初始届界面
void initdisplay()
{

	printf("---------------------------------------------\n");
	printf("----------------------------------------------\n");
    printf("----Student achievement management system-----\n");
    printf("----------------------------------------------\n");
    printf("---------------------------------------------\n");


}

//展示英文服务界面
void serverDisplay()
{

	printf("-------------------------------------------\n");
	printf("-------------------------------------------\n");
	printf("--------------------------------------------\n");
    printf("----Please enter the service you need------\n");
    printf("-------------------------------------------\n");
    printf("----1. Print all grades-------------------\n");
    printf("-------------------------------------------\n");
    printf("----2. Total score and average score-------\n");
    printf("-------of students with the highest score--\n");
    printf("-------------------------------------------\n");
    printf("----3. Total score and average score--------\n");
    printf("-------of students with the lowest score-----\n");
    printf("---------------------------------------------\n");
    printf("----4. Quit service-------------------------\n");
    printf("-------------------------------------------\n");
	printf("-------------------------------------------\n");
	printf("-------------------------------------------\n");

}

//展示中文服务界面
void serverDis()
{
	printf("-------------------------------------------\n");
	printf("------------------------------------------\n");
    printf("------------请输入您需要的服务--------------\n");
    printf("-------------------------------------------\n");
    printf("---------1.打印所有成绩-------------------\n");
    printf("-------------------------------------------\n");
    printf("---------2.得到最高分学生总分及其平均分-------\n");
    printf("-------------------------------------------\n");
    printf("---------3.得到最低分学生总分及其平均分--------\n");
    printf("---------------------------------------------\n");
    printf("---------4.退出服务-------------------------\n");
    printf("-------------------------------------------\n");
	printf("-------------------------------------------\n");

}

int main()
{
	initdisplay();
    int sum1 ;//班级个数
    int sum2 ;//学生个数
    int select;
    int language;
    struct Class *head = NULL;

  	printf("请输入班级个数\n");
    scanf("%d",&sum1);
    printf("请输入学生个数\n");
    scanf("%d",&sum2);
	
	head = creatClass(head,sum1,sum2);
	getchar();
	printf("language select\n1.English\n2.Chinese\n3.quit\n");
	scanf("%d",&language);
	switch(language){
		case 1:
			serverDisplay();
			break;
		case 2:
			serverDis();
			break;
		case 3:	
			break;
		default:
			printf("your inseret is error.\n");
			break;
	}

		scanf("%d",&select);
			switch(select){
				case 1:
					printScore(head,sum1,sum2);
					break;
				case 2:
					getMax(head,sum1,sum2);
					break;
				case 3:
					getMin(head,sum1,sum2);
					break;
				case 4:
					printf("Thank you for your use.");
					break;
				default:
					printf("your inseret is error.\n");
					break;
			}

	return 0;

}

学识浅薄,希望能帮到您

  • 5
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值