#include<iostream>
using namespace std;
class Student
{ public:
Student(int n,int a,float s):num(n),age(a),score(s){}
void total();
static float average();
friend void show(Student&);
private:
int num,age;
float score;
static float sum;
static int count;
};
void Student::total()
{ sum+=score;
count++;
}
float Student::average()
{ return (sum/count);}
void show(Student&t)
{
cout<<"the intformating of student is:"<<endl<<t.num<<endl<<t.age<<endl<<t.score<<endl;
}
int Student::count=0;
float Student::sum=0;
int main()
{ Student stud[3]={Student(120,22,100),Student(119,22,89),Student(118,23,60)};
int n;
cout<<"please enter the number of students:"<<endl;
cin>>n;
for(int i=0;i<n;i++)
stud[i].total();
cout<<"the average score of"<<n<<"students is:"<<endl<<Student::average()<<endl;
for(int j=0;j<n;j++)
show(stud[j]);// 为什么不能这么做啊?我编译时进入了死循环.只有把两个for改为for(int i=0;i<n;i++){stud[i].total();show(stud[i]);}就可以了,为什么啊,谁能告诉我.谢谢
system("pause");
return 0;
}