#include<iostream>
#include<string>
using namespace std;
class student
{
public:
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;
}
student(string num1,string name1,double score1)
{
num=num1;
name=name1;
score=score1;
count++;
sum+=score1;
aver=sum/count;
}
private:
string 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","huangchongwen",98);
stu1.show();
student stu2("02","chenxi",100);
stu2.show();
student stu3("03","dazhong",88);
stu3.show();
student::show1();
return 0;
}
作业4.21
最新推荐文章于 2024-05-08 18:35:33 发布