/* (程序頭部註釋開始)
* 程序的版權和版本聲明部分
* Copyright (c) 2011, 煙臺大學計算機學院學生
* All rights reserved.
* 文件名稱:
* 作 者: 晁陽
* 完成日期: 2012 年 03 月 20 日
* 版 本 號:t 1.0
max函數是在不會啊,參考了同學的!
#include<iostream>
using namespace std;
class Student
{
public:
Student (int n,int s):num(n),score(s){};
void max( Student *p );
void show();
private:
int num;
int score;
};
void Student::show()
{
cout << num << " " << score << endl;
}
void Student::max( Student *p )//這個函數是在不會寫!!!!!!
{
int max_score = p[0].score;
int k;
for(int j = 1; j < 5; ++j)
{
if(p[j].score > max_score)
{
max_score = p[j].score;
k = j;
}
}
cout << "最高成績同學的學號和成績:" << endl << endl;
cout << p[k].num << " " << max_score << endl;
}
int main()
{
Student stud[5] = {
Student( 01, 95),
Student( 02, 96),
Student( 03, 99),
Student( 04, 97),
Student( 05, 98)
};
Student *p =stud;
for(int i = 0; i <= 2; p += 2, ++i)
{
p->show();
}
cout << endl;
p->max(stud);
system("PAUSE");
return 0;
}