#include<iostream>
#include<string>
using namespace std;
class student
{
public:
student(int num,string name1,float score1);
void show();
static void show_all();
private:
int num;
string name;
float score;
static int count;
static float sum;
static float ave;
};
student::student(int num1,string name1,float score1)
{
num=num1;
name=name1;
score=score1;
++count;
sum=sum+score;
ave=sum/count;
}
void student::show()
{
cout<<"学号:"<<num<<endl;
cout<<"姓名:"<<name<<endl;
cout<<"成绩:"<<score<<endl;
cout<<".........................."<<endl;
}
void student::show_all()
{
cout<<"学生总人数:"<<count<<endl;
cout<<"学生总成绩:"<<sum<<endl;
cout<<"学生平均成绩:"<<ave<<endl;
}
int student::count=0;
float student::sum=0.0;
float student::ave=0.0;
int main()
{
student stu[3]={
student(1,"a",96),
student(2,"b",89),
student(3,"c",69)
};
student *p;
p=stu;
for(int j=0;j<3;j++,p++)
p->show();
student::show_all();
return 0;
}
第四单元 4.21
最新推荐文章于 2024-04-21 11:31:55 发布