C++通讯录管理系统
程序员文章站
2024-03-14 18:28:04
...
直接上代码:
#include<iostream>
using namespace std;
#include<string>
#define MAX 1000
void showMenu()
{
cout << "***** 1:添加联系人 *****" << endl;
cout << "***** 2:显示联系人 *****" << endl;
cout << "***** 3:删除联系人 *****" << endl;
cout << "***** 4:查找联系人 *****" << endl;
cout << "***** 5:修改联系人 *****" << endl;
cout << "***** 6:清空联系人 *****" << endl;
cout << "***** 0:退出通讯录 *****" << endl;
}
struct person
{
string m_name;
int m_sex;
int m_age;
string m_phone;
string m_addr;
};
struct addressBooks
{
struct person personArray[MAX];
int size;
};
void addPerson(addressBooks * abs )
{
if (abs->size > MAX)
{
cout << "通讯录已满" << endl;
}
else
{
string name, phone, addr;
cout << "请输入姓名:";
cin >> name;
abs->personArray[abs->size].m_name = name;
int sex, age;
cout << "请输入性别,1代表男性,2代表女性:";
cin >> sex;
abs->personArray[abs->size].m_sex = sex;
cout << "请输入年龄:";
cin >> age;
abs->personArray[abs->size].m_age = age;
cout << "请输入电话号码:";
cin >> phone;
abs->personArray[abs->size].m_phone = phone;
cout << "请输入住址:";
cin >> addr;
abs->personArray[abs->size].m_addr = addr;
abs->size++;
cout << "添加成功" << endl;
system("pause");
system("cls");
}
}
void showPerson(addressBooks* abs)
{
if (abs->size== 0)
{
cout << "通讯录为空!" << endl;
}
else
{
for (int i = 0; i < abs->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");
}
int ifExit(addressBooks * abs,string name)
{
for (int i = 0; i < abs->size; i++)
{
if (abs->personArray[i].m_name == name)
{
return i;
}
}
return -1;
}
void delectPerson(addressBooks* abs)
{
string name;
cout << "请输入您想删除的联系人姓名:";
cin >> name;
int a= ifExit(abs, name);
if (a == -1)
{
cout << "通讯录中无此人!" << endl;
}
else
{
for (int i = a; i < abs->size; i++)
{
abs->personArray[i] = abs->personArray[i + 1];
}
abs->size--;
cout << "删除成功!" << endl;
}
system("pause");
system("cls");
}
void searchPerson(addressBooks* abs, string name)
{
int a = ifExit(abs, name);
if (a == -1)
{
cout << "通讯录中无此人!" << endl;
}
else
{
cout << "姓名:" << abs->personArray[a].m_name << '\t';
cout << "性别:" << (abs->personArray[a].m_sex == 1 ? "男" : "女") << '\t';
cout << "年龄:" << abs->personArray[a].m_age << '\t';
cout << "号码:" << abs->personArray[a].m_phone << '\t';
cout << "住址:" << abs->personArray[a].m_addr << endl;
}
system("pause");
system("cls");
}
void revisePerson(addressBooks* abs, string name)
{
int a = ifExit(abs, name);
if (a == -1)
{
cout << "通讯录中无此人!" << endl;
}
else
{
string name, phone, addr;
cout << "请重新输入姓名:";
cin >> name;
abs->personArray[a].m_name = name;
int sex, age;
cout << "请重新输入性别,1代表男性,2代表女性:";
cin >> sex;
abs->personArray[a].m_sex = sex;
cout << "请重新输入年龄:";
cin >> age;
abs->personArray[a].m_age = age;
cout << "请重新输入电话号码:";
cin >> phone;
abs->personArray[a].m_phone = phone;
cout << "请重新输入住址:";
cin >> addr;
abs->personArray[a].m_addr = addr;
cout << "修改成功!" << endl;
}
system("pause");
system("cls");
}
void cleanPerson(addressBooks* abs)
{
abs->size = 0;
cout << "通讯录已清空!" << endl;
system("pause");
system("cls");
}
int main()
{
addressBooks abs;
abs.size = 0;
int select;
while (1)
{
showMenu();
cout << "请输入你的选择:";
cin >> select;
switch (select)
{
case 1:
addPerson(&abs);
break;
case 2:
showPerson(&abs);
break;
case 3:
delectPerson(&abs);
break;
case 4:
{
string name;
cout << "请输入您要查找的联系人姓名:";
cin >> name;
searchPerson(&abs, name);
break;
}
case 5:
{
string name;
cout << "请输入您要修改的联系人姓名:";
cin >> name;
revisePerson(&abs, name);
break;
}
break;
case 6:
cleanPerson(&abs);
break;
case 0:
cout << "欢迎下次使用" << endl;
return 0;
break;
}
}
}
上一篇: 网络营销方法
下一篇: Segment Occurrences
推荐阅读
-
C++通讯录管理系统
-
简练软考知识点整理-项目全面质量管理TQM 软考项目管理信息系统信管
-
简练软考知识点整理-形震规发散 项目管理信息系统系统集成简练软考
-
简练软考知识点整理-职惩奖专参 项目管理信息系统系统集成简练软考
-
简练软考知识点整理-范围确认易混概念 项目管理信息系统系统集成简练软考
-
简练软考知识点整理-公邀竞单询其 项目管理信息系统系统集成简练软考
-
简练软考知识点整理-项目冲突的来源 项目管理信息系统系统集成简练软考
-
如何通过数据分析,精细化客户管理? 博客分类: 数据分析系统,案例,商业智能 商业智能
-
Java设计模块系列之书店管理系统单机版(三)
-
Java设计模块系列之书店管理系统单机版(二)