#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
Student(string name1,int number1,float score1);
void show();
void show_count_sum_ave();
private:
string name;
int number;
float score;
static int count;
static float sum;
static float ave;
};
Student::Student(string n,int num,float s)
{
name=n;
number=num;
score=s;
count++;
sum+=score;
ave=sum/count;
}
void Student::show()
{
cout<<"name:"<<name<<endl;
cout<<"number:"<<number<<" ";
cout<<"score:"<<score<<endl;}
void Student::show_count_sum_ave()
{
cout<<"count:"<<count<<" ";
cout<<"sum:"<<sum<<" ";
cout<<"ave:"<<ave<<" ";
cout<<endl<<endl;
}
int Student::count=0;
float Student::sum=0.0;
float Student::ave=0.0;
int main()
{Student stu1("a",1,100);
stu1.show();
stu1.show_count_sum_ave();
Student stu2("b",2,99);
stu2.show();
stu2.show_count_sum_ave();
Student stu3("c",3,98);
stu3.show();
stu3.show_count_sum_ave();
return 0;
}
作业4.21
最新推荐文章于 2024-05-08 18:35:33 发布