代码如下:
#include
#include
using namespace std;
class Student {
public:
Student(int id, const string& name, int score) {
myId = id;
myName = name;
myScore = score;
classSize++;
totalScore += score;
averageScore = totalScore / classSize;
}
static int getNum() {
return classSize;
}
static int getAverage() {
return averageScore;
}
private:
int myId;
string myName;
int myScore;
static int classSize;
static int totalScore;
static int averageScore;
};
int Student::classSize = 0;
int Student::totalScore = 0;
int Student::averageScore = 0;
int main()
{
int id, score;
string name;
cin >> id >> name >> score;
Student stu1(id, name, score);
cin >> id >> name >> score;
Student stu2(id, name, score);
cin >> id >> name >> score;
Student stu3(id, name, score);
cin >> id >> name >> score;
Student stu4(id, name, score);
cout << Student::getNum() << " " << Student::getAverage() << endl;
system("pause");
return 0;
}
运行结果:
图片太模糊了,看不清楚。
兄弟东大的吧
老哥几班的2333