#include "iostream"
using namespace std;
class Student
{
public:
Student(int n,double s):num(n),score(s) {}
int getnum()
{
return num;
}
double getscore()
{
return score;
}
void show()
{
cout<<num<<" "<<score<<endl;
}
private:
int num;
double score;
};
int max(Student *arr);
int main()
{
Student stud[5]=
{
Student(101,78.5),Student(102,85.5),Student(103,100),Student(104,98.5),Student(105,95.5)
};
for(int i=0;i<5;i=i+2)
stud[i].show();
cout<<"5个学生中成绩最高者的学号为:"<<max(stud);
return 0;
}
int max(Student *arr)
{
double max_score=arr[0].getscore();
int k=0;
for(int i=1; i<5; i++)
if(arr[i].getscore()>max_score)
{
max_score=arr[i].getscore();
k=i;
}
return arr[k].getnum();
}
8.3指向学生类的指针
最新推荐文章于 2024-08-28 19:49:43 发布