请问怎么实现这个程序的编写

img

img

img


请大家看一下这个问题,顺便帮我指出一下我这个代码哪错了,感谢大家🤧

用c++写的,我估计题目的目的不是让你写入文件。只是单纯的做一个系统


#include <iostream>
#include <Windows.h>
#include <vector>
using namespace std;

struct Person
{
    string name;
    int age;
    string number;
};

int main()
{
    vector<Person> res;
    int operation=3;
    SetConsoleOutputCP(CP_UTF8);

    while (true) {
        cout<<"--------------------手机通讯录--------------------"<<endl;
        cout<<"----------------请按下面的键盘进行操作--------------"<<endl;
        cout<<"1.查询联系人...."<<endl;
        cout<<"2.添加联系人....";
        cin>>operation;
        if(operation==1)
        {
            cout<<"输入要查询联系人的名字";
            string strName;
            cin>>strName;
            for(int i=0;i<res.size();++i)
            {
                Person person=res[i];
                if(person.name==strName)
                {
                    cout<<"名字:"<<person.name<<"年龄:"<<person.age<<"电话号码:"<<person.number<<endl;
                }
            }
        }
        else if(operation==2)
        {
            cout<<"请依次输入 名字,年龄 电话号码";
            Person person;
            cin>>person.name>>person.age>>person.number;
            if(res.size()<50)
            {
                res.push_back(person);
                cout<<"添加成功"<<endl;
            }
            else
            {
                cout<<"联系人已满"<<endl;
            }
        }
        else
        {
            cout<<"无效操作"<<endl;
        }
    }


    system("pause");
    return 0;
}

img