第五週作業

#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;
}

	







發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章