简单课后习题求高手指点啊!!!
题目是这样的:建立一个对象数组,内放5个学生的数据(学号、成绩),设立一个函数max。用指向对象的指针作函数参数,在max函数中找出5个学生中成绩最高者,并输出其学号。下面是我写的程序求指点错误。。。#include<iostream>
using namespace std;
class student
{
public:
student(int n,float s):number(n),score(s){}
void display();
int number:
float score:
};
void student::display()
{
cout<<number<<endl;
}
void max(student *pt)
{
int i,max_i=0;
float max_score=0;
for(i=0;i<5;i++)
{
if((pt+i)->score>max_score)
{max_score=(pt+i)->score;
max_i=i;
}
}
(pt+i)->display();
}
int main()
{
student stu[5]={student(1,3.0),student(2,3.2),student(3,5.3),student(4,3.8),student(5,4.2)};
student *p;
p=stu;
max(p);
return(0);
}