帮忙看一下这个C++程序里哪里出错了(生成是成功的,但无法运行),谢谢各位指点

2024-12-31 15:29:42
推荐回答(1个)
回答1:

#include
using namespace std;
class Student
{
public:
Student();//添加个默认构造函数
double score;
static double total;
static int count;

void scoretotalcount(double);
static double sum();
static double average();
};

double Student::total=0;
int Student::count=0;
Student::Student()//score初始化为0
{
score=0;
}
void Student::scoretotalcount(double s)
{
score=s;
total=total+score;
count++;
}
double Student::sum ()
{
return total;
}
double Student::average ()
{
return total/count;
}

int main()
{
double s;
Student Std;
while (1) //你原来的输入最后一次负数时还被计算
{
cout<<"student_"< cin>>s; //当score<0时停止输入,跳出循环
if (s<0)
break;
Std.scoretotalcount(s);
cout< }
cout<