#include<iostream>
using namespace std;
class Croster
{
private:
string name;
int Math;
static const double Score;
double GPA;
public:
Croster(string na = "undef", int m = 0, int s = 3);
double GetGPA();
void Display()const;
};
//常数据成员的初始化只能在构造函数的初始化列表中进行
Croster::Croster(string na, int m, int s)//:Score(s)
{
name = na;
Math = m;
}
double Croster::GetGPA()
{
GPA = Math / 100.0 * Score;
return GPA;
}
void Croster::Display() const
{
cout << name << " get " << Math << endl;
cout << "Your GPA is>>>" << GPA << endl;
}
//在类外初始化
const double Croster::Score = 3.0;
int main()
{
Croster stu_a("Steve", 95);
stu_a.GetGPA();
stu_a.Display();
return 0;
}