饭卡(容器)2.0

发布时间 2023-12-29 19:04:07作者: 爱吃泡面的皮卡
#include<iostream>
#include<vector>
#include<windows.h>
using namespace std;
    int a=999;
    int b=0;
    bool c=false;
    struct student{
    string name;    
    int age;
    int card;
    int grade;
    }s;
    void ka(){
    cout<<"学生管理系统:"<<endl;
    cout<<"1.新建学生信息"<<endl;
    cout<<"2.查找学生信息"<<endl;
    cout<<"3.修改学生信息"<<endl;
    cout<<"4.删除学生信息"<<endl;
    cout<<"5.退出系统"<<endl;
    }
    vector<student> insert(vector<student> v){
    cout<<"请输入学生姓名:";
    cin>>s.name;
    cout<<"请输入学生年龄:";
    cin>>s.age;
    cout<<"请输入学生年级:";
    cin>>s.grade;
    cout<<"你的学号是:";
    a++;
    s.card=a;
    cout<<s.card;
    v.push_back(s);
    Sleep(500);
    return v;
    }
    vector<student> find(vector<student> v){
    while(1){
        cout<<"你要用什么形式查找:"<<endl;
        cout<<"1.学生卡号"<<endl;
        cout<<"2.学生年龄"<<endl;
        cout<<"3.学生姓名"<<endl;
        cout<<"4.退出"<<endl;
        cin>>b;
        if(b==4){
        break;
        }
        switch(b){
        case 1:{
        cin>>b;
        for(int i=0;i<v.size();i++){
        if(v[i].card==b){
        cout<<"学生姓名:";
        cout<<v[i].name<<endl;
        cout<<"请输入学生年龄:";
        cout<<v[i].age<<endl;
        cout<<"请输入学生年级:";
        cout<<v[i].grade<<endl;
        Sleep(2000);
        c=true;
        }
        }
        if(c==false){
        cout<<"没找到";
        Sleep(500);
        }
        break;
        }
        case 2:{
        cin>>b;
        for(int i=0;i<v.size();i++){
        if(v[i].age==b){
        cout<<"学生姓名:";
        cout<<v[i].name<<endl;
        cout<<"请输入学生年龄:";
        cout<<v[i].age<<endl;
        cout<<"请输入学生年级:";
        cout<<v[i].grade<<endl;
        Sleep(2000);
        c=true;
        }
        }
        if(c==false){
        cout<<"没找到";
        Sleep(500);
        }
        break;
        }
        case 3:{
        string d;
        cin>>d;
        for(int i=0;i<v.size();i++){
        if(v[i].name.find(d)!=string::npos){
        cout<<"学生姓名:";
        cout<<v[i].name<<endl;
        cout<<"请输入学生年龄:";
        cout<<v[i].age<<endl;
        cout<<"请输入学生年级:";
        cout<<v[i].grade<<endl;
        Sleep(2000);
        c=true;
        }
        }
        if(c==false){
        cout<<"没找到";
        Sleep(500);
        }
        break;
        }
        
        default :{
        
        break;
        }
        }
        system("cls");
        }
        
        return v;
        }
        vector<student> change(vector<student> v){
        
        for(int i=0;i<v.size();i++){
        if(v[i].card==b){
        while(1){
        c=true;
        cout<<"你要修改什么:"<<endl;
        cout<<"1.学生姓名"<<endl;
        cout<<"2.学生年龄"<<endl;
        cout<<"3.学生年级"<<endl;
        cout<<"4.退出"<<endl;
        cin>>b;
        if(b==4){
        break;
        }
        switch(b){
        case 1:{
        cout<<v[i].name<<endl;
        cin>>v[i].name;
        break;
        }
        case 2:{
        cout<<v[i].age<<endl;
        cin>>v[i].age;
        break;
        }
        case 3:{
        cout<<v[i].grade<<endl;
        cin>>v[i].grade;
        break;
        }
        default:{
        break;
        }
        }
        system("cls");
        }
        
        }
        }
        if(c==false){
        cout<<"没找到";
        Sleep(500);
        }
        
        
        return v;
        }
        int main(){
        vector<student> v;
        while(1){
        ka();
        int n;
        cin>>n;
        if(n==5){
        break;
        }
        switch(n){
        case 1:{
        v=insert(v);
        break;
        }
        case 2:{
        find(v);
        break;
        }
        case 3:{
        cout<<"请输入学生卡号:";
        cin>>b;
        change(v);
        break;
        }
        case 4:{
        
        break;
        }
        default:{
        break;
        }
        }
        system("cls");
        }
        
        return 0;
        
        }