求大神帮我看一道简单的C++程序,看错误在哪里

2025-03-06 12:37:12
推荐回答(2个)
回答1:

cout<
修改为

cout<

回答2:

/*

p[3].score = 100

Press any key to continue

*/

#include
using namespace std;
class student {
public:
int num;
float score;
student(int n,float s):num(n),score(s){}
};

int main() {
student stud[5] = {student(101,78.5),student(102,85.5),student(103,98.5),
student(104,100.0),student(105,95.5)
};
void max(student*,int);
max(stud,5);
return 0;
}

void max(student *p,int n) {
float max_score = p[0].score;
int k = 0;
for(int i = 1;i < 5;i++) {
if(p[i].score > max_score) {
max_score = p[i].score;
k = i;
}
}
cout << "p[" << k << "].score = " << p[k].score << endl;
}