Manchester


私信TA

用户名:wenyajie

访问量:312625

签 名:

在历史前进的逻辑中前进,这个逻辑就是人心向背的逻辑

等  级
排  名 1
经  验 62709
参赛次数 1
文章发表 188
年  龄 0
在职情况 学生
学  校 Xiamen University
专  业 计算机科学

  自我简介:

在历史前进的逻辑中前进,这个逻辑就是人心向背的逻辑

解题思路:
在1050题的基础上;

  1. 添加一个平均分成员变量ave;

  2. 在主函数中,所有成绩的平均分输出;

  3. 输出,个人平均分最高的学生信息;

  4. 下面代码只是给思路,不是纯正c++,c和c++的混合体,为了方便,就那样写了

参考代码:

#include <iostream>
#include <string.h>
using namespace std;
class student {
public:
    char    token[20];
    char    name[20];
    double    math;
    double    pe;
    double    el;
    double    ave;  //平均分


    void input();  //输入函数

    void output();  //输出函数
};

void student:: input()
{
    cin >> token;
    cin >> name;
    cin >> math;
    cin >> pe;
    cin >> el;
    ave = (math + pe + el) / 3;  //求平均分
}


void student::output()  //输出学生信息
{
    cout    << token
        << " "
        << name
        << " "
        << math
        << " "
        << pe
        << " "
        << el;
}


int main()
{
    int x;
    cin >> x;
    student *s = new student[x];  //创建对象数组

    for ( int i = 0; i < x; i++ )  //输入学生信息
        s[i].input();    

    double mave = 0, pave = 0, eave = 0;  //数学,体育,英语的平均分

    for ( int i = 0; i < x; i++ )    //求总分
    {
        mave    = mave + s[i].math;
        pave    = pave + s[i].pe;
        eave    = eave + s[i].el;
    }
    mave    /= x;   //求总体平均分
    pave    /= x;
    eave    /= x;
    int    max    = 0;   //个人平均分最高的学生下标
    double    Max    = 0;   //最大个人平均分
    cout << mave << " " << pave << " " << eave << endl;  //输出总体每科的平均分

    for ( int i = 0; i < x; i++ )   //求个人平均分最大的学生
    {
        if ( Max < s[i].ave )
        {
            Max = s[i].ave; max = i;
        }
    }

    s[max].output(); //输出个人平均分最大的学生

    return(0);
}

别忘点赞哦-.-

 

0.0分

25 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区

这问题能不能描述得严谨一点?既不说明最高成绩是以最高分还是最高平均分区分,也不说明平均分是否取整
2020-02-07 14:59:08
#include <stdio.h>
struct stud
{
	char num[20];
	char name[20];
	int english;
	int math;
	int chinese;
}stu[10];
int main()
{
	int i,n,ar1,ar2,ar3,s1=0,s2=0,s3=0;
	int a[10],max;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%s%s%d%d%d",&stu[i].num,&stu[i].name,&stu[i].english,&stu[i].math,&stu[i].chinese);
		a[i]=stu[i].english+stu[i].math+stu[i].chinese;
	}
	for(i=0;i<n;i++)
	{
		s1=s1+stu[i].english;
		s2=s2+stu[i].math;
		s3=s3+stu[i].chinese;
	}
	ar1=s1/2;
	ar2=s2/2;
	ar3=s3/2;
	printf("%d %d %d\n",ar1,ar2,ar3);
	max=a[0];
	if(a[1]>max)
	printf("%s %s %d %d %d",stu[1].num,stu[1].name,stu
2019-11-17 11:35:34
#include<stdio.h>

struct student
{
	char num[10];
	char name[10];
	int score[3];
};
void input(struct student stu[],int n )
{
	for (int i = 0; i < n; i++)
	{
		scanf("%s%s%d%d%d", stu[i].num, stu[i].name, &stu[i].score[0], &stu[i].score[1], &stu[i].score[2]);
	}
}
void print(struct student stu[], int n)
{
	double a;
	for (int i = 0; i < 3; i++)
	{
		a = 0;
		for (int j = 0; j < n; j++)
		{
			a += stu[j].score[i];
		}
		printf("%.0lf ", a / n);
	}
	printf("\n");
	int c = 0,d=0;
	for (int i = 0; i < n; i++)
	{
		int b = 0;
		for (int j = 0; j < 2; j++)
		{
			b += stu[i].score[j];
			if (b>c)
2019-09-23 08:51:07
#include <stdio.h>
struct Student
{
	char num[100];
	char name[100];
	int a1,a2,a3;
	int sum;
}stu[50];
int main(){
	int n,i,k;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%s %s %d %d %d",stu[i].num,stu[i].name,&stu[i].a1,&stu[i].a2,&stu[i].a3);
		stu[i].sum=stu[i].a1+stu[i].a2+stu[i].a3;
	}
	int s1=stu[0].a1,s2=stu[0].a2,s3=stu[0].a3;
	int max=stu[0].sum;
	for(i=1;i<n;i++){
		if(max<stu[i].sum){
			max=stu[i].sum;
			k=i;
		}
		s1=s1+stu[i].a1;
		s2=s2+stu[i].a2;
		s3=s3+stu[i].a3;
	}
	printf("%d %d %d\n",s1/n,s2/n,s3/n);
还请大佬帮小弟看一下,老是运行错误%50!
2019-05-05 21:46:36
#include<stdlib.h>
#include<stdio.h>
struct stu{
	char xuehao[20];
	char name[20];
	int a;
	int b;
	int c;
	struct stu *next;
};
struct stu *input(int n){
	struct stu *head,*pb,*pf,*p;
	for(int i=0;i<n;i++){
		pb=(struct stu *)malloc(sizeof(struct stu));
		scanf("%s%s%d%d%d",&pb->xuehao,&pb->name,&pb->a,&pb->b,&pb->c);
		if(i==0){
			pf=head=pb;
		}else{
			pf->next=pb;
			pb->next=NULL;
			pf=pb;
		}
	}
	return(head);
}
void print(struct stu *head){
	struct stu *p=head,*bb;
	int a[3]={0},i=0;
	int max=p->a+p->b+p->c;
	for(;p!=NULL;p=p->next){
		a[0]+=p->a;  a[1]+=p->b;  a[2]+=p->c;
		if(max<=
2019-02-19 22:18:40
万一最大平均分有相同的呢?就不止一个人分数最高
2018-03-21 15:51:46