Describe CPPStudy_2005_1/STL������������_3_class here.
~cpp #include <fstream> #include <iostream> #include <string> #include <vector> #include <algorithm> //sort #include <numeric> //accumulate const int SUBJECT_NO = 4; using namespace std; class student_table { public: void readdata();//��������������� ������������ ������������ void printdata(); //������ void operation(); //������과 ���균 vector<student_table>::iterator zbegin() { return ztable.begin(); } vector<student_table>::iterator zend() { return ztable.end(); } double average() {return avg;} private: string name; vector<int> score; unsigned int total; double avg; vector<student_table> ztable; }; bool zcompare(student_table& x,student_table& y); //sort��� ���교 ����� int main() { student_table z; //��������� ���������. z.readdata(); //������과 ���균 z.operation(); //���균������ ������ sort(z.zbegin(),z.zend(),zcompare); //������ z.printdata(); return 0; } //��������������� ������������ ������������ void student_table::readdata(){ ifstream fin("data.txt"); student_table tmp; int tmp2,i; while(1) { fin >> tmp.name; for(i=1;i<=SUBJECT_NO;i++) { fin >> tmp2; tmp.score.push_back(tmp2); } if(fin.eof()) break; ztable.push_back(tmp); } } //sort��� ���교 ����� bool zcompare(student_table& x,student_table& y) { return x.average() > y.average(); } //���������기 void student_table::printdata() { int cnt=0; cout << "������\t국���\t������\t������\t과���\t������\t���균" << endl; for(vector<student_table>::iterator i=ztable.begin();i<ztable.end();++i) { cout << i->name << "\t" << i->score[cnt*4+0] << "\t" << i->score[cnt*4+1] << "\t" << i->score[cnt*4+2] << "\t" << i->score[cnt*4+3] << "\t" << i->total << "\t" << i->avg <<endl; cnt++; } } void student_table::operation() { for(vector<student_table>::iterator i=ztable.begin() ;i<ztable.end();++i) { i->total = accumulate(i->score.begin()+i->score.size()-4,i->score.end(),0); i->avg = i->total/4.0; } }