计算高考状元 高考成绩已经公布,大家正在填报志愿。设计一个学生类student,四门学科成绩是其私有成员,分别是语文、数学、英语、综合。

1 篇文章 0 订阅
1 篇文章 0 订阅

高考成绩已经公布,大家正在填报志愿。设计一个学生类student,四门学科成绩是其私有成员,分别是语文、数学、英语、综合。有个计算高考状元的函数是其友元函数,其形式是 student top(const student *p, int count) 。
以上类名和友元函数的形式,均须按照题目要求,不得修改。
输入是姓名 和 四科成绩,以0结束。 (不超过100个学生)
输出是状元的总分。

输入样例:
Alice 105 107 107 230
Bob 112 120 120 250
0

输出样例:
602

源程序代码:
#include
#include
using namespace std;
class student{
 string name;
 int yu,shu,ying,zong;
 public:
  student(){
  }
  void voidset(string name,int a,int b,int c, int d){
   this->name=name;
   yu=a;
   shu=b;
   ying=c;
   zong=d;
  }
  friend student top(const student *p, int count);
};
student top(const student *p, int count){
 int sum;
 sum=p[0].yu+p[0].shu+p[0].ying+p[0].zong;
 for(int i=1;i<count;i++){
  if((p[i].yu+p[i].shu+p[i].ying+p[i].zong)>sum)
  sum=p[i].yu+p[i].shu+p[i].ying+p[i].zong;
 }
 cout<<sum; 
}
int main(){
 int yu,shu,ying,zong,i=0,count=0;
 string name;
 student stu[100];
 while(cin>>name && name!=“0”){
  cin>>yu>>shu>>ying>>zong;
  stu[i].voidset(name,yu,shu,ying,zong);
  count++;
  i++;
 }
 top(stu,count);
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值