通讯录管理系统
目前存在一个bug,就是删除联系人的时候,会显示姓名年龄等,但实际姓名年龄不显示,其他的功能测试正常
#include<iostream>
#include<string>
using namespace std;
bool ture = 1;
struct people
{
string name;
string age;
string phone_num;
string addr;
};
void showMenu(void)
{
cout << "1.添加联系人" << endl;
cout << "2.显示联系人" << endl;
cout << "3.删除联系人" << endl;
cout << "4.查找联系人" << endl;
cout << "5.修改联系人" << endl;
cout << "6.清空联系人" << endl;
cout << "7.退出通讯录" << endl;
}
int main()
{
int people = 0;//人数
struct people temp_p; //要删除的人临时存放的变量
int select;//输入键值
struct people p[1000];
bool confirm;
struct people duizhao;
showMenu();
while (ture)
{
cout << "请输入选项前的数字" << endl;
cin >> select;
switch (select)
{
case 1:cout << "请输入联系人姓名:" << endl;
cin >> p[people].name;
cout << "请输入联系人年龄:" << endl;
cin >> p[people].age;
cout << "请输入联系人电话:" << endl;
cin >> p[people].phone_num;
cout << "请输入联系人地址:" << endl;
cin >> p[people].addr;
people++;
break;
case 2:if (people == 0)
cout << "当前通讯录无人!" << endl;
for (int i = 0; i < 10; i++)//显示联系人
{
if (p[i].name != "\0") {
cout << "姓名:" << p[i].name << " 年龄:" << p[i].age << " 电话:" << p[i].phone_num << " 地址" << p[i].addr << endl;
}
}
break;
case 3:if (people != 0) {
cout << "请输入要删除的人的名字:" << endl;//删除联系人
cin >> temp_p.name;
//people--;
for (int i = 0; i < 1000; i++)
{
while (p[i].name == temp_p.name) {
p[i].name = '\0'; p[i].age = '\0'; p[i].phone_num = '\0'; p[i].addr = '\0';
break;
}
}
}
else cout << "当前通讯录无人!" << endl;
break;
case 5:if (people == 0)//修改当前联系人
{
cout << "当前通讯录无人!" << endl;
}
else
{
cout << "请输入需要修改的联系人的姓名:" << endl;
cin >> temp_p.name;
for (int i = 0; i < people; i++)
{
if (temp_p.name == p[i].name) {//找到了需要修改的内容
cout << "请输入需要修改后的信息" << endl;
cout << "请输入联系人姓名:" << endl;
cin >> p[i].name;
cout << "请输入联系人年龄:" << endl;
cin >> p[i].age;
cout << "请输入联系人电话:" << endl;
cin >> p[i].phone_num;
cout << "请输入联系人地址:" << endl;
cin >> p[i].addr;
}
else//没找到需要修改的内容
{
cout << "查无此人!" << endl;
}
}
}
break;
case 4:if (people > 0) {
cout << "请输入你需要查找的人的姓名:" << endl;//查找联系人
cin >> temp_p.name;
for (int i = 0; i < people; i++)
{
if (temp_p.name == p[i].name) {
cout << "您查找的人的信息为:" << endl;
cout << "姓名:" << p[i].name << " 年龄:" << p[i].age << " 电话:" << p[i].phone_num << " 地址" << p[i].addr << endl;
}
else {
cout << "未找到您查找的联系人!" << endl;
}
}
}
else cout << "当前通讯录无人" << endl;
break;
case 6:if (people > 0) {
cout << "您确定要清空联系人吗?此操作不可逆!" << endl;//清空联系人
cout << "确定清空请扣1,其他情况请扣2" << endl;
cin >> confirm;
if (confirm == 1)
{
for (int i = 0; i < people; i++)
{
p[i].name = '\0'; p[i].age = '\0'; p[i].phone_num = '\0'; p[i].addr = '\0';
}
}
}
else cout << "当前通讯录无人" << endl;;
break;
case 7:system("pause"); ture = 0; break;
break;
}
}
system("pause");
return 0;
}