#include<iostream>
#include<string>
using namespace std;
class student{
public:
student(stringname1,float score1,string id1)
{name=name1;
score=score1;
id=id1;
++count;
sum=sum+score;
ave=sum/count;
}
voidshow()
{cout<<"学生姓名为:"<<name<<endl;
cout<<"学生成绩为:"<<score<<endl;
cout<<"学生学号为:"<<id<<endl;
}
voidshow_ave_count()
{
cout<<"学生人数为:"<<count<<endl;
cout<<"总成绩为:"<<sum<<endl;
cout<<"平均成绩为:"<<ave<<endl;
}
private:
stringname;
floatscore;
stringid;
staticint count;
staticfloat sum;
staticfloat ave;
};
int student::count=0;
float student::sum=0.0;
float student::ave=0.0;
int main()
{
studentstu1("fish",74.5,"24");
stu1.show();
stu1.show_ave_count();
cout<<"------我是分隔线君----------"<<endl;
studentstu2("liu",75,"15");
stu2.show();
stu2.show_ave_count();
return0;
}
这是一个C++程序,定义了一个`student`类,用于存储学生的姓名、成绩和学号。程序创建了两个`student`对象,并显示了每个学生的详细信息,同时计算并输出了所有学生的总人数和平均成绩。

275

被折叠的 条评论
为什么被折叠?



