[4.21]编写一个程序,已有若干个学生的数据,包括学号、姓名、成绩、要求输出这些学生的数据并计算出学生人数和平均成绩(要求将学生人数和总成绩用静态数据成员表示)。




#include 
class Student{ 
public: 
 Student(int num,int sco); 
    int getScore(); 
private: 
    int number; 
    int score; 
}; 
   
Student::Student(int num,int sco) 
{
   
    number=num; 
    score=sco; 

int Student::getScore() 

    return score; 

 
void  max(Student *stu)                                                      

     int big; 
     int j; 
  int i; 
   big=stu[0].getScore(); 
    for(i=1;i<6;i++) 
        if(stu[i].getScore()>big) 
                    big=stu[i].getScore();                                      
             for(j=0;j<6;j++)     
              if(stu[j].getScore()==big) 
               std::cout<<"成绩最高的学生的学号是"<
 
int main() 

    Student stu[6]={ 
       Student(1,70), 
        Student(2,50), 
        Student(3,80), 
        Student(4,90), 
       Student(5,60), 
       Student(6,100),}; 
               max(stu); 
       system("pause"); 
        return 0; 


运行结果:


你可能感兴趣的:([4.21]编写一个程序,已有若干个学生的数据,包括学号、姓名、成绩、要求输出这些学生的数据并计算出学生人数和平均成绩(要求将学生人数和总成绩用静态数据成员表示)。)