#include <iostream> #include <vector> using namespace std; #define list 1000 struct a{ string name; int id; int age; string Class; }index; void MAIN(){ cout<<"欢迎使用学生管理系统"<<endl <<"1.新建学生信息"<<endl <<"2.查找学生信息"<<endl <<"3.修改学生信息"<<endl <<"4.删除学生信息"<<endl <<"5.退出管理系统"<<endl; } void FMAIN(){ cout<<"请选择您要查找的方式:"<<endl <<"1.根据学号查找"<<endl <<"2.根据姓名查找"<<endl <<"3.根据年龄查找"<<endl <<"4.根据班级查找"<<endl <<"5.返回主界面"<<endl; } void FFMAIN(string n){ cout<<"请选择您要"<<n<<"的方式:"<<endl <<"1.根据学号"<<n<<endl <<"2.返回"<<n<<endl; } vector<a> no1(vector<a> x,int number); vector<a> no2(vector<a> x,int number); vector<a> no3(vector<a> x,int number); vector<a> no4(vector<a> x,int number); int main(){ vector<a>x; int n,number = 0; while(1){ MAIN(); cin>>n; if(n>5){ system("cls"); continue; }else if(n==5){ system("pause"); break; } switch(n){ case 1: x = no1(x,number); number++; break;
#include <iostream> #include <vector> using namespace std; #define list 1000 struct a{ string name; int id; int age; string Class; }index; void MAIN(){ cout<<"欢迎使用学生管理系统"<<endl <<"1.新建学生信息"<<endl <<"2.查找学生信息"<<endl <<"3.修改学生信息"<<endl <<"4.删除学生信息"<<endl <<"5.退出管理系统"<<endl; } void FMAIN(){ cout<<"请选择您要查找的方式:"<<endl <<"1.根据学号查找"<<endl <<"2.根据姓名查找"<<endl <<"3.根据年龄查找"<<endl <<"4.根据班级查找"<<endl <<"5.返回主界面"<<endl; } void FFMAIN(string n){ cout<<"请选择您要"<<n<<"的方式:"<<endl <<"1.根据学号"<<n<<endl <<"2.返回"<<n<<endl; } vector<a> no1(vector<a> x,int number); vector<a> no2(vector<a> x,int number); vector<a> no3(vector<a> x,int number); vector<a> no4(vector<a> x,int number); int main(){ vector<a>x; int n,number = 0; while(1){ MAIN(); cin>>n; if(n>5){ system("cls"); continue; }else if(n==5){ system("pause"); break; } switch(n){ case 1: x = no1(x,number); number++; break; case 2: x = no2(x,number); break; case 3: x = no3(x,number); break; case 4: x = no4(x,number); break; case 5: system("pause"); return 0; } system("pause"); system("cls"); } return 0; } vector<a> no1(vector<a> x,int number){ cout<<"请输入你的姓名:"; cin>>index.name; cout<<"请输入你的年龄:"; cin>>index.age; cout<<"请输入你的班级:"; cin>>index.Class; index.id = list+number; cout<<"你的学号是:"<<index.id<<endl; x.push_back(index); return x; } vector<a> no2(vector<a> x,int number){ int n; while(1){ system("cls"); FMAIN(); cin>>n; if(n==5){ break; } int _id,_age; string _name,_class; bool have = false; switch(n){ case 1:{ cout<<"请输入你的学号:"; cin>>_id; for(int i = 0;i<x.size();i++){ /*if(x[i].id==-1){ cout<<"无法找到该学生信息"<<endl; return x;*/ /*}else */ if(_id==x[i].id){ cout<<"姓名:"<<x[i].name<<endl; cout<<"年龄:"<<x[i].age<<endl; cout<<"班级:"<<x[i].Class<<endl; have = true; } } if(!have){ cout<<"查找失败"<<endl; } break; } case 2:{ cout<<"请输入你的姓名:"; cin>>_name; for(int i = 0;i<x.size();i++){ if(_name==x[i].name || x[i].name.find(_name)!=string::npos){ cout<<"姓名:"<<x[i].name<<endl; cout<<"年龄:"<<x[i].age<<endl; cout<<"班级:"<<x[i].Class<<endl; cout<<"学号:"<<x[i].id<<endl; cout<<endl; have = true; } } if(!have){ cout<<"查找失败"<<endl; } break; } case 3:{ cout<<"请输入你的年龄:"; cin>>_age; for(int i = 0;i<x.size();i++){ if(_age==x[i].age){ cout<<"姓名:"<<x[i].name<<endl; cout<<"年龄:"<<x[i].age<<endl; cout<<"班级:"<<x[i].Class<<endl; cout<<"学号:"<<x[i].id<<endl; cout<<endl; have = true; } } if(!have){ cout<<"查找失败"<<endl; } break; } case 4:{ cout<<"请输入你的班级:"; cin>>_class; for(int i = 0;i<x.size();i++){ if(_class==x[i].Class){ cout<<"姓名:"<<x[i].name<<endl; cout<<"年龄:"<<x[i].age<<endl; cout<<"班级:"<<x[i].Class<<endl; cout<<"学号:"<<x[i].id<<endl; cout<<endl; have = true; } } if(!have){ cout<<"查找失败"<<endl; } break; } } system("pause"); } return x; } vector<a> no3(vector<a> x,int number){ int n; while(1){ system("cls"); FFMAIN("修改"); cin>>n; if(n==2){ break; } int _id,_age,_class; string _name; bool have = false; switch(n){ case 1: cout<<"请输入你的学号:"; cin>>_id; for(int i = 0;i<number;i++){ if(list+i==_id){ system("cls"); cout<<"请选择你要修改的信息"<<endl <<"*****1.修改姓名*****"<<endl <<"*****2.修改年龄*****"<<endl <<"*****3.修改班级*****"<<endl <<"*****4.返回*********"<<endl; int _n; cin>>_n; switch(n){ case 1:{ cout<<"请输入你要修改的姓名:"; cin>>_name; x[i].name = _name; break; } case 2:{ cout<<"请输入你要修改的年龄:"; cin>>_age; x[i].name = _age; break; } case 3:{ cout<<"请输入你要修改的班级:"; cin>>_class; x[i].name = _class; break; } case 4:{ break; } } have = true; } } if(!have){ cout<<"修改失败"<<endl; break; } cout<<"修改成功"<<endl; break; } system("pause"); } return x; } vector<a> no4(vector<a> x,int number){ int _id; cout<<"请输入你的学号:"; cin>>_id; bool have = false; for(int i = 0;i<number;i++){ if(_id==x[i].id){ x.erase(x.begin()+i); //x[i].id = -1; have = true; } } if(!have){ cout<<"删除失败"<<endl; return x; } cout<<"删除成功"<<endl; return x; }
case 2: x = no2(x,number); break; case 3: x = no3(x,number); break; case 4: x = no4(x,number); break; case 5: system("pause"); return 0; } system("pause"); system("cls"); } return 0; } vector<a> no1(vector<a> x,int number){ cout<<"请输入你的姓名:"; cin>>index.name; cout<<"请输入你的年龄:"; cin>>index.age; cout<<"请输入你的班级:"; cin>>index.Class; index.id = list+number; cout<<"你的学号是:"<<index.id<<endl; x.push_back(index); return x; } vector<a> no2(vector<a> x,int number){ int n; while(1){ system("cls"); FMAIN(); cin>>n; if(n==5){ break; } int _id,_age; string _name,_class; bool have = false; switch(n){ case 1:{ cout<<"请输入你的学号:"; cin>>_id; for(int i = 0;i<x.size();i++){ /*if(x[i].id==-1){ cout<<"无法找到该学生信息"<<endl; return x;*/ /*}else */ if(_id==x[i].id){ cout<<"姓名:"<<x[i].name<<endl; cout<<"年龄:"<<x[i].age<<endl; cout<<"班级:"<<x[i].Class<<endl; have = true; } } if(!have){ cout<<"查找失败"<<endl; } break; } case 2:{ cout<<"请输入你的姓名:"; cin>>_name; for(int i = 0;i<x.size();i++){ if(_name==x[i].name || x[i].name.find(_name)!=string::npos){ cout<<"姓名:"<<x[i].name<<endl; cout<<"年龄:"<<x[i].age<<endl; cout<<"班级:"<<x[i].Class<<endl; cout<<"学号:"<<x[i].id<<endl; cout<<endl; have = true; } } if(!have){ cout<<"查找失败"<<endl; } break; } case 3:{ cout<<"请输入你的年龄:"; cin>>_age; for(int i = 0;i<x.size();i++){ if(_age==x[i].age){ cout<<"姓名:"<<x[i].name<<endl; cout<<"年龄:"<<x[i].age<<endl; cout<<"班级:"<<x[i].Class<<endl; cout<<"学号:"<<x[i].id<<endl; cout<<endl; have = true; } } if(!have){ cout<<"查找失败"<<endl; } break; } case 4:{ cout<<"请输入你的班级:"; cin>>_class; for(int i = 0;i<x.size();i++){ if(_class==x[i].Class){ cout<<"姓名:"<<x[i].name<<endl; cout<<"年龄:"<<x[i].age<<endl; cout<<"班级:"<<x[i].Class<<endl; cout<<"学号:"<<x[i].id<<endl; cout<<endl; have = true; } } if(!have){ cout<<"查找失败"<<endl; } break; } } system("pause"); } return x; } vector<a> no3(vector<a> x,int number){ int n; while(1){ system("cls"); FFMAIN("修改"); cin>>n; if(n==2){ break; } int _id,_age,_class; string _name; bool have = false; switch(n){ case 1: cout<<"请输入你的学号:"; cin>>_id; for(int i = 0;i<number;i++){ if(list+i==_id){ system("cls"); cout<<"请选择你要修改的信息"<<endl <<"*****1.修改姓名*****"<<endl <<"*****2.修改年龄*****"<<endl <<"*****3.修改班级*****"<<endl <<"*****4.返回*********"<<endl; int _n; cin>>_n; switch(n){ case 1:{ cout<<"请输入你要修改的姓名:"; cin>>_name; x[i].name = _name; break; } case 2:{ cout<<"请输入你要修改的年龄:"; cin>>_age; x[i].name = _age; break; } case 3:{ cout<<"请输入你要修改的班级:"; cin>>_class; x[i].name = _class; break; } case 4:{ break; } } have = true; } } if(!have){ cout<<"修改失败"<<endl; break; } cout<<"修改成功"<<endl; break; } system("pause"); } return x; } vector<a> no4(vector<a> x,int number){ int _id; cout<<"请输入你的学号:"; cin>>_id; bool have = false; for(int i = 0;i<number;i++){ if(_id==x[i].id){ x.erase(x.begin()+i); //x[i].id = -1; have = true; } } if(!have){ cout<<"删除失败"<<endl; return x; } cout<<"删除成功"<<endl; return x; }
标签:case,容器,饭卡,cout,int,number,break,vector,3.0 From: https://www.cnblogs.com/w6826301/p/17935614.html