第四章第二十一题
2015-06-21 23:31
183 查看
#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;
}
#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;
}
相关文章推荐
- 2015062106 - 改编之后为何不过瘾
- 图书管理系统——测试与调试
- Uva - 1149 - Bin Packing
- Uva - 1149 - Bin Packing
- poj 1060 Modular multiplication of polynomials 除数是大数的高精度除法
- 团队作业-第5周-提交处-测试与调试 :
- 标准字符串和宽字符串处理函数
- STL中的常用算法
- leetcode-226-Invert Binary Tree
- 2015第25周日
- 测试
- 运行及总结
- Struts2(七)基于XML方式进行数据输入校验
- cmd下运行php脚本 不支持curl库的问题
- Servlet 初步(一)
- 土木/岩土期刊版面费/审稿费统计列表
- 我是chongjg
- <<出现问题的自绘组合框>>的分析和修正
- 说说那些光说不练的事
- 读后感