Find a contact address book management system function of c ++ examples of the (five)

#include<iostream>
using namespace std;
constexpr auto MAX = 1000;

// contact structure 
struct the Person
{
    string m_name;
    int m_sex;
    int m_age;
    string m_phone;
    string m_address;

};
// contacts structure 
struct AddressBooks
{
    // contact array 
    struct the Person personArray [MAX];
     // record the number of contacts 
    int m_size;
};

// Add people 
void the addPerson (AddressBooks * ABS) {
     // determines whether the full address book, it is no longer added full 
    IF (ABS-> == m_size MAX) {
        cout << " address book is full " << endl;
    }
    else{
        string name;
        int sex;
        int age;
        string phone;
        string address;
        cout << " Please enter your name: " ;
        cin >> name;
        while (true) {
            cout << " Please enter the gender (0 for male, 1 for female): " ;
            cin >> sex;
            if (sex == 0 || sex == 1) {
                break;
            }else{
                cout << " you entered is incorrect, please re-enter! " << endl;
            }
        }
        cout << " Please enter the Age: " ;
        cin >> age;
        cout << " Please enter the phone: " ;
        cin >> phone;
        cout << " Please enter the address: " ;
        cin >> address;
        abs->personArray[abs->m_size].m_name = name;
        abs->personArray[abs->m_size].m_sex = sex;
        abs->personArray[abs->m_size].m_age = age;
        abs->personArray[abs->m_size].m_phone = phone;
        abs->personArray[abs->m_size].m_address = address;
        abs->m_size++;
        cout << " Add success! " << endl;
         // Press any key to continue 
        System ( " PAUSE " );
         // clear screen 
        System ( " CLS " );
    }
}
// display a contact 
void showPerson (AddressBooks * ABS) {
     IF (ABS-> m_size == 0 ) {
        cout << " The current record is empty " << endl;
    }else {
        for (int i = 0; i < abs->m_size; i++) {
            cout << "姓名:" << abs->personArray[i].m_name << "\t"
                << "性别:" << (abs->personArray[i].m_sex == 0 ? "" : "") << "\t"
                << "年龄:" << abs->personArray[i].m_age << "\t"
                << "电话:" << abs->personArray[i].m_phone << "\t"
                << "地址:" << abs->personArray[i].m_address << endl;
        }
    }
    system("pause");
    system("cls");
}
// determines whether there is contact, if there is, where the index is returned, otherwise -1 
int ISEXIST (AddressBooks * ABS, String name) {
     for ( int I = 0 ; I <ABS-> m_size; I ++ )
    {
        if (abs->personArray[i].m_name == name) {
            return i;
        }
    }
    return -1;
}

// true deletion 
void del (ABS AddressBooks *, int ID) {
     for ( int I = ID; I <ABS-> m_size; I ++ )
    {
        abs->personArray[i] = abs->personArray[i + 1];
    }
    abs->m_size--;
}

// Find and remove 
void deletePerson (AddressBooks * ABS) {
     String name;
    cout << " Please enter the name you want to delete: " ;
    cin >> name;
    int tmp;
    tmp = isExist(abs, name);
    if (tmp != -1){
        del(abs, tmp);
        cout << " deleted successfully " << endl;
    }else{
        cout << " no such person " << endl;
    }
    system("pause");
    system("cls");
}

// display unit personal information 
void showPerson (ABS AddressBooks *, int I) {
    cout << "姓名:" << abs->personArray[i].m_name << "\t"
        << "性别:" << (abs->personArray[i].m_sex == 0 ? "" : "") << "\t"
        << "年龄:" << abs->personArray[i].m_age << "\t"
        << "电话:" << abs->personArray[i].m_phone << "\t"
        << "地址:" << abs->personArray[i].m_address << endl;
}

// to find information and return the corresponding 
void the FindPerson (AddressBooks * ABS) {
     String name;
    cout << " Please enter the name you want to find: " ;
    cin >> name;
    int tmp;
    tmp = isExist(abs, name);
    if (tmp != -1) {
        cout << " to find the person " << endl;
        showPerson(abs, tmp);
    }
    else {
        cout << " no such person " << endl;
    }
    system("pause");
    system("cls");
}

// menu interface 
void showMenu is () {
    cout << "************************" << endl;
    cout << " ***** 1. To add a contact ***** " << endl;
    cout << " ***** 2. Show contacts ***** " << endl;
    cout << " ***** 3. Delete Contact ***** " << endl;
    COUT << " ***** 4. Edit contact ***** " << endl;
    cout << " ***** 5. Find a contact ***** " << endl;
    cout << " ***** 6. Empty Contact ***** " << endl;
    cout << " ***** 0. Exit contacts ***** " << endl;
    cout << "************************" << endl;
}

int main () {
     // Create a contact structure variables 
    AddressBooks abs;
    abs.m_size = 0;
    int select = 0;
    while(true){
        showMenu();
        cout << " Please enter the appropriate option: " << endl;
        CIN >> SELECT ;
         Switch ( SELECT ) {
         Case  . 1 : // Add 
            the addPerson (& ABS);
             BREAK ;
         Case  2 : // display 
            showPerson (& ABS);
             BREAK ;
         Case  . 3 : // Delete 
            deletePerson (& ABS);
             BREAK ;
         Case  . 4 : // modify 
            BREAK ;
         Case 5 : // Find 
            the FindPerson (& ABS);
             BREAK ;
         Case  6 : // Clear 
            BREAK ;
         Case  0 : // Exit 
            cout << " Welcome to the next use " << endl;
            system("pause");
            return 0;
            break;
        }
    }
}

Guess you like

Origin www.cnblogs.com/xiximayou/p/12083793.html