• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

wukong04

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

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

#include <iostream>
using namespace std;
class Student
{
public:
void max(int *p,float *t);
};
void Student::max(int *p,float *t)
{
int i;
int a=0, b;
for (i = 0; i < 5; i++)
{
cin >> *(p + i);
cin >> *(t + i);
if (*(t + 1) > a) { a = *(t + i); b = *(p + i); }
}
cout << b << " " << a;
}
int main()
{
Student t1;
int a[10];
float b[10];
t1.max(a,b);
return 0;
}

posted on 2023-03-21 22:04  悟空+  阅读(523)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3