输入成绩找出班级最低分

c++实现Student,含数据成员:学号、姓名、数学、语文、总分
要求:
(1)计算学生总分
(2)找出班级学生中总分最高的学生和最低的学生
(3)输出班级学生总分的平均分

#include <stdio.h>
#include <string>
#include <iostream>
using namespace std;

struct student
{
    int id;
	string name;
    int math;
	int chinese;
	int all;
};

void sortscore(struct student *score,int n)
{
    int i,j;
    struct student temp1;
    for(i=0;i<n-1;i++)
        for(j=i+1;j<n;j++)
            if (score[i].all<score[j].all)
            {
                temp1=score[i];score[i]=score[j];score[j]=temp1;                
            }   
}
int main()
{
    long maxnum;
    struct student score[11];
    int maxscore,n;
	float allscore=0;
	float aveg;
    printf("输入你们班的总人数:");
    scanf("%d", &n);    /*从键盘输入学生人数n*/

    for(int i=1; i<=n; i++)  {
		printf("\n输入第%d名学生的学号:\n",i);
        scanf("%d",&score[i].id);
		printf("输入第%d名学生的姓名:\n",i);
		cin>>score[i].name;
		printf("输入第%d名学生的数学成绩:\n",i);
		scanf("%d",&score[i].math);
		printf("输入第%d名学生的语文成绩:\n",i);
		scanf("%d",&score[i].chinese);
		score[i].all=score[i].math+score[i].chinese;
    }
		cout<<"\n大家的总分是:"<<endl;
		for( i=1;i<=n;i++)
		cout<<score[i].name<<":"<<score[i].all<<endl;

		for( i=1;i<=n;i++)
		allscore+=score[i].all;

    sortscore(score,n);
	cout<<"\n最高的是"<<score[0].name<<":"<<score[0].all<<endl;
	cout<<"最低的是"<<score[n].name<<":"<<score[n].all<<endl;
	
	cout<<"\n班级学生的平均分为:"<<endl;
	aveg=allscore/n;
	printf("%.2f\n",aveg);
    return 0;
}

在这里插入图片描述

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值