数据成员:score (分数), total(总分),count(学生人数);
成员函数:scoretotalcount(double s)用于设置分数、求总分和累计学生人数
Sum() 用于返回总分;
Average()用于求平均值。
在main()函数中,输入某班同学的成绩,并调用上述函数求全班学生的总分和平均分。
定义一个student类,在该类定义中包括以下数据成员和成员函数:
答案:3 悬赏:30
解决时间 2021-03-20 23:11
- 提问者网友:夜微涼
- 2021-03-20 18:11
最佳答案
- 二级知识专家网友:许你一世温柔
- 2021-03-20 18:50
struct student
{
float score;
float total;
int count;
}stu1,stu2;
利用结构体……就很简单哟!
{
float score;
float total;
int count;
}stu1,stu2;
利用结构体……就很简单哟!
全部回答
- 1楼网友:高冷不撩人
- 2021-03-20 21:48
class student
{
private:
double* score;
double total;
int count;
protected:
~student();
public:
student();
void scoretotalcount(double s);
void Sum(double &total);
void Average(double &avg);
};
student::student()
{
count = 1;
score = new double[count]{0};
for(int i = 0;i < count;i++)
*(score+i) = 0;
total = 0;
}
student::~student()
{
if(score != null)
delete [] score;
}
void student::scoretotalcount(double s);
{
for(int i = 0;i<count;i++)
{
*(score+i) = s;
total += s;
}
}
void student::Sum(double &total)
{
total = this->total;
}
void student::Average(double &avg)
{
if(count)
avg = total/count;
}
- 2楼网友:爱情是怎么炼成的
- 2021-03-20 20:14
class student
{
public:
static int getnumber() { return number; }
student() {}
private:
static int number;
};
// 初始化静态成员
int student::number = 0;
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯