大家看下这个程序,运行结果不对
#include<iostream>using namespace std;
class Student
{
public:
float score;
static float total;
static float count;
scoretotalcount(float = 0.0);
static float sum();
static float average();
fun(float = 0.0);
};
float Student::total = 0.0;
float Student::count = 0.0;
Student::fun(float c)
{
count = c;
}
Student::scoretotalcount(float s)
{
score = s;
total = total + score;
}
float Student::sum()
{
return total;
}
float Student::average()
{
return total / count;
}
int main()
{
Student p;
int i;
p.fun(2.0);
for (i = 0; i<2; i++)
{
float t;
cin >> t;
p.scoretotalcount(t);
}
cout << p.sum << endl;
cout << p.average << endl;
return 0;
}