问题描述
- 大家帮忙看看哪里不对,怎么改???
-
#include
#include
using namespace std;
class Student
{public:
Student(int n,string na,double d)
{
no=n;
name=na;
deg=d;
sum+=d;
num++;
}
static double avg()
{
return sum/num;
}
static int total()
{
return num;
}
void disp()
{
cout<<no<<" "<<name<<" "<<deg<<endl;
}
private:
int no;
string name;
static double sum;
static int num;
};
double Student::sum=0;
int Student::num=0;
int main()
{
Student s1(1001,"li", 97), s2(1002,"tian",96), s3(1003,"chen", 90);
cout<<"学号 姓名 成绩"<<endl;
s1.disp();
s2.disp();
s3.disp();
cout<<"学生人数="<<Student::total()<<endl;
cout<<"平均成绩="<<Student::avg();
return 0;}
解决方案
deg这个变量没有定义吧你。
private:
int no;
string name;
double deg;
static double sum;
static int num;
解决方案二:
谢谢,已经改过来了,初学C++,不太会呢
时间: 2024-11-02 00:16:28