#include <iostream>
using namespace std;
#include <string>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX 1000
#include <string>
struct Person
{
string name;
int sex;
int phone;
};
struct Address
{
Person personArray[MAX];
int m_size;
};
void show()
{
cout<<"***** 1.添加联系人"<<endl;
cout<<"***** 2.删除联系人"<<endl;
}
void addPerson(Address *abs)
{
if(abs->m_size==MAX)
{
cout<<"通讯录已满"<<endl;
return;
}
else
{
string name;
cout<<"请输入姓名:"<<endl;
cin>>name;
abs->personArray[abs->m_size].name=name;
abs->m_size++;
cout<<"添加成功"<<endl;
}
system("pause");
system("cls");
}
void printf(Address *abs)
{
if(abs->m_size==0)
{
cout<<"当前记录为空"<<endl;
}else
{
for(int i=0;i<abs->m_size;i++)
{
cout<<"姓名"<<abs->personArray[i].name<<endl;
}
}
system("pause");
system("cls");
}
int isExist(Address *abs,string name)
{
for(int i=0;i<abs->m_size;i++)
{
if(abs->personArray[i].name==name)
{
return i;
}
}
return -1;
}
void deletePerson(Address *abs)
{
cout<<"请输入要删除的联系人"<<endl;
string name;
cin>>name;
int ret =isExist(abs,name);
if(ret!=-1)
{
for(int i=ret;i<abs->m_size;i++)
{
abs->personArray[i]=abs->personArray[i+1];
}
abs->m_size--;
}
else
{
cout<<"查无此人"<<endl;
}
system("pause");
system("cls");
}
void findPerson(Address*abs)
{
cout<<"输入查找的联系人"<<endl;
string name;
cin>>name;
int ret=isExist(abs,name);
if(ret!=-1)
{
cout<<"姓名 "<<abs->personArray[ret].name<<"\t";
}
else
{
cout<<"查无此人"<<endl;
}
system("pause");
system("cls");
}
void modify(Address *abs)
{
cout<<"请输入你要修改的联系人的信息"<<endl;
string name;
cin>>name;
int ret=isExist(abs,name);
if(ret!=-1)
{
//姓名
string name;
cout<<"请输入姓名"<<endl;
cin>>name;
abs->personArray[ret].name=name;
}
else
{
cout<<"没有找到此联系人"<<endl;
}
}
void cleanPerson(Address*abs)
{
}
int main()
{
int n;
Address abs;
abs.m_size=0;
while(1)
{
cin>>n;
switch(n)
{
case 1:
addPerson(&abs);break;
case 2:
printf(&abs);break;
case 3:
deletePerson(&abs);break;
case 4:
findPerson(&abs);break;
case 0:
return 0;
}
}
return 0;
}