您的位置:首页 > 其它

第五周实验报告4

2012-03-20 14:39 190 查看
#include<iostream>

using namespace std;

class Student
{
private:

int num;
int score;
public:
void show();

int getnum(){return num;}
int getscore(){return score;}
Student(int a,int b):num(a),score(b){}
};
void Student::show()
{
cout<<"学号:"<<num<<endl;
cout<<"成绩:"<<score<<endl;
}

int showmax(Student *p);
int main()
{
Student stu[5]=
{
Student(1,78),
Student(2,79),
Student(3,60),
Student(4,87),
Student(5,98)
};

for(int i=0;i<=4;i=i+2)
{
stu[i].show();

}
cout<<"成绩最大是:"<<showmax(stu)<<endl;
return 0;
}
int showmax(Student *p)
{
int max;
max=p[0].getscore();
for(int i=1;i<=4;i++)
{
if(p[i].getscore()>max)
{
max=p[i].getscore();
}
}
return max;
}

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: