#include<iostream>
using namespace std;
//建立对象数组,内放5个学生数据
class Student
{
public:
Student(int n,double s):num(n),score(s){}
friend void max(Student *);
private:
int num;
double score;
};
void max(Student *p)
{
double score_max = p[0].score;
int count;
for (int i = 0; i < 5; i++)
if (p[i].score > score_max)
{
score_max = p[i].score;
count = i;
}
cout << "第" << count + 1 << "个同学成绩最好,他的学号是" << p[count].num << endl;
}
int main()
{
Student stud[5] = {
Student(101,89),
Student(102,87.5),
Student(103,99),
Student(104,97.5),
Student(105,86)
};
Student* pt = stud;
max(pt);
return 0;
}
谭浩强c++第三版9-5
最新推荐文章于 2020-04-12 14:34:24 发布