#include <iostream> #include <vector> using namespace std; #define list 1 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; } 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<<"请输入您的书籍名称:"<<endl; cin>>index.name; 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==3){ 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(_id==x[i].id){ cout<<"书籍:"<<x[i].name<<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].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].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 <<"*****4.返回*********"<<endl; int _n; cin>>_n; switch(n){ case 1:{ cout<<"请输入你要修改的书名:"; cin>>_name; x[i].name = _name; 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,图书 From: https://www.cnblogs.com/w6826301/p/18078131