PTA 计算高考状元

计算高考状元
高考成绩已经公布,大家正在填报志愿。设计一个学生类student,四门学科成绩是其私有成员,分别是语文、数学、英语、综合。有个计算高考状元的函数是其友元函数,其形式是 student top(const student *p, int count) 。

以上类名和友元函数的形式,均须按照题目要求,不得修改。

输入是姓名 和 四科成绩,以0结束。 (不超过100个学生) 输出是状元的总分。

输入样例:

Alice 105 107 107 230

Bob 112 120 120 250

0

输出样例:

602

#include<iostream>
#include<string>
using namespace std;
class student
{
    string name;
    int yu,shu,yin,zong;
    public:

        student()
        {
            name="0";yu=0;shu=0;
            yin=0;zong=0;
        };
        void set(string name1,int yu1,int shu1,int yin1,int zong1)
        {
            name=name1;yu=yu1;shu=shu1;yin=yin1;zong=zong1;
        }
        friend student top(const student *p,int count );
};
 student top(const student *p,int count )
{
    int top1=0;
    int add=0;
    for(int i=0;i<count;i++)
    {
        add=p[i].yu+p[i].shu+p[i].yin+p[i].zong;
        if(add>top1)
            {
                top1=add;
            }
    }
    cout<<top1;
    return *p;
}
int main()
{
    student St[100];
        string name;
        int num=0;
    int yu,shu,yin,zong;
    cin>>name;
    while(name!="0")
    {   cin>>yu>>shu>>yin>>zong;
        //student stu[num];
    /*  St[num].name=name;
        St[num].yu=yu;
        St[num].shu=shu;
        St[num].yin=yin;
        St[num].zong=zong;*/
        St[num].set(name,yu,shu,yin,zong);
        num++;
        cin>>name;
    }
    top(St,num);
    return 0;
}
  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

YULIU_

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

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

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

打赏作者

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

抵扣说明:

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

余额充值