资 源 简 介
#include
using namespace std;
class Student
{
public:
Student(int, int);
int num;
int grade;
};
Student::Student(int n, int g)
{
num = n;
grade = g;
}
int maxGradeIndex(Student* s)
{
int maxGrade, index = 0, i = 0;
maxGrade = s[0].grade;
for (i = 0; i<5; i++)
{
if (s[i].grade > maxGrade)
{
maxGrade = s[i].grade;
index = i;
}
}
return index;
}
int main()
{
Student a[5] = { Student(1, 86), Student(2, 60), Student(3, 72), Student(4, 95), Student(5, 66) };
int maxGradeStNum = maxGradeIndex(a);
cout << "成绩最好学生的学号是:" << a[maxGradeStNum].num << endl;
cout << "成绩最好学生的成绩是:" << a[maxGradeStNum].grade << endl;
getchar();
return 0;
}