#include<iostream>
using namespace std;
#define Max 100
//联系人结构体
struct Person
{
string Name;
string Sex;
int Age;
string Phone;
string Address;
};
//通信录结构体,显示的时候用
struct Addressbooks
{
int len;
struct Person *PersonArray;
};
void showMenu()
{
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 AddPerson(Addressbooks *CC)
{
if (CC->len > Max)
{
cout << "通信录已满" << endl; return;
}
else {
string name;
cout << "请输入你的姓名" << endl;
cin >> name;
CC->PersonArray[CC->len].Name = name;//访问结构体时必须用结构体访问符号
string sex;
cout << "请输入你的性别" << endl;
cin >> sex;
CC->PersonArray[CC->len].Sex = sex;
int age;
cout << "请输入你的年龄" << endl;
cin >> age;
CC->PersonArray[CC->len].Age = age;
string phone;
cout << "请输入你的电话号码" << endl;
cin >> phone;
CC->PersonArray[CC->len].Phone = phone;
string address;
cout << "请输入你的地址" << endl;
cin >> address;
CC->PersonArray[CC->len].Address = address;
CC->len++;
cout << "添加成功" << endl;
system("pause");
system("cls");
}
}
//显示所有联系人操作
void ShowPerson(Addressbooks *CC)
{
if (CC->len == 1)
cout << "当前通信录为空" << endl;
for (int i = 1; i < (CC->len); i++) {
cout << CC->PersonArray[i].Name << '\t' << CC->PersonArray[i].Sex << ' ' << CC->PersonArray[i].Age << '\t' << CC->PersonArray[i].Phone << ' '
<< CC->PersonArray[i].Address << endl;
cout << "lvvv" << endl;
}
}
//
int main() {
//使用switch语句实现选择结构
int select = -1;
while (select) {//保证用户只有在按0时才会退出系统
//初始界面显示,用函数封装
showMenu();
struct Addressbooks CC;
CC.len = 1;//创建初始化通信录结构体
cin >> select;
switch (select)
{
case 1://增加联系人
AddPerson(&CC);
break;
case 2://删除联系人
break;
case 3://查找联系人
break;
case 4://修改联系人
break;
case 5://显示所有联系人
ShowPerson(&CC);
break;
case 6://清空通信录
break;
case 0://退出系统
cout << "欢迎下次使用" << endl;
system("pause");
return 0;
break;
default:
break;
}
}
system("pause");
return 0;
}