#include<iostream>
using namespace std;
const int SIZE =10;
class Student
{
private:
static int count;
static float total;
float score;
public :
void scoretotalcount(float s);
static float sum();
static float average();
};
int Student::count=0;
float Student::total=0;
void Student::scoretotalcount(float s)
{
score =s;
count++;
total=total+score;
}
float Student::sum()
{
return total;
}
float Student::average()
{
return total/count;
}
Student student[SIZE];
int main(void)
{
float grade;
int i=0;
cout<<"请输入每个人的成绩:"<<endl;
for(i=0;i<SIZE;i++)
{
cin>>grade;
student[i].scoretotalcount(grade);
}
cout<<"全班总分为:"<<Student::sum()<<endl;
cout<<"全班成绩平均分为:"<<Student::average()<<endl;
return 0;
}
你参考一下吧。