求助,要求得到成绩最高者的学号
#include<iostream>using namespace std;
class student
{
public:
void set_num(int n);
void set_grade(int g);
int get_grade();
int get_num();
int max(student*p);
private:
int num;
int grade;
};
int main()
{
int n,g;
student *p=new student[5];
for(int i=0;i<5;i++)
{
cout<<"输入学号:"<<endl;
cin>>n;
cout<<"输入成绩:"<<endl;
cin>>g;
(p+i)->set_num(n);
(p+i)->set_grade(g);
}
int max(student);
delete[]p;
return 0;
}
void student::set_num(int n)
{
num=n;
}
void student::set_grade(int g)
{
grade=g;
}
int student::get_num()
{
return num;
}
int student::get_grade()
{
return grade;
}
int student::max(student*p)
{
int j=0;
for(int i=1;i<5;i++)
{
if(p[i].get_grade()>p[j].get_grade())
j=i;
}
return(p[j].get_num());
}