4.18

来源:互联网 发布:淘宝童学少年儿童家具 编辑:程序博客网 时间:2024/05/16 13:52
  1. #include<iostream>  
  2. #include<cstdlib>  
  3. using namespace std;  
  4. class student{  
  5. private:  
  6.   
  7. public:  
  8. int number,math;  
  9.  void  stu(int num,int m)  
  10. {  
  11.    number=num;  
  12.    math=m;  
  13. }  
  14.   
  15.   
  16. };  
  17. void max(student *p)  
  18. {  
  19. int i,j;  
  20. student s[1];  
  21. s[0].math=(*p).math;  
  22. s[0].number=(*p).number;  
  23. p++;  
  24.     for(j=0;j<6-1;j++)  
  25. {  
  26.          
  27.             if((*p).math>s[0].math)//数组元素大小按升序排列  
  28.             {  
  29.                 s[0].math=(*p).math;  
  30. s[0].number=(*p).number;  
  31.                 p++;  
  32.                   
  33.             }  
  34.           
  35.  }  
  36.      cout<<s[0].number<<" "<<s[0].math<<endl;  
  37. }  
  38. int main()  
  39. {  
  40. student stu[6];  
  41. stu[0].stu(01,88);  
  42. stu[1].stu(02,90);  
  43. stu[2].stu(03,100);  
  44.         stu[3].stu(04,94);  
  45.         stu[4].stu(05,96);  
  46.         stu[5].stu(06,98);   
  47.   
  48. student *q;  
  49. q=stu;  
  50. max(q);  
  51.   
  52.  system("pause");  
  53. return 0;  
  54. }  
0 0
原创粉丝点击