#include<iostream>
using namespace std;
class Student
{
public:
void account(double a)
{
score=a;
total_score+=score;
count++;
}
static double sum()
{
cout<<"成绩之和:"<<total_score<<endl;
return total_score;
}
static double average()
{
double aver;
aver=total_score/count;
return aver;
}
private:
double score;
static double total_score;
static int count;
};
double Student::total_score=0.0;
int Student::count=0;
int main()
{
Student stu[3];
stu[0].account(99.3);
stu[1].account(78);
stu[2].account(89);
Student::sum();
cout<<"平均成绩:"<<Student::average()<<endl;
return 0;
}
运行结果: