c++程序问题 。建立一个对象数组,内放5个学生的数据(学号、成绩),设立一个 20

建立一个对象数组,内放5个学生的数据(学号、成绩),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出五个学生中成就最高者,并输出其学号... 建立一个对象数组,内放5个学生的数据(学号、成绩),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出五个学生中成就最高者,并输出其学号 展开
 我来答
fengfei5551223
2015-12-03 · TA获得超过135个赞
知道小有建树答主
回答量:213
采纳率:100%
帮助的人:122万
展开全部

#include<iostream>

#include<string.h>

using namespace std;

class  student

{

public:

student(string number,int  id)

{

this->number=number;

this->id=id;


}

int getscore(){

return  id;


}

string  getname(){

return  number;

}

private:

string  number;

int  id;


};

int main()

{

student  stu[5]={student("001",100),student("002",100),student("003",99),student("004",95),student("0055",86)};

int  max_score=stu[0].getscore();

for(int i=0;i<5;i++)

{

if (max_score <stu[i].getscore())

{

  max_score=stu[i].getscore();

}


}

cout<<"最高分为"<<max_score<<endl;


for(int j=0;j<5;j++)

{

if(stu[j].getscore()==max_score)

{

cout<<"最高分的学生学号为:"<<stu[j].getname()<<endl;

}


}


}

//运行结果为:

./a.out

最高分为100

最高分的学生学号为:001

最高分的学生学号为:002

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式