#include<iostream>
using namespace std;
class student
{
public:
student(int n = 0, float sc = 60) : num(n), score(sc){};//用参数的初始化表对数据成员初始化。
void max(student *arr);
void display();
private:
int num;
int score;
};
void student :: display()
{
cout << num << " " << score << endl;
}
void student :: max(student *arr)
{
float max_score = arr[0].score;
int k;
for(int j = 1; j < 5; ++j)
{
if(arr[j].score > max_score)
{
max_score = arr[j].score;
k = j;
}
}
cout << arr[k].num << " " << max_score << endl;
}
int main()
{
student stud1;
student stud[5] = {
student(11, 80),
student(12, 79),
student(13, 89),
student(14, 96),
student(15, 81)
};
student *p = stud;
for(int i = 0; i <= 2; p += 2, ++i)
{
p->display();
}
cout << endl;
p->max(stud);
return 0;
}
第五周作业
最新推荐文章于 2020-05-20 13:41:40 发布