参照书本96页,例4.9
#include<iostream>
#include<string>
using namespace std;
class student{
public:
student(string i,string j,float k)
{
name=i;
number=j;
score=k;
++count;
sum=sum+score;
ave=sum/count;
}
void show()
{
cout<<"学生姓名:"<<name<<endl;
cout<<"学生学号:"<<number<<endl;
cout<<"学生成绩:"<<score<<endl;
}
void show_all()
{
cout<<"学生人数:"<<count<<endl;
cout<<"学生平均成绩:"<<ave<<endl;
}
private:
string name;
string number;
float score;
static float sum;
static int count;
static float ave;
};
int student::count=0;
float student::sum=0.0;
float student::ave=0.0;
int main()
{
student stu1("huaqing","201411671202",99);
stu1.show();
stu1.show_all();
student stu2("lurenjia","201411671203",90);
stu2.show();
stu2.show_all();
student stu3("lurenyi","201411671204",86);
stu3.show();
stu3.show_all();
system("pause");
return 0;
}