C++编程题-----类与对象练习题

第三题。。。求解答。谢啦。。。

第1个回答  2013-03-12
.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;
}本回答被提问者采纳
相似回答