#include<iostream>
#define Max 1000
using namespace std;
/*
1、添加联系人(信息包括,姓名,性别,年龄,联系电话,家庭住址)最多记录1000人
2、显示联系人,打印信息
3、删除联系人,按照要求删除联系人
4、修改联系人,根据要求更改联系人的信息
5、清空联系人
6、退出通迅录
*/
//定义某一个联系人的结构体
struct Person
{
string name;
int sex;
int age;
string phone_numble;
string home_load;
};
//设计通讯录结构体
struct Person_arry
{
struct Person person_arry[Max];
int in_size;
};
//把某个联系人添加如通讯录中
int add_one(Person_arry *abs)
{
if (abs->in_size == Max)
{
cout << "无法添加,通讯录已满!!!" << endl;
return 0;
}
else
{
string name;
int sex;
int age;
string phone_numble;
string home_load;
cout << "输入姓名:" << endl;
cin >> name;
abs->person_arry[abs->in_size].name=name;
while(true)
{
cout << "输入性别:" << endl << "1-男生\n" << "2-女生" << endl;
cin >> sex;
if (sex == 1 or sex == 2)
{
abs->person_arry[abs->in_size].sex = sex;
break;
}
else
{
cout << "输出误,重新输入!" << endl;
}
}
cout << "输入年龄:" << endl;
cin >> age;
abs->person_arry[abs->in_size].age = age;
cout << "输入电话:" << endl;
cin >> phone_numble;
abs->person_arry[abs->in_size].phone_numble = phone_numble;
cout << "输入家庭住址:" << endl;
cin >> home_load;
abs->person_arry[abs->in_size].home_load =home_load;
abs->in_size++;
cout << "添加成功" << endl;
system("pause");
system("cls");
}
};
//打印通讯录中的信息
void print_all(Person_arry* abs)
{
if (abs->in_size == 0)
{
cout << "通讯录中无任何记录!!!" << endl;
}
else
{
for (int i = 0; i < abs->in_size; i++)
{
cout << "姓名:" << abs->person_arry[i].name << " ";
cout << "性别:" << (abs->person_arry[i].sex==1?"男":"女") << " ";
cout << "年龄:" << abs->person_arry[i].age << " ";
cout << "电话:" << abs->person_arry[i].phone_numble << " ";
cout << "地址:" << abs->person_arry[i].home_load << endl;
}
}
system("pause");
system("cls");
};
//查找通讯录中某一个联系人
int check_one(Person_arry* abs)
{
if (abs->in_size == 0)
{
cout << "通讯录中无任何记录!!!" << endl;
}
else
{
string name;
cout << "输入待操作的姓名:" << " ";
cin >> name;
for (int i = 0; i < abs->in_size; i++)
{
if (abs->person_arry[i].name == name)
{
cout << "在通讯录中找到以下记录!!!" << endl;
cout << "姓名:" << abs->person_arry[i].name << " ";
cout << "性别:" << (abs->person_arry[i].sex == 1 ? "男" : "女") << " ";
cout << "年龄:" << abs->person_arry[i].age << " ";
cout << "电话:" << abs->person_arry[i].phone_numble << " ";
cout << "地址:" << abs->person_arry[i].home_load << endl;
cout << "按任一键进行下一步操作!!!" << endl;
system("pause");
system("cls");
return i;
return 0;
}
else
{
cout << "数据库中暂无该人记录!!!" << endl;
system("pause");
system("cls");
}
}
}
system("pause");
system("cls");
return 0;
};
//修改通讯录中的某一个联系人信息
void change_one(Person_arry* abs)
{
if (abs->in_size == 0)
{
cout << "通讯录中无任何记录!!!" << endl;
}
else
{
cout << "重新修改信息,请按照下面提示进行操作..." << endl;
string name;
int sex;
int age;
int i = check_one(abs);
string phone_numble;
string home_load;
cout << "输入姓名:" << endl;
cin >> name;
abs->person_arry[i].name = name;
while (true)
{
cout << "输入性别:" << endl << "1-男生\n" << "2-女生" << endl;
cin >> sex;
if (sex == 1 || sex == 2)
{
abs->person_arry[i].sex = sex;
break;
}
else
{
cout << "输出误,重新输入!" << endl;
}
}
cout << "输入年龄:" << endl;
cin >> age;
abs->person_arry[i].age = age;
cout << "输入电话:" << endl;
cin >> phone_numble;
abs->person_arry[i].phone_numble = phone_numble;
cout << "输入家庭住址:" << endl;
cin >> home_load;
abs->person_arry[i].home_load = home_load;
cout << "修改成功" << endl;
abs->in_size++;
}
system("pause");
system("cls");
};
//清空通讯录
void del_all(Person_arry* abs)
{
abs->in_size = 0;
cout << "已经清空通讯录!!!" << endl;
system("pause");
system("cls");
};
//退出
void exit()
{
cout << "已退出本通讯录" << endl;
};
//删除一个元素
void del_one(Person_arry* abs)
{
if (abs->in_size == 0)
{
cout << "通讯录中无任何记录!!!" << endl;
}
else
{
int i = check_one(abs);
for (int j = i; j < abs->in_size; j++)
{
abs->person_arry[j] = abs->person_arry[j + 1];
}
abs->in_size--;
cout << ".........正在删除.........." << endl;
}
system("pause");
system("cls");
};
int main()
{
//存储数据的列表
Person_arry abs;
//初始化通讯录中人数
abs.in_size = 0;
int n;
Flag:
cout << "这是一个信息管理系统:....(键盘输入下面的数字进行操作)" << endl;
cout << "1、添加联系人(信息包括,姓名,性别,年龄,联系电话,家庭住址)最多记录1000人" << endl;
cout << "2、显示联系人,打印全部信息" << endl;
cout << "3、查找联系人,按照要求输出联系人信息" << endl;
cout << "4、修改联系人,根据要求更改联系人的信息" << endl;
cout << "5、清空通讯表" << endl;
cout << "6、删除联系人,按照要求删除联系人" << endl;
cout << "7、退出通迅录" << endl;
cout << "请进行操作:";
cin >> n;
switch (n)
{
case 1:add_one(&abs); goto Flag;//传入地址
case 2:print_all(&abs); goto Flag;
case 3:check_one(&abs); goto Flag;
case 4:change_one(&abs); goto Flag;
case 5:del_all(&abs); goto Flag;
case 6:del_one(&abs); goto Flag;
default: exit(); break;
}
return 0;
}
c++ 通讯录管理系统
最新推荐文章于 2024-08-03 15:40:43 发布