#include<iostream>
using namespace std;
class student
{
public:
student(int num1, float score1)
{
num = num1;
score = score1;
}
float getscore()
{
return score;
}
private:
int num;
float score;
};
void max(student *a)
{
int big= a[0].getscore();
for (int i = 1;i < 6; i++)
{
if (a[i].getscore()>big)
big = a[i].getscore();
}
for (int j = 0; j < 6;j++)
{
if (a[j].getscore() == big)
cout << "成绩最高者的学号为: " << j + 1 << endl;
}
}
int main()
{
student a[6] = { student(01, 98), student(02, 85), student(03, 90), student(04, 100), student(05, 84), student(06, 97) };
max(a);
return 0;
}
程序运行结果为:
成绩最高者的学号为:4