#include<iostream>
using namespace std;
const int ArrSize = 1000;
int cap = 0;
struct people
{
string name;
string sex;
int age;
string telephone;
string address;
};
people address_book[ArrSize];
void Show_Menu();
void Add(people*);
void show(people*);
void del(people*);
void find(people*);
void change(people*);
void clear(people*);
int main()
{
int select;
while (true)
{
Show_Menu();
cout << "请选择功能:";
cin >> select;
switch (select)
{
case 1:
Add(address_book);
break;
case 2:
show(address_book);
break;
case 3:
del(address_book);
break;
case 4:
find(address_book);
break;
case 5:
change(address_book);
break;
case 6:
clear(address_book);
break;
case 0:
cout << "欢迎下次使用" << endl;
exit(-1);
break;
}
}
return 0;
}
void Show_Menu()
{
cout << "*************************" << endl;
cout << "***** 1,添加联系人 *****" << endl;
cout << "***** 2,显示联系人 *****" << endl;
cout << "***** 3,删除联系人 *****" << endl;
cout << "***** 4,查找联系人 *****" << endl;
cout << "***** 5,修改联系人 *****" << endl;
cout << "***** 6,清空联系人 *****" << endl;
cout << "***** 0,退出通讯录 *****" << endl;
cout << "*************************" << endl;
}
void Add(people pe[])
{
if (cap < ArrSize)
{
cout << "请输入联系人姓名:";
cin >> pe[cap].name;
cout << "请输入联系人性别:";
cin >> pe[cap].sex;
cout << "请输入联系人年龄:";
cin >> pe[cap].age;
cout << "请输入联系人电话:";
cin >> pe[cap].telephone;
cout << "请输入联系人地址:";
cin >> pe[cap].address;
cap++;
}
else cout << " 空间不足,请释放部分联系人在添加" << endl;
system("pause");
system("cls");
}
void show(people pe[])
{
if (!cap) cout << " 通讯录为空,请添加联系人吧" << endl;
else
{
cout << "姓名:" << "\t" << "性别" << "\t" << "年龄" << "\t" << "电话" << "\t" << "\t地址" << endl;
for (int i = 0; i < cap; i++)
{
cout << pe[i].name << " " << pe[i].sex << "\t" << pe[i].age << "\t" << pe[i].telephone << "\t" << pe[i].address << endl;
}
}
system("pause");
system("cls");
}
void del(people pe[])
{
string temp;
cout << "请输入你要删除的联系人:";
cin >> temp;
bool flag = true;
int t = 0;
for (int i = 0; i < cap; i++)
{
if (pe[i].name == temp)
{
flag = false;
t = i;
break;
}
}
if (flag) cout << " 要删除的联系人不存在 " << endl;
else
{
for (int i = t; i < cap; i++)
{
pe[i] = pe[i + 1];
}
cap--;
cout << "删除成功" << endl;
}
system("pause");
system("cls");
}
void find(people pe[])
{
string temp;
cout << "请输入你要查找的联系人:";
cin >> temp;
bool flag = false;
int t = 0;
for (int i = 0; i < cap; i++)
{
if (pe[i].name == temp)
{
flag = true;
t = i;
break;
}
}
if (flag)
{
cout << "姓名:" << "\t" << "性别" << "\t" << "年龄" << "\t" << "电话" << "\t" << "\t地址" << endl;
cout << pe[t].name << " " << pe[t].sex << "\t" << pe[t].age << "\t" << pe[t].telephone << "\t" << pe[t].address << endl;
}
else
{
cout << " 通讯录中没有此人" << endl;
}
system("pause");
system("cls");
}
void change(people pe[])
{
string temp;
cout << "请输入你要修改的联系人:";
cin >> temp;
bool flag = false;
int t = 0;
for (int i = 0; i < cap; i++)
{
if (pe[i].name == temp)
{
flag = true;
t = i;
break;
}
}
if (flag)
{
cout << "请输入需要修改联系人的姓名:";
cin >> pe[t].name;
cout << "请输入需要修改联系人的性别:";
cin >> pe[t].sex;
cout << "请输入需要修改联系人的年龄:";
cin >> pe[t].age;
cout << "请输入需要修改联系人的电话:";
cin >> pe[t].telephone;
cout << "请输入需要修改联系人的地址:";
cin >> pe[t].address;
}
else
{
cout << " 通讯录中没有此人" << endl;
}
system("pause");
system("cls");
}
void clear(people pe[])
{
cap = 0;
system("pause");
system("cls");
}