#include <the iostream> the 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 art void the addPerson (AddressBooks *ABS) { // determines whether the full address book, it is no longer added full IF (ABS-> == m_size MAX) { COUT << " Phonebook Full " << endl; } the else { String name; int Sex ; int Age; String Phone; String address; cout << " Please enter your name: " ; cin >> name; the while ( to true ) { cout << "Please enter the gender (0 for male, 1 for female): " ; cin >> Sex; IF (Sex == 0 || Sex == 1 ) { BREAK ; } the else { cout << " you entered is incorrect. Please re input! " << endl; } } cout << " Please enter the age: " ; cin >> Age; cout << " Please enter the phone: " ; cin > phone; cout << "请输入地址:"; 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 << "添加成功!" << 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 << " current record is empty " << endl; } the 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 return -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 << "删除成功"<<endl; }else{ cout << "查无此人"<<endl; } system("pause"); system("cls"); } //菜单界面 void showMenu() { cout << "************************" << endl; cost<< " ***** 1. Add contacts ***** " << endl; COUT << " ***** 2. Show contacts ***** " << endl; COUT << " ***** 3. delete contact ***** " << endl; cout << " ***** 4. modify contact ***** " << endl; cout << " * 5. Find contact **** ***** " << endl; COUT << " ***** 6. The empty contacts ***** " << endl; cout << "***** 0. Exit contacts ***** " << endl; cout << " ************************ " < < endl; } int main () { // Create a contact structure variables AddressBooks ABS; abs.m_size = 0 ; int SELECT = 0 ; the while ( to true ) { showMenu is (); COUT << " Please enter the appropriate option: " << endl; cin >> the 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 BREAK ; Case 6 : // Clear BREAK ; Case 0 : // Exit cout << " Welcome to the next use " << endl; System ( " PAUSE " ); return 0 ; BREAK ; } } }
To delete a contact address book management systems function c ++ examples of (D)
Guess you like
Origin www.cnblogs.com/xiximayou/p/12083674.html
Recommended
Ranking