其中姓名定义为长度为18的字符数组,其它数据成员类型为整型,数学总成绩、英语总成绩和人数为静态数据成员,函数成员包括构造函数、显示基本数据函数(ShowBase)和显示静态数据函数(ShowStatic),其中构造函数由已知参数姓名(nm)、学号(nu)、数学成绩(math)和英语成绩(english)构造对象,显示基本数据函数用于显示学生的姓名、学号、数学成绩、英语成绩,显示静态数据函数为静态成员函数,用于显示人数,数学总成绩,英语总成绩;要求所有数据成员为private访问权限,所有成员函数为public访问权限,在主函数中定义若干个学生对象,分别显示学生基本信息,以及显示学生人数,数学总成绩与英语总成绩。
#include"iostream"
using namespace std;
class student
{
private:
char name[18];
int num;
int mathScore;
int englishScore;
static int count;
static int mathTotalScore;
static int englishTotalScore;
public:
student(char *nm,int nu,int math,int english):num(nu),mathScore(math),englishScore(english){
strcpy(name,nm);
count++;
mathTotalScore+=mathScore;
englishTotalScore+=englishScore;
}
void bshow()
{
cout << name << " " << num <<