设计包含静态数据成员的Student类 |
您所在的位置:网站首页 › 计算平均分和总成绩的函数 › 设计包含静态数据成员的Student类 |
设计包含静态数据成员的Student类,在该类定义中包括: 数据成员:学号,年龄,分数score,及静态数据成员学生人数count; 定义成员函数用于设置和读取及显示学号,年龄,分数,累计学生人数;静态成员函数getCount( ) 用于返回总人数;外部函数average()用于求平均值。 在main函数中,输入某班同学的成绩,并调用上述函数求全班学生的平均分。
#include using namespace std; class Student { private: int num; int age; float score; static int count; public: Student(){count++; } Student(int n,int a,float s) { num=n;age=a;score=s; count++; } void setStud(int n,int a,float s) { num=n;age=a;score=s; } void dispStud() { cout |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |