// 通讯录管理系统.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
using namespace std;
#define MAX 1000
//设计联系人的结构体
struct Person
{
//姓名
string m_Name;
//性别 1 男 2 女
int m_Sex;
//年龄
int m_Age;
//电话
string m_Phone;
//住址
string m_Addr;
};
//设计通讯录结构体
struct Addressbooks
{
//通讯录中保存的联系人数组
struct Person personArray[MAX];
//通讯录中当前记录联系人个数
int m_Size;
};
int isExist(Addressbooks* abs, string name); // 添加函数原型
//1.添加联系人
void addPerson(Addressbooks * ads)
{
//判断通讯录是否已满,如果满了就不再添加
if (ads->m_Size == MAX)
{
cout << "通讯录已满,无法添加!" << endl;
return;
}
else
{
//姓名
string name;
cout << "请输入姓名:" << endl;
cin >> name;
ads->personArray[ads->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)
{
ads->personArray[ads->m_Size].m_Sex = sex;
break;
}
}
//年龄
cout << "请输入年龄:" << endl;
int age = -1;
while (true) {
cin >> age;
if (age >= 0 && age <= 130)
{
ads->personArray[ads->m_Size].m_Age = age;
break;
}
cout << "输入有误,请输入正确的年龄:" << endl;
}
//电话
cout << "请输入联系电话:" << endl;
string phone;
cin >> phone;
ads->personArray
12-31
06-29
08-04
1620
