程序设计与问题求解实验 实验八

程序设计与问题求解实验

题目

设计一个保存学生成绩信息的结构,包括学号、姓名、课程名、平时成绩、考试成绩、总评成绩。分别用函数实现以下功能:

  1. 输入n个学生的信息(平时和考试成绩)
  2. 要求计算并输出学生的总分(平时20%,考试80%)并输出;
  3. 输出总分最高和最低的学生信息。

代码

我是用动态链表来存储学生信息的!

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
//#include <time.h>
#define LEN sizeof(struct student)
struct course
{
	float pea,exam;
};
struct student  //声明结构体
{
	long num;
	char name[20];
	float score;
	struct course Chi,Math,Eng;
	struct student *next;
};
int n;  //记录链表结构体数量
struct student *max,*min;  //保存最高分与最低分同学的信息
struct student *creat(void)  //建立关于学生的动态链表,并计算总成绩
{
	struct student *head;
	struct student *p1,*p2;
	n=0;
	p1=p2=(struct student * )malloc(LEN);
	printf("Please input student's ID and Name :\n");
	scanf("%ld %s",&p1->num,&p1->name);
	head=NULL;
	while (p1->num!=0)
	{
		n=n+1;
		if (n==1)head=p1;
		else p2->next=p1;
		p2=p1;
		p1=(struct student * )malloc(LEN);
		printf("Please input student's ID and Name :\n");
		scanf("%ld %s",&p1->num,&p1->name);
	 }
	p2->next=NULL;
	return(head);
}
void input(struct student *head)
{
	struct student *p;
	srand( (unsigned)time( NULL ) );
	for(p=head;p!=NULL;p=p->next)
	{
		printf("Please input %s's common,exam score of Chinese:\n",p->name);
		//printf("%.0f\t%.0f\n",p->Chi.pea=rand()%100,p->Chi.exam=rand()%100);
		scanf("%f %f",&p->Chi.pea,&p->Chi.exam);
		printf("Please input %s's common,exam score of Math:\n",p->name);
		//printf("%.0f\t%.0f\n",p->Math.pea=rand()%100,p->Math.exam=rand()%100);
		scanf("%f %f",&p->Math.pea,&p->Math.exam);
		printf("Please input %s's common,exam score of English:\n",p->name);
		//printf("%.0f\t%.0f\n",p->Eng.pea=rand()%100,p->Eng.exam=rand()%100);
		scanf("%f %f",&p->Eng.pea,&p->Eng.exam);
		p->score=(p->Chi.pea+p->Math.pea+p->Eng.pea)*0.2
			+(p->Chi.exam+p->Math.exam+p->Eng.exam)*0.8;
		//printf(" %f \n",p->score);
	}
}
void seek(struct student *head)  //搜索总分最高和最低
{
	struct student *p;
	float Max,Min;
	Max=Min=head->score;
	for(p=head;p!=NULL;p=p->next)
	{
		if(p->score>=Max)
		{
			Max=p->score;
			max=p;
		}
		if(p->score<=Min)
		{
			Min=p->score;
			min=p;
		}
	}
}
void print ()  //输出总分最高和最低
{
	printf("\nThere are %d students in all.\n",n);
	printf("The information of the students with the highest total score is as follows :\n");
	printf("%ld\t%s\t%.2f\n",max->num,max->name,max->score);
	printf("The information of the students with the lowest total score is as follows :\n");
	printf("%ld\t%s\t%.2f\n",min->num,min->name,min->score);
}
int main ( )								//主函数
{
	struct student *head;
	head=creat();
	input(head);
	seek(head);
	print();
	system("pause");
	return 0;
}
  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CartapenaBark

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值