#include <iostream.h>
#include <string>
using namespace std;
class student
{
private:
string no;
string name;
float deg1;
float deg2;
float deg3;
static float sum1,sum2,sum3;
static int num;
public:
student(string no,string name,float deg1,float deg2,float deg3)
{
this->no = no;
this->name = name;
this->deg1 = deg1;
this->deg2 = deg2;
this->deg3 = deg3;
sum1+=this->deg1;
sum2+=this->deg2;
sum3+=this->deg3;
num+=1;
}
float avg1()
{
return sum1/num;
}
float avg2()
{
return sum2/num;
}
float avg3()
{
return sum3/num;
}
void disp()
{
cout<<name<<endl;-------------------------------------------->>???这处不明白呀?
cout<<"语文总成绩:"<<sum1<<endl;
cout<<"数学总成绩:"<<sum2<<endl;
cout<<"英语总成绩:"<<sum3<<endl;
}
};
float student::sum1 = 0;
float student::sum2 = 0;
float student::sum3 = 0;
int student::num = 0;
void main()
{
student s[5]={student("11","Li ming",76,83,77),student("12","Wang Tao",74.5,87,67.5),
student("8","Sun Yue",79,89,68.5),student("21","li Lei",73,87,69),
student("9","xiao ming",77.5,86.5,87)}; //对象数组的使用!
cout<<"语文平均分:"<<s[1].avg1()<<endl;
cout<<"数学平均分:"<<s[1].avg2()<<endl;
cout<<"英语平均分:"<<s[1].avg3()<<endl;
s[1].disp();
}