通讯录管理系统,无限添加联系人的通讯录,无限添加联系人这个类的对象实现无限添加联系人,通讯录容器,通讯录管理系统

#include
#include
#include
using namespace std;
void menu()
{
    cout << "     FunctionMenu" << endl;
    cout << "\t0:exit" << endl;
    cout << "\t1:add" << endl;
    cout << "\t2:display" << endl;
    cout << "\t3:delete" << endl;
    cout << "\t4:find" << endl;
    cout << "\t5:modify" << endl;
    cout << "\t6:clear" << endl;
    cout << "please select the function" << endl << endl;
}

class Person
{
public:
    string name, phone, address, sex;
    int age=0;
};
class Contact
{
public:
    vector personarray;
    int personsize=0;
};

vector t;

void addPerson(Contact& a)
{
    Person p;                       //if(p->personsize==max){cout<<"Full"<> name;
    cout << "enter phone" << endl;
    cin >> phone;
    cout << "enter address" << endl;
    cin >> address;
    cout << "enter sex" << endl;
    while (1)
    {
        cin >> sex;
        if (sex != "male" && sex != "female")
            cout << "alien sex"<> age;

    p.name = name;
    p.phone = phone;
    p.address = address;
    p.sex = sex;
    p.age = age;                            //p->personarray[p->personsize].age=age         

    a.personarray.push_back(p);          //p->personarray[p->personsize].name=name;          a.personarray[i]
    a.personsize = a.personarray.size();
    cout << "successfully add, and now there is " << a.personsize << " people in contact."<> name;
    cout << "enter the phone of people that you'd like to delete:" << endl;
    cin >> phone;
    if (checkPerson(a, name, phone) == -1)
    {
        cout << "there is no one named " << name << " with a number of '" << phone << "' in contact." << endl<::iterator t=(a.personarray.begin()+i);
        a.personarray.erase(t,t+1);
        a.personsize = a.personarray.size();
        cout << "Now, there is " << a.personsize << " people in contact." << endl<> name;
    findP(a, name);
    if (t.empty())
    {
        cout << "there is no one named " << name << " in contact." << endl << endl;
    }
    else
    {
        cout << "OK, there is such " << t.size() << " person that you want to find whose information is below : " << endl<> name;
    findP(a, name);
    if (t.empty())
    {
        cout << "there is no one named " << name << " in contact." << endl << endl;
    }
    else
    {
        cout << "OK, there is such " << t.size() << " person that you want to modify whose information is below : " << endl << endl;
        for (decltype(t.size()) i = 0; i != t.size(); i++)
        {
            cout << "the information of " << i << "th person named " << name << " is :" << endl;
            cout << "name: " << a.personarray[i].name << "\t";
            cout << "sex: " << a.personarray[i].sex << "\t";
            cout << "age: " << a.personarray[i].age << "\t";
            cout << "phone: " << a.personarray[i].phone << "\t";
            cout << "address: " << a.personarray[i].address << endl << endl;
        }
        cout << "Now, which one named " << name << " you'd like to modify? Please enter name and phone to match." << endl;
        while (1)
        {
            cout << "enter the name of people that you'd like to modify:" << endl;
            cin >> name;
            cout << "enter the phone of people that you'd like to modify:" << endl;
            cin >> phone;
            auto i = checkPerson(a, name, phone);
            if (checkPerson(a, name, phone) == -1)
            {
                cout << "there is no one named " << name << " with a number of '" << phone << "' in contact." << endl << endl;
            }
            else
            {
                cout << "OK, there is such a person. Please enter new information of that person" << endl << endl;
                cout << "enter new name" << endl;
                cin >> name;
                cout << "enter new phone" << endl;
                cin >> phone;
                cout << "enter new address" << endl;
                cin >> address;
                cout << "enter new sex" << endl;
                while (1)
                {
                    cin >> sex;
                    if (sex != "male" && sex != "female")
                        cout << "alien sex" << endl << "please enter again" << endl;
                    else break;
                }
                cout << "enter age" << endl;
                cin >> age;

                a.personarray[i].name = name;
                a.personarray[i].phone = phone;
                a.personarray[i].address = address;
                a.personarray[i].sex = sex;
                a.personarray[i].age = age;
                cout << "successfully modify the information of " << name << endl << endl;
                break;
            }
        }
    }
    system("pause");
    system("cls");
}
void clearPerson(Contact& a)
{
    string confirm;
    cout << "are you serious to clear all out? please enter yes or no to confirm." << endl;
    while (1)
    {
        cin >> confirm;
        if (confirm == "yes")
        {
            a.personarray.clear();                      //a->personsize=0(数组情况)
            a.personsize = a.personarray.size();
            cout << "successfully clear all out." << endl << endl;
            break;
        }
        else if (confirm == "no")
        {
            cout << "successfully prevent clearing all." << endl << endl;
            break;
        }
        else
        {
            cout << "illeague input, please enter yes or no, enter again: " << endl << endl;
            continue;
        }
    }
    system("pause");
    system("cls");
}

int main()
{
    Contact c;
    int select = 0;
    while (1)
    {
        menu();
        cin >> select;
        switch (select)
        {
        case 0:
            cout << "successfully exit" <

 

 

你可能感兴趣的:(c++,开发语言,数据结构)