十分简单的对象数组比较成绩大小输出学号
代码如下
class max_score
{
public:
void set_max();
void max_max();
private:
int a[10];
};
void max_score::set_max()
{ for(int i=0;i<10;i++)
cin>>a[i];
}
void max_score::max_max()
{ int *max;max=&a[1];
int i;
for(i=3;i<10;i+=2)
if(a[i]>*max)max=&a[i];
cout<<"the highest score is "<<*max<<endl;
max--;
cout<<"and the person is "<<*max<<endl;
}
main()
{
max_score m1;
m1.set_max();
m1.max_max();
}
这样一个简单的比大小,输出成绩学号的代码就完成了
不过在输出的函数中 max_max,
我没有想到更好的代码;如果不用指针会怎么样呢
菜鸡一个,欢迎批评。