#include<iostream>
#include<string>
#define MAX 1000
using namespace std;
//菜单界面
struct person {
string m_name;
int m_Sex;
int m_Age;
string m_Phone;
string m_Addr;
};
struct Addressbooks {
struct person personArray[MAX];
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 == 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");
}
}
int main(){
Addressbooks abs;
abs.m_size = 0;
int select = 0;
while (true) {
showmenu();
cin >> select;
switch (select) {
case 1:
addPerson(&abs);//利用地址传递
break;
case 2:
break;
case3:
break;
case 4:
break;
case5:
break;
case 6:
break;
case 0:
cout << "欢迎您下次使用" << endl;
system("pause");
return 0;
break;
default:
break;
}
}
system("pause");
return 0;
}