系统需求

通讯录是一个可以记录亲人、好友信息的工具。

本教程主要利用C++来实现一个通讯录管理系统

系统中需要实现的功能如下:

  • 添加联系人:向通讯录中添加新人,信息包括(姓名、性别、年龄、联系电话、家庭住址)最多记录1000人
  • 显示联系人:显示通讯录中所有联系人信息
  • 删除联系人:按照姓名进行删除指定联系人
  • 查找联系人:按照姓名查看指定联系人信息
  • 修改联系人:按照姓名重新修改指定联系人
  • 清空联系人:清空通讯录中所有信息
  • 退出通讯录:退出当前使用的通讯录

System Requirements

An address book is a tool that can record the information of family and friends.

This tutorial mainly uses C++ to implement an address book management system

The functions that need to be implemented in the system are as follows:

  • Add contact: add a new person to the address book, with information including (name, gender, age, phone number, home address), recording up to 1000 people
  • Display contacts: display the information of all contacts in the address book
  • Delete contact: delete the specified contact by name
  • Find contact: view the information of the specified contact by name
  • Modify contact: re-modify the specified contact by name
  • Clear contacts: clear all information in the address book
  • Exit address book: exit the address book currently in use

创建项目

创建项目步骤如下:

  • 创建新项目
  • 添加文件

Create the Project

The steps to create the project are as follows:

  • Create a new project
  • Add files

创建项目

打开vs2017后,点击创建新项目,创建新的C++项目

1544151401138

填写项目名称,选择项目路径

1544151579620

Create the Project

After opening VS2017, click “Create New Project” to create a new C++ project

1544151401138

Fill in the project name and select the project path

1544151579620

添加文件

1544161551746

1544161648175

添加成功后,效果如图:

1544162344057

至此,项目已创建完毕

Add Files

1544161551746

1544161648175

After adding successfully, the effect is as shown:

1544162344057

At this point, the project has been created

菜单功能

功能描述: 用户选择功能的界面

菜单界面效果如下图:

1544149559893

步骤:

  • 封装函数显示该界面 如 void showMenu()
  • 在main函数中调用封装好的函数

代码:

Function description: The interface where the user selects functions

The menu interface effect is shown below:

1544149559893

Steps:

  • Encapsulate a function to display this interface, such as void showMenu()
  • Call the encapsulated function in the main function

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include<iostream>
using namespace std;

//菜单界面
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;
}

int main() {

showMenu();

system("pause");

return 0;
}

退出功能

功能描述:退出通讯录系统

思路:根据用户不同的选择,进入不同的功能,可以选择switch分支结构,将整个架构进行搭建

当用户选择0时候,执行退出,选择其他先不做操作,也不会退出程序

代码:

Exit Function

Function description: exit the address book management system

Approach: according to the user’s different choices, different functions are entered. A switch branch structure can be chosen to build the entire architecture

When the user selects 0, exit is executed; when other options are selected, no operation is performed and the program will not exit

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
int main() {

int select = 0;

while (true)
{
showMenu();

cin >> select;

switch (select)
{
case 1: //添加联系人
break;
case 2: //显示联系人
break;
case 3: //删除联系人
break;
case 4: //查找联系人
break;
case 5: //修改联系人
break;
case 6: //清空联系人
break;
case 0: //退出通讯录
cout << "欢迎下次使用" << endl;
system("pause");
return 0;
break;
default:
break;
}
}

system("pause");

return 0;
}

效果图:

1544163868043

Screenshot of the effect:

1544163868043

添加联系人

功能描述:

实现添加联系人功能,联系人上限为1000人,联系人信息包括(姓名、性别、年龄、联系电话、家庭住址)

添加联系人实现步骤:

  • 设计联系人结构体
  • 设计通讯录结构体
  • main函数中创建通讯录
  • 封装添加联系人函数
  • 测试添加联系人功能

Add Contact

Function description:

Implement the function of adding contacts. The upper limit of contacts is 1000 people, and the contact information includes (name, gender, age, phone number, home address)

Steps to implement adding contacts:

  • Design the contact structure
  • Design the address book structure
  • Create the address book in the main function
  • Encapsulate the add-contact function
  • Test the add-contact function

设计联系人结构体

联系人信息包括:姓名、性别、年龄、联系电话、家庭住址

设计如下:

Design the Contact Structure

The contact information includes: name, gender, age, phone number, home address

Design as follows:

1
2
3
4
5
6
7
8
9
10
#include <string>  //string头文件
//联系人结构体
struct Person
{
string m_Name; //姓名
int m_Sex; //性别:1男 2女
int m_Age; //年龄
string m_Phone; //电话
string m_Addr; //住址
};

设计通讯录结构体

设计时候可以在通讯录结构体中,维护一个容量为1000的存放联系人的数组,并记录当前通讯录中联系人数量

设计如下

Design the Address Book Structure

When designing, we can maintain an array with a capacity of 1000 for storing contacts in the address book structure, and record the current number of contacts in the address book

Design as follows

1
2
3
4
5
6
7
8
#define MAX 1000 //最大人数

//通讯录结构体
struct Addressbooks
{
struct Person personArray[MAX]; //通讯录中保存的联系人数组
int m_Size; //通讯录中人员个数
};

main函数中创建通讯录

添加联系人函数封装好后,在main函数中创建一个通讯录变量,这个就是我们需要一直维护的通讯录

Create the Address Book in the main Function

After the add-contact function is encapsulated, create an address book variable in the main function; this is the address book we need to maintain all along

1
2
3
4
5
6
mian函数起始位置添加:

//创建通讯录
Addressbooks abs;
//初始化通讯录中人数
abs.m_Size = 0;

封装添加联系人函数

思路:添加联系人前先判断通讯录是否已满,如果满了就不再添加,未满情况将新联系人信息逐个加入到通讯录

添加联系人代码:

Encapsulate the Add-Contact Function

Approach: before adding a contact, first check whether the address book is full. If it is full, no more contacts will be added. If it is not full, add the new contact’s information to the address book one by one

The add-contact code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//1、添加联系人信息
void addPerson(Addressbooks *abs)
{
//判断电话本是否满了
if (abs->m_Size == MAX)
{
cout << "通讯录已满,无法添加" << endl;
return;
}
else
{
//姓名
string name;
cout << "请输入姓名:" << endl;
cin >> name;
abs->personArray[abs->m_Size].m_Name = name;

cout << "请输入性别:" << endl;
cout << "1 -- 男" << endl;
cout << "2 -- 女" << endl;

//性别
int sex = 0;
while (true)
{
cin >> sex;
if (sex == 1 || sex == 2)
{
abs->personArray[abs->m_Size].m_Sex = sex;
break;
}
cout << "输入有误,请重新输入" << endl;
}

//年龄
cout << "请输入年龄:" << endl;
int age = 0;
cin >> age;
abs->personArray[abs->m_Size].m_Age = age;

//联系电话
cout << "请输入联系电话:" << endl;
string phone = "";
cin >> phone;
abs->personArray[abs->m_Size].m_Phone = phone;

//家庭住址
cout << "请输入家庭住址:" << endl;
string address;
cin >> address;
abs->personArray[abs->m_Size].m_Addr = address;

//更新通讯录人数
abs->m_Size++;

cout << "添加成功" << endl;
system("pause");
system("cls");
}
}

测试添加联系人功能

选择界面中,如果玩家选择了1,代表添加联系人,我们可以测试下该功能

在switch case 语句中,case1里添加:

Test the Add-Contact Function

In the selection interface, if the player selects 1, it means adding a contact; we can test this function

In the switch case statement, add it in case 1:

1
2
3
case 1:  //添加联系人
addPerson(&abs);
break;

测试效果如图:

1544165554002

The test result is shown below:

1544165554002

显示联系人

功能描述:显示通讯录中已有的联系人信息

显示联系人实现步骤:

  • 封装显示联系人函数
  • 测试显示联系人功能

Display Contacts

Function description: display the contact information already in the address book

Steps to implement displaying contacts:

  • Encapsulate the display-contacts function
  • Test the display-contacts function

封装显示联系人函数

思路:判断如果当前通讯录中没有人员,就提示记录为空,人数大于0,显示通讯录中信息

显示联系人代码:

Encapsulate the Display-Contacts Function

Approach: check whether there are people in the current address book. If there are no people, prompt that the records are empty; if the number is greater than 0, display the information in the address book

The display-contacts code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//2、显示所有联系人信息
void showPerson(Addressbooks * abs)
{
if (abs->m_Size == 0)
{
cout << "当前记录为空" << endl;
}
else
{
for (int i = 0; i < abs->m_Size; i++)
{
cout << "姓名:" << abs->personArray[i].m_Name << "\t";
cout << "性别:" << (abs->personArray[i].m_Sex == 1 ? "男" : "女") << "\t";
cout << "年龄:" << abs->personArray[i].m_Age << "\t";
cout << "电话:" << abs->personArray[i].m_Phone << "\t";
cout << "住址:" << abs->personArray[i].m_Addr << endl;
}
}

system("pause");
system("cls");

}

测试显示联系人功能

在switch case语句中,case 2 里添加

Test the Display-Contacts Function

In the switch case statement, add it in case 2

1
2
3
case 2:  //显示联系人
showPerson(&abs);
break;

测试效果如图:

1544166401582

The test result is shown below:

1544166401582

删除联系人

功能描述:按照姓名进行删除指定联系人

删除联系人实现步骤:

  • 封装检测联系人是否存在
  • 封装删除联系人函数
  • 测试删除联系人功能

Delete Contact

Function description: delete the specified contact by name

Steps to implement deleting contacts:

  • Encapsulate the check for whether a contact exists
  • Encapsulate the delete-contact function
  • Test the delete-contact function

封装检测联系人是否存在

设计思路:

删除联系人前,我们需要先判断用户输入的联系人是否存在,如果存在删除,不存在提示用户没有要删除的联系人

因此我们可以把检测联系人是否存在封装成一个函数中,如果存在,返回联系人在通讯录中的位置,不存在返回-1

检测联系人是否存在代码:

Encapsulate the Check for Whether a Contact Exists

Design approach:

Before deleting a contact, we need to first determine whether the contact entered by the user exists. If it exists, delete it; if it does not exist, prompt the user that there is no contact to delete

Therefore, we can encapsulate the check for whether a contact exists into a function. If the contact exists, return its position in the address book; if it does not exist, return -1

The code for checking whether a contact exists:

1
2
3
4
5
6
7
8
9
10
11
12
13
//判断是否存在查询的人员,存在返回在数组中索引位置,不存在返回-1
int isExist(Addressbooks * abs, string name)
{
for (int i = 0; i < abs->m_Size; i++)
{
if (abs->personArray[i].m_Name == name)
{
return i;
}
}
return -1;
}

封装删除联系人函数

根据用户输入的联系人判断该通讯录中是否有此人

查找到进行删除,并提示删除成功

查不到提示查无此人。

Encapsulate the Delete-Contact Function

Determine whether the person is in the address book based on the contact entered by the user

If found, delete the contact and prompt that the deletion succeeded

If not found, prompt that no such person exists.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//3、删除指定联系人信息
void deletePerson(Addressbooks * 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--;
cout << "删除成功" << endl;
}
else
{
cout << "查无此人" << endl;
}

system("pause");
system("cls");
}

测试删除联系人功能

在switch case 语句中,case3里添加:

Test the Delete-Contact Function

In the switch case statement, add it in case 3:

1
2
3
case 3:  //删除联系人
deletePerson(&abs);
break;

测试效果如图:

存在情况:

1544167951559

不存在情况:

1544168010831

The test result is shown below:

When the contact exists:

1544167951559

When the contact does not exist:

1544168010831

查找联系人

功能描述:按照姓名查看指定联系人信息

查找联系人实现步骤

  • 封装查找联系人函数
  • 测试查找指定联系人

Find Contact

Function description: view the information of the specified contact by name

Steps to implement finding a contact

  • Encapsulate the find-contact function
  • Test finding the specified contact

封装查找联系人函数

实现思路:判断用户指定的联系人是否存在,如果存在显示信息,不存在则提示查无此人。

查找联系人代码:

Encapsulate the Find-Contact Function

Implementation approach: determine whether the contact specified by the user exists. If it exists, display the information; if it does not exist, prompt that no such person exists.

The find-contact code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//4、查找指定联系人信息
void findPerson(Addressbooks * abs)
{
cout << "请输入您要查找的联系人" << endl;
string name;
cin >> name;

int ret = isExist(abs, name);
if (ret != -1)
{
cout << "姓名:" << abs->personArray[ret].m_Name << "\t";
cout << "性别:" << abs->personArray[ret].m_Sex << "\t";
cout << "年龄:" << abs->personArray[ret].m_Age << "\t";
cout << "电话:" << abs->personArray[ret].m_Phone << "\t";
cout << "住址:" << abs->personArray[ret].m_Addr << endl;
}
else
{
cout << "查无此人" << endl;
}

system("pause");
system("cls");

}

测试查找指定联系人

在switch case 语句中,case4里添加:

Test Finding the Specified Contact

In the switch case statement, add it in case 4:

1
2
3
case 4:  //查找联系人
findPerson(&abs);
break;

测试效果如图

存在情况:

1544170057646

不存在情况:

1544170254021

The test result is shown below

When the contact exists:

1544170057646

When the contact does not exist:

1544170254021

修改联系人

功能描述:按照姓名重新修改指定联系人

修改联系人实现步骤

  • 封装修改联系人函数
  • 测试修改联系人功能

Modify Contact

Function description: re-modify the specified contact by name

Steps to implement modifying a contact

  • Encapsulate the modify-contact function
  • Test the modify-contact function

封装修改联系人函数

实现思路:查找用户输入的联系人,如果查找成功进行修改操作,查找失败提示查无此人

修改联系人代码:

Encapsulate the Modify-Contact Function

Implementation approach: find the contact entered by the user. If the search succeeds, perform the modification; if it fails, prompt that no such person exists

The modify-contact code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//5、修改指定联系人信息
void modifyPerson(Addressbooks * abs)
{
cout << "请输入您要修改的联系人" << endl;
string name;
cin >> name;

int ret = isExist(abs, name);
if (ret != -1)
{
//姓名
string name;
cout << "请输入姓名:" << endl;
cin >> name;
abs->personArray[ret].m_Name = name;

cout << "请输入性别:" << endl;
cout << "1 -- 男" << endl;
cout << "2 -- 女" << endl;

//性别
int sex = 0;
while (true)
{
cin >> sex;
if (sex == 1 || sex == 2)
{
abs->personArray[ret].m_Sex = sex;
break;
}
cout << "输入有误,请重新输入" << endl;
}

//年龄
cout << "请输入年龄:" << endl;
int age = 0;
cin >> age;
abs->personArray[ret].m_Age = age;

//联系电话
cout << "请输入联系电话:" << endl;
string phone = "";
cin >> phone;
abs->personArray[ret].m_Phone = phone;

//家庭住址
cout << "请输入家庭住址:" << endl;
string address;
cin >> address;
abs->personArray[ret].m_Addr = address;

cout << "修改成功" << endl;
}
else
{
cout << "查无此人" << endl;
}

system("pause");
system("cls");

}

测试修改联系人功能

在switch case 语句中,case 5里添加:

Test the Modify-Contact Function

In the switch case statement, add it in case 5:

1
2
3
case 5:  //修改联系人
modifyPerson(&abs);
break;

测试效果如图:

查不到指定联系人情况:

1544172265676

查找到联系人,并修改成功:

1544172164141

再次查看通讯录,确认修改完毕

1544172228627

The test result is shown below:

When the specified contact cannot be found:

1544172265676

The contact is found and modified successfully:

1544172164141

Check the address book again to confirm the modification is complete

1544172228627

清空联系人

功能描述:清空通讯录中所有信息

清空联系人实现步骤

  • 封装清空联系人函数
  • 测试清空联系人

Clear Contacts

Function description: clear all information in the address book

Steps to implement clearing contacts

  • Encapsulate the clear-contacts function
  • Test clearing contacts

封装清空联系人函数

实现思路: 将通讯录所有联系人信息清除掉,只要将通讯录记录的联系人数量置为0,做逻辑清空即可。

清空联系人代码:

Encapsulate the Clear-Contacts Function

Implementation approach: to clear all contact information in the address book, simply set the number of contacts recorded in the address book to 0 to perform a logical clear.

The clear-contacts code:

1
2
3
4
5
6
7
8
//6、清空所有联系人
void cleanPerson(Addressbooks * abs)
{
abs->m_Size = 0;
cout << "通讯录已清空" << endl;
system("pause");
system("cls");
}

测试清空联系人

在switch case 语句中,case 6 里添加:

Test Clearing Contacts

In the switch case statement, add it in case 6:

1
2
3
case 6:  //清空联系人
cleanPerson(&abs);
break;

测试效果如图:

清空通讯录

1544172909693

再次查看信息,显示记录为空

1544172943653

至此,通讯录管理系统完成!

The test result is shown below:

Clear the address book

1544172909693

Check the information again, and the records are shown to be empty

1544172943653

At this point, the address book management system is complete!

我的完整实现代码

点击查看:

My Complete Implementation Code

Click to view:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include <iostream>
#include <string>
using namespace std;

#define MaxPersonNum 1000

struct Person {
string name;
int m_Sex;
int m_Age;
string m_Phone;
string m_Addr;
};

struct Addressbooks {
struct Person personArray[MaxPersonNum];
int m_Size;
};


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* abs) {
if (abs->m_Size == MaxPersonNum) {
cout << "通讯录已满,无法添加!" << endl;
return;
}
string name;
cout << "请输入姓名:" << endl;
cin >> name;
abs->personArray[abs->m_Size].name = name;

int sex = 0;
while (sex != 1 && sex != 2)
{
sex = 0;
cout << "请输入性别:1. 男 2. 女" << endl;
cin >> sex;
if (sex != 1 && sex != 2) {
cout << "输入数据有误!请重新输入。" << endl;
}
}
abs->personArray[abs->m_Size].m_Sex = sex;

int age = 0;
cout << "请输入年龄:" << endl;
cin >> age;
abs->personArray[abs->m_Size].m_Age = age;

string phone;
cout << "请输入电话号码:" << endl;
cin >> phone;
abs->personArray[abs->m_Size].m_Phone = phone;

string address;
cout << "请输入家庭住址:" << endl;
cin >> address;
abs->personArray[abs->m_Size].m_Addr = address;

abs->m_Size++;
cout << "添加成功!" << endl;

system("cls");
}


void showPerson(Addressbooks* abs) {
if (abs->m_Size == 0) {
cout << "通讯录为空!" << endl;

}
else {
cout << "姓名\t" << "性别\t" << "年龄\t" << "电话号码\t" << "家庭住址\t"
<< endl;
for (int i = 0;i < abs->m_Size; i++) {
string sex = (abs->personArray[i].m_Sex == 1) ? "男" : "女";
cout << abs->personArray[i].name << "\t" << sex
<< "\t" << abs->personArray[i].m_Age << "\t"
<< abs->personArray[i].m_Phone << "\t"
<< abs->personArray[i].m_Addr << "\t" << endl;
}
}
system("pause");
system("cls");
return;
}
int isExist(Addressbooks * abs, string name) {
if (abs->m_Size == 0) return -1;
for (int i = 0;i < abs->m_Size; i++) {
if (abs->personArray[i].name == name) {
return i;
}
}
return -1;
}
void deletePerson(Addressbooks * abs) {
if (abs->m_Size == 0) {
cout << "通讯录为空!" << endl;
}
else {
int select = 1;
while (select) {
string name;
cout << "请输入要删除联系人姓名:" << endl;
cin >> name;
int flag = isExist(abs, name);
if (flag != -1) {
for (int i = flag;i < abs->m_Size; i++) {
abs->personArray[i] = abs->personArray[i + 1];
}
abs->m_Size--;
cout << "删除成功!" << endl << endl;
break;
}
else {
cout << "查无此人!" << endl << endl;
cout << "是否重新输入?" << endl << "1. 是" << endl << "0. 否" << endl;
cin >> select;
}
}
}
system("pause");
system("cls");
return;
}

void searchPerson(Addressbooks * abs) {
if (abs->m_Size == 0) {
cout << "通讯录为空!" << endl;
}
else{
int select = 1;
while (select) {
string name;
cout << "请输入要查询联系人姓名:" << endl;
cin >> name;
int flag = isExist(abs, name);
if (flag != -1) {
cout << name << " 的信息如下:" << endl;
cout << "性别:\t" << (abs->personArray[flag].m_Sex == 1 ? "男" : "女") << endl
<< "年龄:\t" << abs->personArray[flag].m_Age << endl
<< "电话号码:\t" << abs->personArray[flag].m_Phone << endl
<< "家庭住址:\t" << abs->personArray[flag].m_Addr << endl;
break;
}
else {
cout << "查无此人!" << endl << endl;
cout << "是否重新输入?" << endl << "1. 是" << endl << "0. 否" << endl;
cin >> select;
}
}

}
system("pause");
system("cls");
return;
}

void modifyPerson(Addressbooks *abs) {
if (abs->m_Size == 0) {
cout << "通讯录为空!" << endl;

}
else {
string name;
cout << "请输入要修改联系人姓名:" << endl;
cin >> name;
int flag = isExist(abs, name);
if (flag != -1) {
cout << "请输入姓名:" << endl;
cin >> abs->personArray[flag].name;

int sex = 0;
while (sex != 1 && sex != 2) {
cout << "请输入性别:" << endl << "1. 男" << endl << "2. 女" << endl;
cin >> sex;
if (sex != 1 && sex != 2) {
cout << "输入数据有误!请重新输入。" << endl;
}
}
abs->personArray[flag].m_Sex = sex;

cout << "请输入电话号码:" << endl;
cin >> abs->personArray[flag].m_Phone;

cout << "请输入家庭住址:" << endl;
cin >> abs->personArray[flag].m_Addr;

cout << "修改成功!" << endl << endl;
}
else {
cout << "查无此人!" << endl;
}
}
system("pause");
system("cls");
return;
}

void cleanPerson(Addressbooks * abs)
{
abs->m_Size = 0;
cout << "通讯录已清空" << endl;
system("pause");
system("cls");
}
int main() {
int select;
struct Addressbooks abs;
abs.m_Size = 0;

while (true) {
showMenu();
cin >> select;
switch (select) {
case 1:
addPerson(&abs);
break;
case 2:
showPerson(&abs);
break;
case 3:
deletePerson(&abs);
break;
case 4:
searchPerson(&abs);
break;
case 5:
modifyPerson(&abs);
break;
case 6:
cleanPerson(&abs);
break;
case 0:
cout << "欢迎下次使用" << endl;
return 0;
default:
cout << "输入有误!" << endl;
break;
}
}


system("pause");
return 0;
}