#include<iostream> #include<fstream> #include<string> #include<vector> using namespace std; class Student { ?? ?string name; ?? ?float score; public: ?? ?Student() {} ?? ?Student(string n, float sc) { ?? ??? ?name = n; ?? ??? ?score = sc; ?? ?} ?? ?float GetScore() { ?? ??? ?return score; ?? ?} ?? ?void Input() { ?? ??? ?cin >> name >> score; ?? ?} ?? ?void Output() { ?? ??? ?cout << endl << name << " " << score; ?? ?} ?? ?int compare(string name1) { ?? ??? ?if (name == name1) ?? ??? ??? ?return 1; ?? ??? ?else return 0; ?? ?} }; int main() { ?? ?string name; ?? ?Student student; ?? ?vector<Student>mys; ?? ?vector<Student>::iterator iter; ?? ?cout << "请输入学生的信息:" << endl; ?? ?student.Input(); ?? ?mys.push_back(student); ?? ?for (iter = mys.begin();iter<mys.end();iter++) ?? ??? ?(*iter).Output(); ?? ?cout << "输入要查找的姓名:" << endl; ?? ?cin >> name; ?? ?for (iter = mys.begin();iter<mys.end();iter++) ?? ??? ?if ((*iter).compare(name)) ?? ??? ??? ?cout <<(*iter).GetScore() << endl; ?? ?return 0; }
?
|