第五周实验报告 任务4

#include <iostream>  
  
using namespace std;  
  
class Student  
{  
public:  
  
    int  max_student(Student *stu);  
      
private:  
    int num;  
  
    int score;  
};  
void main()  
{  
    Student *p;  
  
    Student stu[5] = {  Student(1,78),  Student(2,89),  Student(3,100), Student(4,98),  Student(5,99)};  
  
    p = stu;  
  
    for(int i = 0;i < 5;i = i+2)  
    {  
        cout << (*(p+i)).num << '\t' << (*(p+i)).score << endl;  
    }  
  
     stu[5].max_student(stu);  
  
    system("Pause");  
}  
int Student::max_student(Student *stu)  
{  
    int i;  
    Student *m;  
  
    m = &score;  
  
    for(i = 0;i < 5;i++)  
    {  
        if(*m < *score)  
        {  
            m = &score;  
        }  
  
    }  
    for(i = 0;i < 5;i++)  
    {  
        if(*m == stu[i].score)  
        {  
            cout << stu[i].num <<endl;  
        }  
    }  
    return 0;  
  
}  

 
阅读更多
想对作者说点什么? 我来说一句

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

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭