#include <iostream>
using namespace std;
#include <string>
#define MAX 1000//Set up a Person struct to lay in the data
struct Person
{
string Name;int Sex;int Age;
string Phone;
string Addr;};//Set up a Addressbooks struct to lay in person information
struct Addressbooks
{
struct Person personArray[MAX];int Size;};//A Function to show the fundamental functionvoidshowMenu(){
cout <<"********************************"<< endl;
cout <<"***** 1.Add Member *****"<< endl;
cout <<"***** 2.Show Member *****"<< endl;
cout <<"***** 3.Delete Member *****"<< endl;
cout <<"***** 4.Search Member *****"<< endl;
cout <<"***** 5.Edit Member *****"<< endl;
cout <<"***** 6.Clean up Member *****"<< endl;
cout <<"***** 0.Exit *****"<< endl;
cout <<"********************************"<< endl;
cout <<"Please choose the number"<< endl;}voidaddPerson(Addressbooks * abs){//To judge whether the Addressbooks is full , if not , enter the data if(abs -> Size == MAX){
cout <<" The List is full!"<<endl;return;}else{
string name;
cout <<"Please set the name:"<<endl;
cin >> name;
abs ->personArray[abs->Size].Name = name;}
cout <<"Please set the sex:"<< endl;
cout <<" *1 --- ♂* "<< endl;
cout <<" *2 --- ♀* "<< endl;int sex =0;//enter 1 or 2 to jump out of the circulation , if not , continue the circulationwhile(true){
cin >> sex;if(sex ==1|| sex ==2){
abs -> personArray[abs->Size].Sex = sex;break;}else{
cout <<"Error.Please reset the Sex"<< endl;}}//enter the data of Person
cout <<"Please set the Age:"<< endl;int age =0;
cin >> age;
abs -> personArray[abs -> Size].Age = age;
cout <<"Please set the Number:"<< endl;
string phone;
cin >> phone;
abs -> personArray[abs -> Size].Phone = phone;
cout <<"Please set the Address:"<< endl;
string address;
cin >> address;
abs -> personArray[abs -> Size].Addr = address;
abs -> Size++;
cout <<"Success"<< endl;system("pause");system("cls");}//This function can show all the person data in the addressbookvoidshowPerson(Addressbooks *abs){if(abs -> Size ==0){
cout <<"Empty"<< endl;}else{for(int i =0; i < abs->Size; i++){
cout <<"Name:"<< abs -> personArray[i].Name <<"\t";
cout <<"Sex:"<<(abs -> personArray[i].Sex ==1?" ♂ ":" ♀ ")<<"\t";
cout <<"Age:"<< abs -> personArray[i].Age <<"\t";
cout <<"PhoneNumber:"<< abs -> personArray[i].Phone <<"\t";
cout <<"Address:"<< abs -> personArray[i].Addr << endl;}}//Pause and clean the windowsystem("pause");system("cls");}//This function can examine whether the person is existintisExist(Addressbooks *abs, string name){for(int i=0; i < abs->Size; i++){if(abs -> personArray[i].Name == name){return i;}}return-1;}//This function can delete the person datavoiddeletePerson(Addressbooks *abs){
cout <<"Please enter a name that you want to delete"<< endl;
string name;
cin >> name;//ret == -1 , does not exist//ret != -1 , exist , deleteint ret =isExist(abs, name);if(ret !=-1){//Found the one you want to delete//run the delete fuctionfor(int i = ret; i < abs->Size; i++){//data cover
abs -> personArray[i]= abs -> personArray[ i+1];}//refresh the person data
abs ->Size--;
cout <<"Detele Success"<< endl;}system("pause");system("cls");}//Search the person data you wantvoidfindPerson(Addressbooks *abs){
cout <<"Please enter a person you want to find"<<endl;
string name;
cin >> name;int ret =isExist(abs , name);if(ret !=-1){
cout <<"Name:"<< abs -> personArray[ret].Name <<"\t";
cout <<"Sex:"<<(abs -> personArray[ret].Sex ==1?" ♂ ":" ♀ ")<<"\t";
cout <<"Age:"<< abs -> personArray[ret].Age <<"\t";
cout <<"PhoneNumber:"<< abs -> personArray[ret].Phone <<"\t";
cout <<"Address:"<< abs -> personArray[ret].Addr << endl;}else{
cout <<"Error, doesn't find the person"<<endl;}
system ("pause");
system ("cls");}//Edit the person datavoidmodifyPerson(Addressbooks * abs){
cout <<"Please enter a person you want to modify:"<<endl;
string name;
cin >> name;int ret =isExist(abs, name);if(ret !=-1){
string name;
cout <<"Please enter a Person Name"<<endl;
cin >> name;
abs ->personArray[ret].Name = name;
cout <<"Please enter a Person Sex"<<endl;
cout <<"1 --- ♂"<< endl;
cout <<"2 --- ♀"<< endl;int sex =0;while(true){
cin >> sex;if(sex ==1|| sex ==2){
abs ->personArray[ret].Sex = sex;break;}else{
cout <<"Error , please enter a right number"<<endl;}}
cout <<"Please enter the number"<< endl;
string phone;
cin >> phone;
abs -> personArray[ret].Phone = phone ;
cout <<"Please enter the address"<< endl;
string address;
cin >> address;
abs -> personArray[ret].Addr = address;
cout <<"Edit Success"<< endl;}else{
cout <<"Error , doesn't find the person"<< endl;}system("pause");system("cls");}// Clear up the AddressbooksvoidcleanPerson(Addressbooks *abs){
abs ->Size =0;
cout <<"The Addressbooks are Clear up"<<endl;system("pause");system("cls");}intmain(){
Addressbooks abs;
abs.Size =0;int select;//enter a number from 0-6 and do the functionwhile(true){showMenu();
cin >> select;switch(select){case1:addPerson(&abs);break;case2:showPerson(&abs);break;case3:deletePerson(&abs);break;case4:findPerson(&abs);break;case5:modifyPerson(&abs);break;case6:cleanPerson(&abs);break;case0:
cout <<"Welcome Next Time!"<<endl;system("pause");return0;break;default:
cout <<"* Please enter a number from 0-6 *"<<endl;break;}}system("pause");return0;}