首页新闻找找看学习计划

C++新手(学生),一个程序百思不得其解,希望大佬能看下程序,指点指点,程序可以运行,但是case5无法执行

0
悬赏园豆:80 [已解决问题] 解决于 2018-04-22 23:49

//程序是写了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; }

c++
我叫张小凡的主页 我叫张小凡 | 初学一级 | 园豆:70
提问于:2018-04-22 22:38
< >
分享
最佳答案
0

不知道点击 插入代码 的么,乱作一团的内容

收获园豆:80
Arthurian | 小虾三级 |园豆:931 | 2018-04-22 22:59

我擦,这都可以拿到豆子。。。

TearsOfDawn | 园豆:34 (初学一级) | 2018-06-03 10:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册