概述
#include<iostream>
#include<string>
using namespace std;
class Student{
public:
Student(string name1,float score1);
void show();
void show_count_sum_ave();
private:
string name;
float score;
static int count;
static float sum;
float ave;
};
Student::Student(string name1,float score1)
{ name=name1;
score=score1;
++count;
sum=sum+score;
ave=sum/count;
}
void Student::show()
{
cout<<"姓名:"<<name<<endl;
cout<<"成绩:"<<score<<endl;
}
void Student::show_count_sum_ave()
{
cout<<"学生人数:"<<count<<endl;
cout<<"总分:"<<sum<<endl;
cout<<"平均分:"<<ave<<endl;
}
int Student::count=0;
float Student::sum=0.0;
float ave=0.0;
int main()
{
Student stu1("lina",100);
stu1.show();
stu1.show_count_sum_ave();
Student stu2("abc",90);
stu2.show();
stu2.show_count_sum_ave();
Student stu3("efg",85);
stu3.show();
stu3.show_count_sum_ave();
return 0;
}
最后
以上就是魁梧牛排为你收集整理的4.21输出学生人数和平均成绩的全部内容,希望文章能够帮你解决4.21输出学生人数和平均成绩所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复