第四章第二十一题



#include<iostream>
#include<string>
using namespace std;
class student{
public:
 student(int id1,string name1,double score1);
 void show();
 static void show_count_sum_ave();
private:
 int id;
 string name;
 double score;
 static int count;
 static double sum;
 static double ave;
};
student::student(int id1,string name1,double score1)
{id=id1;
name=name1;
score=score1;
++count;
sum=sum+score;
ave=sum/count;
}
void student::show()
{cout<<"姓名:"<<name<<endl;
cout<<"学号:"<<id<<endl;
cout<<"成绩:"<<score<<endl;
}
void student::show_count_sum_ave()
{cout<<"学生人数:"<<count<<endl;
cout<<"学生总成绩:"<<sum<<endl;
cout<<"学生平均成绩:"<<ave<<endl;
}
int student::count=0;
double student::sum=0.0;
double student::ave=0.0;
int main()
{student stu1(01,"zhangsan",90);
stu1.show();
student::show_count_sum_ave();

student stu2(02,"lisi",80);
stu2.show();
student::show_count_sum_ave();

student stu3(03,"wangwu",70);
stu3.show();
student::show_count_sum_ave();
return 0;

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值