第14周课后习题
计算高考状元
#include<iostream>
#include<cstring>
using namespace std;
class student
{
public:
void set(int a,int b,int c,int d)
{
maths=a;
chinese=b;
english=c;
comprehensive=d;
all=a+b+c+d;
}
friend student top(const student *p, int count);
private:
int maths,chinese,english,comprehensive,all;
char name[10];
};
student top(const student *p, int count)
{
int max=0;
int i;
for(i=0;i<count;i++)
max=max<p[i].all?p[i].all:max;
cout<<max<<endl;
return *p;
}
int main ()
{
string name;
student s[100];
int a,b,c,d,i=0;
cin>>name;
while (name!="0")
{
cin>>a>>b>>c>>d;
s[i++].set(a,b,c,d);
cin>>name;
}
top(s,i);
return 0;
}