第5週実験報告4
1580 ワード
/* ( )
*
* Copyright (c) 2011,
* All rights reserved.
* :class Student
* :
* : 2012 03 21
* : 1.0
*
* : ,
* :
* :
*
*/
[cpp] view plaincopyprint?
1.#include <iostream>
2.using namespace std;
3.
4.class Student
5.{
6.public:
7. Student(int n,float s):num(n),score(s){}//
8.void display();
9.int getNum(){return num;}// ,
10.float getScore(){return score;}
11.private:
12.int num;
13.float score;
14.};
15.
16.void Student::display()
17.{
18. cout<<num<<" "<<score<<endl;
19.}
20.
21.int max(Student *arr);
22.
23.int main()
24.{
25. Student stud[5]={
26. Student(101,78.5),Student(102,85.5),Student(103,100),
27. Student(104,98.5),Student(105,95.5)};
28.
29.// 1、3、5
30.for(int i=0;i<5;i+=2)
31. {
32. cout<<" "<<i+1<<": ";
33. stud[i].display();
34. }
35.// ,
36.cout<<"5 : "<<max(stud);// , , arr
37.
38.system("pause");
39.return 0;
40.}
41.
42.int max(Student *arr)//arr ,
43.{
44.float max_score=arr[0].getScore();// getScore score
45.int k=0;
46.for(int i=1;i<5;i++)
47.if(arr[i].getScore()>max_score)
48.{
49.max_score=arr[i].getScore();
50.k=i;
51. }
52.return arr[k].getNum();
53.}
ネットの原因のため、ピクチャーを伝えることができなくて、多くプログラムを见ます!!!