前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++之类和对象课后习题1

C++之类和对象课后习题1

作者头像
互联网金融打杂
发布2018-04-03 14:06:08
5350
发布2018-04-03 14:06:08
举报
文章被收录于专栏:测试开发架构之路

建立一个对象数组,内放5个学生的(学号,成绩),设立一个函数max,用指向对象的指针作函数参数,在max函数中找出5个学生的最高成绩者,并输出其学号。

代码语言:javascript
复制
#include<iostream>
using namespace std;

class Student
{public:
    Student(int=10,int=0);
    int number;
    int score;
    void display();
};

Student::Student(int num,int sco):number(num),score(sco){
}

void Student::display()
{
    cout<<number<<" "<<score<<endl;
}

void max(Student *p)
{
    int maxi=p[0].score;
    int temp=0;
    for(int i=1;i<5;i++)
    if(p[i].score>maxi)
    {
    maxi=p[i].score;
    temp=i;
    }
    cout<<p[temp].number<<" "<<maxi<<endl;
}

int main()
{
    Student stu[5]={
Student{1001,90},
Student{1002,80},
Student{1003,99},
Student{1004,84},
Student{1005,85}
};
    Student *p=&stu[0];
     max(p);
    return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-07-06 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档