The address book management system is a dark horse programmer C++ Exercises for the next stage of the course , This address book only uses C/C++ Basic syntax to add address book through prompt , see , delete , lookup , Modify contacts and empty contacts , Very simple . Suitable for C/C++ Consolidation of basic knowledge .

Here is the code slice :
#include<iostream> #include<string> using namespace std; #define MAX 100
// Maximum number of contacts void showMenu(); void addPerson(struct addressList* adl); void
showLinkman(struct addressList* adl); int isExist(struct addressList* adl,
string name); void deleteLinkman(struct addressList* adl); void findLinkman(
struct addressList* adl); void modifyLinkman(struct addressList* adl); void
cleanList(struct addressList* adl); // Contact structure struct linkman { string Name; // full name
int Sex; // Gender 1 Representative male 2 Representative female int Age; // Age string PhoneNum;// Telephone number }; // Address book structure struct
addressList{ struct linkman linkmanArray[MAX]; // Contact array int list_Size = 0;
// Number of existing contacts }; int main() { addressList adl; while (1) { showMenu(); cout <<
" Please enter the action you want to perform : "; int choice = -1; cin >> choice; switch (choice) { case 1:
//1. Add a Contact addPerson(&adl); break; case 2: //2. Show contacts showLinkman(&adl); break;
case 3: //3. Delete Contact deleteLinkman(&adl); break; case 4: //4. find contact findLinkman(&adl
); break; case 5: //5. Modify contact modifyLinkman(&adl); break; case 6: //6. Empty contacts
cleanList(&adl); break; case 0: //0. Exit the system system("pause"); return 0; break;
default: cout << " illegal input , Please re-enter !!" << endl; break; } system("pause"); system("cls"
); } system("pause"); return 0; } // Real operation menu information void showMenu(){ cout <<
"==========================" << endl; cout << "----- 1. Add a Contact -----" << endl;
cout<< "----- 2. Show contacts -----" << endl; cout << "----- 3. Delete Contact -----" << endl;
cout<< "----- 4. find contact -----" << endl; cout << "----- 5. Modify contact -----" << endl;
cout<< "----- 6. Empty contacts -----" << endl; cout << "----- 0. Exit the system -----" << endl; cout
<< "==========================" << endl; } // Add a Contact void addPerson(struct
addressList* adl) { if (adl->list_Size < MAX) { cout << " Please enter contact name :"; cin >> adl
->linkmanArray[adl->list_Size].Name; int sex = -1; cout << "1 - male , 2 - female "; cout
<< "\n Please enter contact gender :"; while (sex != 1 && sex != 2) { // If the input is not 1 or 2, Then re-enter cin >> sex; if
(sex == 1 || sex == 2) { adl->linkmanArray[adl->list_Size].Sex = sex; } else {
cout<< " Illegal input , Please re-enter !" << endl; } } cout << "\n Please enter contact age :"; cin >> adl->
linkmanArray[adl->list_Size].Age; cout << "\n Please enter the contact phone number :"; cin >> adl->
linkmanArray[adl->list_Size].PhoneNum; cout << "\n New contact added successfully !!" << endl; adl->
list_Size++; } else { cout << " The address book is full , Unable to add new contact ." << endl; } } // show address book void
showLinkman(struct addressList* adl) { if (adl->list_Size != 0) { for (int i = 0
; i < adl->list_Size; i++) { cout << "\t full name :" << adl->linkmanArray[i].Name <<
"\t\t Gender :" << (adl->linkmanArray[i].Sex == 1 ? " male " : " female ") << "\t\t Age :"<<adl->
linkmanArray[i].Age << "\t\t Telephone number :" << adl->linkmanArray[i].PhoneNum<<endl; } }
else { cout << " Address book is empty !" << endl; } } // Determine whether a name exists in the address book int isExist(struct
addressList* adl, string name) { int flag = -1; for (int i = 0; i < adl->
list_Size;i++) { if (name == adl->linkmanArray[i].Name) { cout << "\t full name :" << adl
->linkmanArray[i].Name << "\t\t Gender :" << (adl->linkmanArray[i].Sex == 1 ? " male " :
" female ") << "\t\t Age :" << adl->linkmanArray[i].Age << "\t\t Telephone number :" << adl->
linkmanArray[i].PhoneNum << endl; flag = 1; } } return flag; } // Delete Contact void
deleteLinkman(struct addressList* adl) { string name; cout << " Please enter the contact name to delete :" <<
endl; cin >> name; int ret = isExist(adl, name); if (ret == 1) { for (int i = 0
; i < adl->list_Size; i++) { if (adl->linkmanArray[i].Name == name) { for (int j
= i; j < adl->list_Size; j++) { adl->linkmanArray[j] = adl->linkmanArray[j + 1];
} adl->list_Size--; cout << " delete "<<name<<" success " << endl; } } } else { cout <<
" Does not exist with name - " << name << " - Contact for !" << endl; } } // find contact void findLinkman(struct
addressList* adl) { string name; cout << " Please enter the name of the contact you want to find :" << endl; cin >> name;
int ret = isExist(adl, name); if (ret == 1) { for (int i = 0; i < adl->list_Size
; i++) { if (adl->linkmanArray[i].Name == name) { cout << " Search complete !" << endl; } } }
else { cout << " Does not exist with name - " << name << " - Contact for !" << endl; } } // Modify contact information void
modifyLinkman(struct addressList* adl) { string name; cout << " Please enter the name of the contact you want to find :" <<
endl; cin >> name; int ret = isExist(adl, name); if (ret == 1) { for (int i = 0
; i < adl->list_Size; i++) { if (adl->linkmanArray[i].Name == name) { int flag =
-1; while(flag != 1){ cout << "\n\n Please enter the information number to be modified :\t1 - full name \n\t\t\t2 - Gender \n\t\t\t3
- Age \n\t\t\t4 - Telephone \n\t\t\t0 - Complete modification \n "; int choice = -1; cin >> choice; switch
(choice) { case 1: cout << " Please enter a new contact name :"; cin >> adl->linkmanArray[i].Name; cout
<< "\n Name modified successfully !"; break; case 2: { int sex = -1; cout << "1 - male , 2 - female "; cout <<
"\n Please enter a new contact gender :"; while (sex != 1 && sex != 2) { cin >> sex; if (sex == 1 || sex
== 2) { adl->linkmanArray[i].Sex = sex; cout << "\n Gender modified successfully !"; } else { cout <<
" Illegal input , Please re-enter !" << endl; } } } break; case 3: cout << "\n Please enter the age of the new contact :"; cin >> adl
->linkmanArray[i].Age; cout << "\n Age modified successfully !"; break; case 4: cout <<
"\n Please enter a new contact phone number :"; cin >> adl->linkmanArray[i].PhoneNum; cout << "\n Phone number modified successfully !";
break; case 0: cout << "\n Finish modifying ."; flag = 1; break; default: cout <<
"\n illegal input , Please re-enter !"; break; } } } } } else { cout << " Does not exist with name - " << name << " -
Contact for !" << endl; } } // Empty address book void cleanList(struct addressList* adl) { int choice
= -1; while(1){ cout << " Are you sure to delete all contact information ?\t1 - yes \t0 - no\n"; cin >> choice; if (
choice== 1) { adl->list_Size = 0; // Do logical emptying cout << " The address book has been cleared !" << endl; break; }
else if (choice == 0) { cout << " Cancel deleting all contact information !" << endl; break; } else { cout <<
" illegal input , Please re-enter !" << endl; } } }

Technology
©2019-2020 Toolsou All rights reserved,
Android Using wechat in H5 Payment result refresh during payment shock !!C++ Can make a sound ! Basic operation of single linked list C Language explanation Java Implement an epidemic number management system 2021 year 11 World programming language ranking linux upper mysql Invalid command _linux lower mysql The command is useless Java project : Campus dormitory management system (java+jsp+javaweb+mysql+ajax) Wechat applet development project directory linux ubuntu Which version ,Ubuntu Which version is the best ?python Code painting cherry blossoms - How to use Python Draw a beautiful cherry blossom