|
发表于 2015-3-31 21:09:55
|
显示全部楼层
- #include <iostream.h>
- class Student
- {
- public:
- Student(int i,double s):id(i),sroce(s){}
- //void max(Student *p);
- int id;
- double sroce;
- };
- //void Student :: max(Student *p)
- void max(Student *p)
- {
- double max = p[0].sroce;
- for(int i=0,j=0;i<5;i++)
- {
- if(p[i].sroce>max)
- {
- max = p[i].sroce;
- j = i;
- }
- }
- cout<<p[j].id<<" "<<max<<endl;
- }
- int main()
- {
- Student s[5]={
- Student(1,90),
- Student(2,94),
- Student(3,89),
- Student(4,97),
- Student(5,87)
- };
- void max(Student *p);
- Student *p = &s[0];
- max(p);
-
- return 0;
- }
复制代码 |
|