编写一个程序,已有若干学生数据,包括学号,姓名,成绩,要求输出这些学生的数据并计算出学生人数和平均成绩。
#include<iostream>
#include<string>
using namespace std;
class student
{
public:
student(int num1,string name1,double score1)
{
num=num1;
name=name1;
score=score1;
count++;
sum+=score1;
aver=sum/count;
}
void show()
{
cout<<"num="<<num<<endl;
cout<<"name="<<name<<endl;
cout<<"score="<<score<<endl;
}
static void show1()
{
cout<<"the numbers of students:"<<count<<endl;
cout<<"the aver score of students:"<<aver<<endl;
}
private:
int num;
string name;
double score;
static double sum;
static int count;
static double aver;
};
double student::sum=0.0;
int student::count=0;
double student::aver=0.0;
int main()
{
student stu1(01,"wubeiren",98);
stu1.show();
student stu2(02,"lianjingxing",100);
stu2.show();
student stu3(03,"lvyingchuang",88);
stu3.show();
student::show1();
return 0;
}