基于C++的通讯录管理系统

主要使用结构体创建通讯录和通讯录成员,利用全局函数实现对通讯录的添加、显示、删除、查找、修改、清空、以及退出通讯录。

实现界面
在这里插入图片描述
实现代码:

#include<iostream>
using  namespace std;
#include<string>
#define max  1000

struct menbers
{
	string name;
	string sex;
	int age;
	string number;
	string addres;
};
struct books
{
	menbers people[max];
	int size=0;
};
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;
}
void getmenbers(struct books *p)
{
	if (p->size >= 1000)
	{
		cout << "通讯录已满" << endl;
		return;
		
	}
	else
	{
		cout << "请输入添加联系人的姓名" << endl;
		cin >> p->people[p->size].name;
		cout << "请输入添加联系人的性别" << endl;
		cin >> p->people[p->size].sex;
		cout << "请输入添加联系人的年龄" << endl;
		cin >> p->people[p->size].age;
		cout << "请输入添加联系人的联系电话" << endl;
		cin >> p->people[p->size].number;
		cout << "请输入添加联系人的家庭住址" << endl;
		cin >> p->people[p->size].addres;
		cout << "添加成功!!" << endl;
		p->size++;
	}
	system("pause");
	system("cls");
}
void print(struct books*p)
{
	if (p->size == 0)
	{
		cout << "通讯录为空" << endl;
		
	}
	else
	{
		for (int i = 0; i < p->size; i++)
		{
			cout << p->people[i].name<< "  " <<  p->people[i].sex << "  " << p->people[i].age << "  " << p->people[i].number << "  " << p->people[i].addres << endl;

		}
	}
	system("pause");
	system("cls");
}
void findmenbers(struct books* p)
{
	if (p->size == 0)
	{
		cout << "通讯录为空" << endl;
		return;
	}
	else
	{
		string name;
		cout << "请输入需要查找的姓名" << endl;
		cin >> name;
		for (int i = 0; i < p->size; i++)
		{
			if (p->people[i].name == name)
			{
				cout << p->people[i].name << "  " << p->people[i].sex << "  " << p->people[i].age << "  " << p->people[i].number << "  " << p->people[i].addres << endl;
			}
		}
	}
	system("pause");
	system("cls");
}
void deletemenbers(struct books* p)
{
	if (p->size == 0)
	{
		cout << "通讯录为空" << endl;
		return;
	}
	else
	{
		string name;
		cout << "请输入需要删除的姓名" << endl;
		cin >> name;
		for (int i = 0; i < p->size; i++)
		{
			if (p->people[i].name == name)
			{
				for (int j = i; j < max+1; j++)
				{
					p->people[i].name = p->people[j+1].name;
					p->people[i].sex = p->people[j+1].sex;
					p->people[i].age = p->people[j+1].age;
					p->people[i].number = p->people[j+1].number;
					p->people[i].addres = p->people[j+1].addres;
				}
			}
			cout << "删除成功" << endl;
			p->size--;
		}
	}
	system("pause");
	system("cls");
}
void changemenbers(struct books* p)
{
	if (p->size == 0)
	{
		cout << "通讯录为空" << endl;
		return;
	}
	else
	{ 
		string name;
		cout << "请输入需要修改联系人的姓名" << endl;
		cin >> name;
		for (int i = 0; i < p->size; i++)
		{
			if (p->people[i].name == name)
			{
				cout << "请输入修改联系人的姓名" << endl;
				cin >> p->people[i].name;
				cout << "请输入修改联系人的性别" << endl;
				cin >> p->people[i].sex;
				cout << "请输入修改联系人的年龄" << endl;
				cin >> p->people[i].age;
				cout << "请输入修改联系人的联系电话" << endl;
				cin >> p->people[i].number;
				cout << "请输入修改联系人的家庭住址" << endl;
				cin >> p->people[i].addres;
				cout << "修改成功!!" << endl;
			}
			
		}

	}
	system("pause");
	system("cls");
}
void emptymenbers(struct books* p)
{
	p->size = 0;
	cout << "清空成功" << endl;
	system("pause");
	system("cls");
}

int main()
{
	struct books b;
	int select;
	while (1)
	{
		showmenu();
		cout << "请选择功能" << endl;
		cin >> select;
		switch (select)
		{
		case 0:cout << "欢迎下次使用" << endl;
			system("pause");
			return 0; break;
		case 1:getmenbers(&b); break;
		case 2:print(&b); break;
		case 3:deletemenbers(&b); break;
		case 4:findmenbers(&b); break;
		case 5:changemenbers(&b); break;
		case 6: emptymenbers(&b); break;
		default:cout << "输入错误" << endl; break;
		}
	}
	system("pause");
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值