C++通讯管理系统(十分简易)

不涉及各信息数据的存储

#include<iostream>
using namespace std;
#include<string>
struct people//结构体
{
	string name;
	string sex;
	int age;
	string phone;
	string address;
}p[1000];
int n = -1;//通讯录中的总人数
bool flag = true;
void add(people p[])//添加联系人
{
	n++;
	string s,t;
	int a;
	cout << "请输入姓名:";
	cin>> p[n].name;
	cout << "请输入性别:";
	cin >> s;
	while (s != "男" && s != "女")
	{
		cout << "请输入正确的性别:";
		cin >> s;
	}
	p[n].sex = s;
	cout << "请输入年龄:";
	cin >> a;
	while (a < 0 || a>150)
	{
		cout << "请输入正确的年纪:";
		cin >> a;
	}
	p[n].age = a;
	cout << "请输入联系电话:";
	cin >> t;
	while (t.length() != 11)
	{
		cout << "请输入正确的电话:";
		cin >> t;
	}
	p[n].phone = t;
	cout << "请输入地址:";
	cin >> p[n].address;
	system("pause");
	system("cls");
}

void show(people p[])//显示联系人
{
	if (n == -1)
	{
       cout << "通讯录为空!" << endl;
	   system("pause");
	   system("cls");
	   return;
	}
	for (int i = 0; i <= n; i++)
	{
		cout << "姓名:" << p[i].name <<
			"\t" << "性别:" << p[i].sex <<
			"\t" << "年龄:" << p[i].age <<
			"\t" << "电话:" << p[i].phone <<
			"\t" << "地址:" << p[i].address << endl;
	}
	system("pause");
	system("cls");
}

void delet(people p[])//删除
{
	string s;
	int i;
	cout << "请输入要删除的联系人姓名:";
	cin >> s;
	for (i = 0; i <= n; i++)
	{
		if (p[i].name == s)
			break;
	}
	if (i == n + 1)
	{
		cout << "查无此人!" << endl;
		system("pause");
		system("cls");
		return;
	}
	while (i < n)
	{
		p[i] = p[i + 1];
		i++;
	}
	n--;
	cout << "删除成功!" << endl;
	system("pause");
	system("cls");

}

void find(people p[])//查找联系人信息
{
	string s;
	cout << "请输入所查联系人的姓名:";
	cin >> s;
	for (int i = 0; i <= n; i++)
	{
		if (p[i].name == s)
		{
			cout << "姓名:" << p[i].name <<
				"\t" << "性别:" << p[i].sex <<
				"\t" << "年龄:" << p[i].age <<
				"\t" << "电话:" << p[i].phone <<
				"\t" << "地址:" << p[i].address << endl;
			system("pause");
			system("cls");
			return;
		}

	}
	cout << "查无此人!" << endl;
	system("pause");
	system("cls");
}

void rewrite(people p[])//修改信息
{
	string s;
	int x;
	cout << "请输入要修改的联系人姓名:";
	cin >> s;
	for (int i = 0; i <= n; i++)
	{
		if (p[i].name == s)
		{
			cout << "1.姓名\t2.年龄\t3.性别\t4.联系电话\t5.地址" << endl;
			cout << "选择要修改的序号:";
			cin >> x;
			cout << "输入修改后的信息:";
			switch (x)
			{
			case 1:
				cin >> p[i].name;
				break;
			case 2:
				cin >> p[i].age;
				break;
			case 3:
				cin >> p[i].sex;
				break;
			case 4:
				cin >> p[i].phone;
				break;
			case 5:
				cin >> p[i].address;
				break;
			default:
				cout << "无此选项!" << endl;
			}
			system("pause");
			system("cls");
			return;
		}
	}
	cout << "查无此人!" << endl;
	system("pause");
	system("cls");
}

void clean()//清除通讯录
{
	n = -1;
	cout << "联系人已清空!" << endl;
	system("pause");
	system("cls");
}

void back()//退出
{
	flag = false;
	cout << "欢迎下次使用!" << endl;
	system("pause");
	system("cls");
}

int main()
{
	while (flag)
	{
	cout << "***********************" << endl;
	cout << "*****1.添加联系人******" << endl;
	cout << "*****2.显示联系人******" << endl;
	cout << "*****3.删除联系人******" << endl;
	cout << "*****4.修改联系人******" << endl;
	cout << "*****5.清空联系人******" << endl;
	cout << "*****6.退出通讯录******" << endl;
	cout << "***********************" << endl;
	int x;
	
		cout <<'\n'<< "请输入选项号:";
		cin >> x;
		switch (x)
		{
		case 1:
			add(p);
			break;
		case 2:
			show(p);
			break;
		case 3:
			delet(p);
			break;
		case 4:
			rewrite(p);
			break;
		case 5:
			clean();
			break;
		case 6:
			back();
			break;
		default:
			cout << "无此选项!" << endl;
			break;
		}
	}
}

运行结果:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述



  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值