在作业4.17的基础上,用学生类的对象指针作为参数,用一个循环选出最高成绩,一个循环输出最高成绩的学生的学号!
#include<iostream>
using namespace std;
class student{
public:
student(double a,int b)
{
number=a;
score=b;
}
int show();
double show1();
private:
double number;
int score;
};
int student::show()
{
return score;
}
double student::show1()
{
return number;
}
void max(student *p)
{
int i;
int big;
big=p->show();
for(i=1;i<6;i++)
{
p++;
if(big<p->show())
big=p->show();
}
cout<<"最高成绩是:"<<big<<endl;
for(int j=0;j<6;j++)
{
if(big==p->show())
cout<<"该学生的学号是:"<<p->show1()<<endl;
p--;
}
}
int main()
{
student stu[6]={
student(01,96),
student(02,100),
student(03,70),
student(04,60),
student(05,50),
student(06,80)
};
student *pr;
pr=stu;
max(pr);
system("pause");
return 0;
}