第五周作业

#include<iostream>

using namespace std;

class student
{
public:
	student(int n = 0, float sc = 60) : num(n), score(sc){};//用参数的初始化表对数据成员初始化。
	void max(student *arr);
	void display();
private:
	int num;
	int score;
	
};

void student :: display()
{
	cout << num << "   " << score << endl;
}

void student :: max(student *arr)
{
	float max_score = arr[0].score;
	int k;
	for(int j = 1; j < 5; ++j)
	{
		if(arr[j].score > max_score)
		{
			max_score = arr[j].score;
			k = j;
		}
	}
	cout << arr[k].num << "   " << max_score << endl;
}


int main()
{
	student stud1;
	student stud[5] = {
		student(11, 80),
	    student(12, 79),
		student(13, 89),
		student(14, 96),
		student(15, 81)
	};
	student *p = stud;
	for(int i = 0; i <= 2; p += 2, ++i)
	{
		p->display();
	}
    cout << endl;

	p->max(stud);

	return 0;
}

	







阅读更多
文章标签: 作业 float
上一篇第五周作业3
下一篇第六周作业
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭