BIG阳
#include<iostream>#include<string>using namespace std;const int length=3;class Student{ int age; int Math; int Eng; int Chn; string name; string sex;public: Student(int age,int Math,int Eng,const string sex) { this->age=age; this->Math=Math; this->Eng=Eng; this->sex=sex; } Student() { } void SetInfo(int age ,string sex,string name,int math,int eng,int chn) { this->age=age; this->sex=sex; this->name=name; this->Math=math; this->Chn=chn; this->Eng=eng; } string GetName(){ return name;} string GetSex(){return sex;} int GetAge(){return age;} int GetMath(){return Math;} int GetEng(){return Eng;} int GetChn(){return Chn;}};class Compute{ Student s[length]; double sum_math; double sum_eng; double sum_chn;public: Compute(double a=0,int b=0,int c=0):sum_math(a),sum_eng(b),sum_chn(c) { Set(); GetAverage(); } void Set() { s[0].SetInfo(10,"F","ABC",87,88,89); s[1].SetInfo(20,"M","CDE",78,89,99); s[2].SetInfo(25,"F","QWE",69,89,94); } void GetAverage() { //double sum_math=0,sum_eng=0,sum_chn=0, for(int i=0;i<length;i++) { sum_math+=s[i].GetMath(); sum_eng+=s[i].GetEng(); sum_chn+=s[i].GetChn(); } } double MathAve(){return (sum_math/length);} double ChnAve(){return (sum_chn/length);} double EngAve(){return (sum_eng/length);} void Show();};void Compute::Show(){ cout<<"name\t"<<"sex\t"<<"age\t"<<"chinese\t"<<"math\t"<<"Eng"<<endl; for(int i=0;i<length;i++) { cout<<s[i].GetName()<<"\t"<<s[i].GetSex()<<"\t"<<s[i].GetAge()<<"\t"<<s[i].GetChn()<<"\t"; cout<<s[i].GetMath()<<"\t"<<s[i].GetEng()<<endl; }}int main(){ Compute obj; obj.Set(); obj.Show(); cout.precision(5); cout<<"chn average is:"<<obj.ChnAve()<<endl; cout<<"eng average is:"<<obj.EngAve()<<endl; cout<<"math average is:"<<obj.MathAve()<<endl; return 0;}