//程序是写了3个文件的(1个.h两个.cpp),我就用空行分开啦 //studuent.h #ifndef Student_h #define Student_h #include #include using namespace std; class student { public: void getStudentNo(); void Update(string, string, string,string); friend istream& operator >>(istream&ci, student&); friend ostream&operator <<(ostream&co,student&); string display_name(student &); string display_num(student&); private: string num; string name; string sex; string adress; }; #endif //student.cpp #include #include #include"Student.h" using namespace std; istream& operator >>(istream&ci, student&s) { ci >> s.num >> s.name >> s.sex >> s.adress; return ci; } ostream&operator <<(ostream&co, student&s) { co << s.num << " " << s.name << " " << s.sex << " " << s.adress << endl; return co; } void student::getStudentNo() { cout << num; cout << " " << name << "" << sex << " " << adress; }; void student::Update(string nu,string n, string s, string a) { this->name=n; this->num = nu; this->sex = s; this->adress = a; cout << "的信息修改为:" << n << " " << s << " " << a << endl; }; string student::display_name(student &s) { return s.name; } string student::display_num(student &s) { return s.num; } // main.cpp #include #include #include #include"Student.h" using namespace std; list List1; list::iterator j; typedef listList3; List3 list3_name; List3 list3_num; List3::iterator k; int main() { student s; int choice = 0; string s_num; string s_name; string num1; string num2; while (choice != 7) { cout << "1:输出人数,2:全部输出,3:新增,4:修改,5:删除,6:按姓名排序,7:退出" << endl; cout << endl; cout << "输入您的操作:\n"; cin >> choice; switch (choice) { case 1: cout << List1.size()<<endl; break; case 2: for (j = List1.begin(); j!= List1.end(); j++) { cout << *j; } cout << endl; break; case 3: for (int k = 0; k < 2; k++) { cin >> s; s_name = s.display_name(s); s_num = s.display_num(s); List1.push_back(s); list3_name.push_back(s_name); list3_num.push_back(s_num); } break; case 4: cout << "请输入您要修改信息的学号:"; cin >> num2; for (j = List1.begin(); j != List1.end(); j++) { if ((*j).display_num(*j) == num2) { cout << "学号:" << num2; (*j).Update(num2,"zhanghao", "man", "shengli011"); cout << endl; } } break; case 5: cout << "请输入您要删除信息的学号:"; cin >> num1; for (j = List1.begin(); j!= List1.end(); j++) { if((*j).display_num(*j) == num1){ List1.erase(j); } } break; case 6: list3_name.sort(); for (k = list3_name.begin(); k != list3_name.end(); k++) { cout << (*k) << " "; } cout << endl; break; } } getchar(); return 0; }
不知道点击 插入代码 的么,乱作一团的内容
我擦,这都可以拿到豆子。。。