展开全部
.h
class Student
{
private:
double score;
static double total;
static int count;
public:
static double sum();
static double average();
int scoretotalcount(double s);
}
.cpp
static double Student::sum()
{
return total;
}
static double Student::average()
{
return total / count;
}
int Student::scoretotalcount(double s)
{
score = s;
total += s;
count++;
return count;
}
main
void main()
{
int nCount = 0;
Student stu;
for(int i = 0; i < 10; i++)
nCount = stu.scoretotalcount( i + 10.3);
cout << "sum = "<< stu.sum()<<endl;
cout<<"nCount = "<< nCount <<endl;
cout<<"average = "<< stu.average()<<endl;
}
class Student
{
private:
double score;
static double total;
static int count;
public:
static double sum();
static double average();
int scoretotalcount(double s);
}
.cpp
static double Student::sum()
{
return total;
}
static double Student::average()
{
return total / count;
}
int Student::scoretotalcount(double s)
{
score = s;
total += s;
count++;
return count;
}
main
void main()
{
int nCount = 0;
Student stu;
for(int i = 0; i < 10; i++)
nCount = stu.scoretotalcount( i + 10.3);
cout << "sum = "<< stu.sum()<<endl;
cout<<"nCount = "<< nCount <<endl;
cout<<"average = "<< stu.average()<<endl;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询